Changeset 137 for branches/generator/UBuilder.pas
- Timestamp:
- Dec 27, 2017, 6:05:11 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/generator/UBuilder.pas
r136 r137 163 163 Add(' Position := StartPos;'); 164 164 Add(' if Required then Error(''Expected "'' + Text + ''" but found "'' + ReadText + ''".'');'); 165 Add(' end ;');165 Add(' end else WriteLn(''Expect: '' + Text);'); 166 166 Add('end;'); 167 167 Add(''); … … 178 178 Add(' Position := StartPos;'); 179 179 Add(' if Required then Error(''Expected "'' + CharFrom + ''" to "'' + CharTo + ''" but found "'' + ReadChar + ''".'');'); 180 Add(' end ;');180 Add(' end else WriteLn(''ExpectRange: '' + CharFrom + ''..'' + CharTo + '': '' + ReadChar);'); 181 181 Add('end;'); 182 182 Add(''); … … 192 192 Text := Text + ' OldPosition: TPosition;' + LineEnding; 193 193 Text := Text + 'begin' + LineEnding; 194 //Text := Text + ' WriteLn(''Rule check: ' + Rule.Name + ''');'; 194 195 Text := Text + ' Result := True;' + LineEnding; 195 196 Text := Text + FunctionBody; 197 Text := Text + ' if Result then WriteLn(''Rule: ' + Rule.Name + ''');'; 196 198 Text := Text + 'end;' + LineEnding + LineEnding; 197 199 end; … … 223 225 end; 224 226 rtAnd: begin 225 if Assigned(Items.Grammer.WhiteSpaceRule) and Items.WithWhiteSpeaces226 and (I > 0) then begin227 Line := Line + Indent(IndentLevel) + 'repeat' + LineEnding;228 Inc(IndentLevel);229 Line := Line + Indent(IndentLevel) + 'if not Parse' +230 Items.Grammer.WhiteSpaceRule.Name + '(False)' +231 ' then Break;' + LineEnding;232 Dec(IndentLevel);233 Line := Line + Indent(IndentLevel) + 'until False;' + LineEnding;234 end;235 236 227 if not Item.Optional then 237 228 Line := Line + Indent(IndentLevel) + 'Result := Result and '; … … 256 247 Indent(IndentLevel + 1) + 'Exit;' + LineEnding + 257 248 Indent(IndentLevel) + 'end;'; 249 250 // Check white spaces 251 if Assigned(Items.Grammer.WhiteSpaceRule) and Items.WithWhiteSpeaces 252 then begin 253 Line := Line + Indent(IndentLevel) + 'repeat' + LineEnding; 254 Inc(IndentLevel); 255 Line := Line + Indent(IndentLevel) + 'if not Parse' + 256 Items.Grammer.WhiteSpaceRule.Name + '(False)' + 257 ' then Break;' + LineEnding; 258 Dec(IndentLevel); 259 Line := Line + Indent(IndentLevel) + 'until False;' + LineEnding; 260 end; 258 261 end; 259 262 end; … … 302 305 Add(' CloseFile(SourceFile);'); 303 306 if Assigned(Grammer.TopRule) then 304 Add(' Parser.Parse' + Grammer.TopRule.Name + ' ;');307 Add(' Parser.Parse' + Grammer.TopRule.Name + '(True);'); 305 308 Add(' FreeAndNil(Parser);'); 306 309 Add('end;'); … … 374 377 var 375 378 Item: TRuleItem; 379 Line: string; 376 380 begin 377 381 Result := ''; 382 Line := ''; 378 383 with SourceFile do begin 379 384 for Item in Items do begin 380 385 case Item.RuleItemType of 381 ritTerminal: Result := Result+ '(Value = ''' + StringText(Item.Terminal, Item.EscapedStrings) + ''')';382 ritNonTerminal: Result := Result+ 'Is' + Item.NonTerminalName + '(Value)';383 ritTerminalRange: Result := Result+ '((Value > ''' + StringText(Item.TerminalFrom, Item.EscapedStrings) + ''') and (Value < ''' + StringText(Item.TerminalTo, Item.EscapedStrings) + '''))';384 ritSubItems: Result := Result+ '(' + BuildTokenizerItems(SourceFile, Item.SubItems) + ')';386 ritTerminal: Line := Line + '(Value = ''' + StringText(Item.Terminal, Item.EscapedStrings) + ''')'; 387 ritNonTerminal: Line := Line + 'Is' + Item.NonTerminalName + '(Value)'; 388 ritTerminalRange: Line := Line + '((Value > ''' + StringText(Item.TerminalFrom, Item.EscapedStrings) + ''') and (Value < ''' + StringText(Item.TerminalTo, Item.EscapedStrings) + '''))'; 389 ritSubItems: Line := Line + '(' + BuildTokenizerItems(SourceFile, Item.SubItems) + ')'; 385 390 end; 386 391 if Item <> Items[Items.Count - 1] then 387 Result := Result + ' ' + RuleTypeText[Items.RuleType] + ' '; 388 end; 392 Line := Line + ' ' + RuleTypeText[Items.RuleType] + ' '; 393 if Length(Line) > 80 then begin 394 Result := Result + Line + LineEnding; 395 Line := ''; 396 end; 397 end; 398 Result := Result + Line; 389 399 end; 390 400 end;
Note:
See TracChangeset
for help on using the changeset viewer.