Warning, /frameworks/ktexteditor/autotests/input/indent/pascal/longtest3/origin is written in an unsupported language. File is not indexed.

0001 // kate: space-indent on; indent-width 3; replace-tabs on; remove-trailing-spaces all;
0002 // kate: syntax pascal; indent-mode pascal;
0003 
0004 // these variables are understood by the pascal indenter ...
0005 // kate: cfgIndentCase true;          // indent elements in a case statement
0006 // kate: cfgIndentBegin 2;            // indent 'begin' this many spaces
0007 // kate: debugMode false;              // show how indent is determined
0008 // kate: cfgAutoInsertStar true;      // auto insert '*' in (* ... *)-comments
0009 // kate: cfgSnapParen true;           // snap ')' to '*)' in comments
0010 
0011 
0012 function f1( var z: integer;
0013 var p,q : real;
0014 t : boolean        ) : integer; // indentation should line up
0015 
0016 type   tArray = array[0..17] of real;
0017 
0018 r= record a: integer; c: char; end;
0019 
0020 // nested variant record - too hard to get right. tough
0021 MyRec = Record
0022 X : Longint;
0023 Case byte of
0024 1,2,8 : (Y : Longint;
0025                case byte of
0026                3 : (Z : Longint);   // CHECK: parens inside parens aligned correctly
0027          );
0028 end;
0029 
0030                                                    commands = (    crsupp,crbefore,blinbefore,
0031                                                                   dindonkey,dindent,spbef,
0032 spaft,gobsym,
0033 inbytab,   { indent current margin (was indent from symbol pos) }
0034 crafter,
0035 finl            { force symbol to follow on same line as previous symbol }
0036 );
0037 
0038 tR = record
0039 i: integer;  // should indent after record
0040 r: real;
0041 a: array[1..11] of char;
0042 
0043 case boolean of
0044 true:( a: int);
0045 dontKnow:
0046 (z: real;
0047  fred : real;       // should be indented after case value
0048 joe  : integer;
0049 );
0050 false:
0051 (  ted : array[
0052                   1..16
0053 ] of boolean;
0054 moe: char; // should align to ''ted''
0055 );
0056 end; // end of case + end of record
0057 
0058 commandset = set of commands;       // should be aligned to 'record', not 'case'
0059 
0060 begin { f1 }
0061 case currsym^.name of
0062 
0063    { for procs, etc just record that we have one, wait for name }
0064 progsym, procsym, funcsym: begin
0065 symbol_seen := procsym;
0066 proc_state := proc_header;
0067 annotate_push( procsym );
0068 end;
0069 s1;                   // coding error, a case value should be here
0070    { remember we are in the declaraions part }
0071                         varsym, typesym, constsym, labelsym:
0072                            proc_state := proc_declarations;
0073 
0074                            { if it's a proc, there will be no begin/end ==> pop info we just saved
0075                            if it's an external var ==> do nothing  }
0076                         forwardsym, externalsym:
0077 if proc_state = proc_header then begin
0078 sym := annotate_pop;
0079 tok := annotate_pop_tok;
0080 if annotate_trace in traceFlags then
0081 writeln( 'undo ', tok.val:tok.len );
0082 end;
0083 
0084 { if a proc has just occurred, this is its name
0085 otherwise, remember it, just in case it's a record name }
0086 othersym: begin
0087 if symbol_seen = procsym then begin
0088 tok.val := currsym^.value;
0089 tok.len := currsym^.length;
0090 annotate_push_tok( tok );
0091 symbol_seen := othersym;
0092 end
0093 else begin
0094 annotate_temp_tok.val := currsym^.value;
0095 annotate_temp_tok.len := currsym^.length;
0096 end;
0097 end;
0098 
0099 { we have the name, push it so the end symbol can get it back }
0100 recordsym: begin
0101 annotate_push_tok(annotate_temp_tok);
0102 annotate_push( recordsym );
0103 symbol_seen := recordsym;
0104 end;
0105 
0106 { we must remember these so they can pushed if the begin symbol occurs }
0107 ifsym, forsym, whilesym, withsym: begin
0108 symbol_seen := currsym^.name;
0109 end;
0110 
0111 { this is the second part of an if statement }
0112 elsesym:
0113 symbol_seen := ifsym;
0114 
0115 { if in a declaration ==> ignore
0116 if in a statement (assume case statement) ==> prepare for possible begin following }
0117 colon:
0118 if proc_state = proc_statements then
0119    symbol_seen := colon;
0120 
0121 { reset symbol_seen }
0122 semicolon:
0123 symbol_seen := semicolon;
0124 
0125 { could be the begin of a proc
0126 ==> get value, leaving it for the corresponding end symbol
0127 or it could be part of an if, etc,
0128 ==> push the symbol so the end symbol knows what to do  }
0129 beginsym: begin
0130 proc_state := proc_statements;
0131 if symbol_seen in [ifsym, forsym, whilesym, withsym, elsesym, colon] then begin
0132 annotate_push( symbol_seen );
0133 end
0134 else begin
0135 sym := annotate_peek;
0136 if sym = procsym then begin
0137    { this is a proc begin, add annotation }
0138 annotate_pending_tok := true;
0139 annotate_temp_tok := annotate_peek_tok;
0140 end
0141 else begin
0142 if annotate_trace in traceFlags then
0143 writeln( infilename,' line ', inlines, ': orphaned begin found' );
0144 annotate_push( nosymbol );
0145 end
0146 end;
0147 end;
0148 
0149 { push the symbol so the end symbol can get it back }
0150                                  casesym: annotate_push( casesym );
0151 
0152                                     { end of proc, end of record  ==> pop name
0153                                     end of if, etc statement    ==> pop symbol
0154                                     end of case item (colon)    ==> ignore
0155                                     end of record ==> check if named record  }
0156 endsym: begin
0157 symbol_seen := endsym;
0158 sym := annotate_pop;
0159 if sym = recordsym then begin
0160    annotate_temp_tok := annotate_pop_tok;
0161    if annotate_temp_tok.val[1] in ['A'..'Z','a'..'z'] then
0162       annotate_pending_tok := true;
0163 end
0164 else if sym = procsym then begin
0165    annotate_pending_tok := true;
0166    annotate_temp_tok := annotate_pop_tok;
0167 end
0168 else if sym = ifsym then begin
0169    { if there's an else part, don't do an annotation here }
0170    if nextsym^.name <> elsesym then begin
0171       annotate_pending := true;
0172       annotate_temp := sym;
0173    end
0174 end
0175 else if sym in [forsym, whilesym, withsym, casesym] then begin
0176    annotate_pending := true;
0177    annotate_temp := sym;
0178 end
0179 else if sym = colon then begin
0180          if annotate_trace in traceFlags then
0181             writeln( 'case item not annotated' );
0182       end
0183       else begin
0184          if annotate_trace in traceFlags then
0185             writeln( infilename,' line: ', inlines, ' end symbol found but not handled' );
0186       end;
0187    end;
0188 end; { case }
0189 
0190 if annotate_pending then begin
0191 if nextsym^.crsbefore > 0 then begin
0192    { rest of line is empty }
0193                               insert_annotation(annotate_temp);
0194                               annotate_pending := false;
0195                            end else if nextsym^.name in [opencomment, closecomment] then begin
0196                               { there's another comment already on the same line }
0197 if annotate_trace in traceFlags then
0198 writeln( infilename,' line: ', inlines, ' annotate ', keyword[annotate_temp], ' abandoned' );
0199 annotate_pending := false;
0200 end
0201 else if (nextsym^.name <> semicolon) then begin
0202 insert_annotation(annotate_temp);
0203 annotate_pending := false;
0204 end;
0205 end;
0206 
0207 if annotate_pending_tok then begin
0208 if nextsym^.crsbefore > 0 then begin
0209    { rest of line is empty }
0210    insert_annotation_tok( annotate_temp_tok );
0211    annotate_pending_tok := false;
0212 end
0213 else if nextsym^.name in [opencomment, closecomment] then begin
0214    { there's another comment already on the same line }
0215 if annotate_trace in traceFlags then
0216 writeln( infilename,
0217          ' line: ', inlines,
0218 ' annotate ', annotate_temp_tok.val:annotate_temp_tok.len, ' abandoned'
0219 );
0220 annotate_pending_tok := false;
0221 end
0222 else if not (nextsym^.name in [semicolon, period]) then begin
0223    insert_annotation_tok( annotate_temp_tok );
0224    annotate_pending_tok := false;
0225 end;
0226 end;
0227 end; { f1 }
0228 
0229 
0230 function f2( p: boolean;
0231              var q: real;
0232 var x: ttype;              // should line up with first param
0233 var c: char;
0234 
0235 var i1, i2: integer;
0236 
0237 ch: char;
0238 z: boolean
0239 ) : real;
0240 
0241 var
0242 a: integer;
0243 b: boolean;
0244 
0245 begin { f2 }
0246 
0247 with floodlePtr^ do
0248 begin name := '        '; id := nil; next := nil; floodleAddr := 0;
0249 cow := grass + floodle  // should be indented
0250 end;
0251 
0252 case e of
0253 1: s1;   // CHECK: cr here should go to new case value!
0254 88:
0255 s3;
0256 
0257 2:  begin
0258 s2;
0259 s3;
0260 end;
0261 
0262 3: s3;
0263 4,5,6..9: s6;
0264 
0265 otherwise
0266 writeln('lots');
0267 writeln(' and lots');
0268 end; {case}
0269 
0270 if c then begin
0271 s1;
0272 a := func( 12,
0273 fffff( 89,
0274 t
0275 ),
0276 a // should align with '12'
0277 );
0278 end; // this must be aligned to the 'if' statement
0279 
0280 
0281 fredzarmplezzzzzzzzzzzz(       arg1,
0282 arg1,
0283 arg2,
0284 arg3
0285 );
0286 
0287 x := f(a) + f(b);
0288 
0289 
0290 if (e111) + e2 then fffffffffffff(    func0(  func1(    func2( f3(       arg1,
0291 
0292 
0293                                                                          arg2,
0294    arg3,
0295    arg4
0296 ),
0297 
0298 
0299 a1,  // should be aligned with arg f3, not '('
0300 a2,
0301 a3,
0302 a4
0303 ),
0304 
0305 aa2,
0306 aa3,
0307 aa4,
0308 aa5
0309 ),
0310 bb1,
0311 bb2,
0312 bb3,
0313 bb4
0314 ),
0315 cc1,
0316 cc2,
0317 cc3,
0318 cc4
0319 )
0320 else if c1 then begin
0321 s1;
0322 end;
0323 
0324 nextStmt := 13;
0325 
0326 while c1 do
0327 if q then
0328 s1
0329 else if qq then begin
0330 s2;
0331 s3
0332 end;
0333 
0334 
0335 if c1
0336 and c2 then begin // this can be aligned manually
0337 a := 12;
0338 s1;
0339 f(x)
0340 end;
0341 
0342 if cc1 then
0343 while c2 do
0344 f(x);
0345 
0346 while c1 do f(  arg1,
0347 arg2  // this should line up with arg1
0348 );
0349 
0350 if c4 then f( arg1,
0351 arg2
0352 );
0353 
0354 f1        ( arg1,
0355 arg2
0356 );
0357 fred      (  arg1,
0358 arg2
0359 arg3
0360 arg4,
0361 
0362 arg5
0363 );
0364 
0365 ff( arg1,
0366 arg2
0367 );
0368 
0369 a[1] := 13;
0370 repeat
0371 s1;
0372 while c3 do begin
0373 s3;
0374 while c2 do begin
0375 s4;
0376 while c4 do begin
0377 if c3 then
0378 begin
0379 s1;
0380 s2;
0381 end else
0382 s3;
0383 if c3 then begin
0384 s1
0385 end else
0386 
0387 if a then b
0388 else
0389 if c then d
0390 else
0391 
0392 s2;
0393 if c3 then
0394 if c4 then
0395 s5;
0396 
0397 s3
0398 end;
0399 end
0400 end
0401 until c3;
0402 
0403 
0404 s5;
0405 
0406 s3;
0407 while c7 do begin
0408 s3;
0409 s4
0410 end;
0411 
0412 s4
0413 end;
0414 
0415 s2
0416 until c1;  // there is no matching repeat here
0417 
0418 end;  { f2 }