Changeset 131 for branches/generator/UGrammer.pas
- Timestamp:
- Dec 24, 2017, 3:54:08 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/generator/UGrammer.pas
r130 r131 15 15 16 16 TRuleItemType = (ritTerminal, ritNonTerminal, ritSubItems, ritTerminalRange); 17 TGrammerNotation = (gnBnf, gnEbnf); 17 18 18 19 { TRuleItem } … … 39 40 procedure SaveToXmlNode(Node: TDOMNode); 40 41 function GetString: string; 42 function ExportAsString(Notation: TGrammerNotation): string; 41 43 constructor Create; 42 44 destructor Destroy; override; … … 61 63 procedure UpdateRuleReference; 62 64 function GetString: string; 65 function ExportAsString(Notation: TGrammerNotation): string; 63 66 property ParentRule: TRule read FParentRule write SetParentRule; 64 67 end; … … 95 98 procedure SaveToXmlNode(Node: TDOMNode); 96 99 function GetString: string; 100 function ExportAsString(Notation: TGrammerNotation): string; 97 101 property Grammer: TGrammer read FGrammer write SetGrammer; 98 102 end; … … 106 110 procedure SaveToXmlNode(Node: TDOMNode); 107 111 function GetString: string; 112 function ExportAsString(Notation: TGrammerNotation): string; 108 113 end; 109 114 … … 129 134 procedure GetUsedByRule(RefRule: TRule; UsedByRules: TStrings); 130 135 function GetString: string; 136 function ExportAsString(Notation: TGrammerNotation): string; 131 137 procedure Change; 132 138 property Modified: Boolean read FModified write SetModified; … … 248 254 begin 249 255 Result := Rules.GetString; 256 end; 257 258 function TGrammer.ExportAsString(Notation: TGrammerNotation): string; 259 begin 260 Result := Rules.ExportAsString(Notation); 250 261 end; 251 262 … … 292 303 if Repetitive then Result := '*' + Result; 293 304 if AnyExcept then Result := '!' + Result; 305 end; 306 307 function TRuleItem.ExportAsString(Notation: TGrammerNotation): string; 308 begin 309 case Notation of 310 gnBnf: begin 311 case RuleItemType of 312 ritTerminal: Result := Terminal; 313 ritNonTerminal: Result := '<' + NonTerminal.Name + '>'; 314 ritSubItems: begin 315 if not Optional and not Repetitive then 316 Result := '(' + SubItems.ExportAsString(Notation) + ')' 317 else Result := SubItems.ExportAsString(Notation); 318 end; 319 ritTerminalRange: Result := '(' + TerminalFrom + ' .. ' + TerminalTo + ')'; 320 end; 321 if Optional and not Repetitive then Result := '[' + Result + ']'; 322 if Repetitive then Result := '{' + Result + '}'; 323 if AnyExcept then Result := 'other then ' + Result; 324 end; 325 gnEbnf: begin 326 case RuleItemType of 327 ritTerminal: Result := '"' + Terminal + '"'; 328 ritNonTerminal: Result := NonTerminal.Name; 329 ritSubItems: begin 330 if not Optional and not Repetitive then 331 Result := '(' + SubItems.ExportAsString(Notation) + ')' 332 else Result := SubItems.ExportAsString(Notation); 333 end; 334 ritTerminalRange: Result := '(' + TerminalFrom + ' .. ' + TerminalTo + ')'; 335 end; 336 if Optional and not Repetitive then Result := '[' + Result + ']'; 337 if Repetitive then Result := '{' + Result + '}'; 338 if AnyExcept then Result := 'other then ' + Result; 339 end; 340 end; 294 341 end; 295 342 … … 395 442 end; 396 443 444 function TRuleItems.ExportAsString(Notation: TGrammerNotation): string; 445 var 446 Item: TRuleItem; 447 begin 448 Result := ''; 449 for Item in Self do begin 450 if Item <> First then begin 451 if RuleType = rtAnd then begin 452 case Notation of 453 gnBnf: Result := Result + ' '; 454 gnEbnf: Result := Result + ', '; 455 end; 456 end else 457 if RuleType = rtOr then begin 458 case Notation of 459 gnBnf: Result := Result + ' | '; 460 gnEbnf: Result := Result + ' | '; 461 end; 462 end; 463 end; 464 Result := Result + Item.ExportAsString(Notation); 465 end; 466 end; 467 397 468 procedure TRuleItems.SetParentRule(AValue: TRule); 398 469 begin … … 456 527 end; 457 528 529 function TRule.ExportAsString(Notation: TGrammerNotation): string; 530 begin 531 case Notation of 532 gnBnf: Result := Name + ' ::= ' + Items.ExportAsString(Notation); 533 gnEbnf: Result := Name + ' = ' + Items.ExportAsString(Notation); 534 end; 535 end; 536 458 537 procedure TRule.SetGrammer(AValue: TGrammer); 459 538 begin … … 553 632 end; 554 633 634 function TRules.ExportAsString(Notation: TGrammerNotation): string; 635 var 636 Rule: TRule; 637 begin 638 Result := ''; 639 for Rule in Self do begin 640 Result := Result + Rule.ExportAsString(Notation) + LineEnding; 641 end; 642 end; 643 555 644 end. 556 645
Note:
See TracChangeset
for help on using the changeset viewer.