Changeset 124 for branches/generator/URules.pas
- Timestamp:
- Nov 29, 2017, 5:09:16 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/generator/URules.pas
r123 r124 116 116 FileName: string; 117 117 Rules: TRules; 118 TopRule: TRule; 118 119 procedure LoadFromXmlFile(FileName: string); 119 120 procedure SaveToXmlFile(FileName: string); … … 149 150 Add(' Source;'); 150 151 Add(''); 151 Add('procedure Compile;'); 152 Add('procedure Compile(FileName: string);'); 153 Add('var'); 154 Add(' SourceFile: Text;'); 152 155 Add('begin'); 156 Add(' AssignFile(SourceFile, FileName);'); 157 Add(' Reset(SourceFile);'); 158 Add(' SetLength(Content, FileSize(SourceFile));'); 159 Add(' Read(SourceFile, Content);'); 160 if Assigned(TopRule) then 161 Add(' Parse' + TopRule.Name + ';'); 162 Add(' CloseFile(SourceFile);'); 153 163 Add('end;'); 154 164 Add(''); 155 165 Add('begin'); 156 Add(' Compile;'); 166 Add(' if ParamCount > 1 then'); 167 Add(' Compile(ParamStr(1));'); 157 168 Add('end.'); 158 169 SaveToFile(FileName); … … 181 192 Add(''); 182 193 Add('type'); 183 for Rule in Rules do begin 194 for Rule in Rules do 195 if Rule.CreateSourceNode then begin 184 196 Add(' T' + Rule.Name + ' = class;'); 185 197 end; 186 198 Add(''); 187 for Rule in Rules do begin 199 for Rule in Rules do 200 if Rule.CreateSourceNode then begin 188 201 Add(' T' + Rule.Name + ' = class'); 189 202 for Item in Rule.Items do begin … … 198 211 Add('implementation'); 199 212 Add(''); 200 for Rule in Rules do 201 if Rule.CreateSourceNode then begin 213 for Rule in Rules do begin 202 214 Add('function Parse' + Rule.Name + ': Boolean;'); 203 215 Add('begin'); … … 212 224 Line := Line + ''; 213 225 end; 214 if Item.RuleItemType = ritTerminal then 215 Line := Line + 'Expect(''' + Item.Terminal + ''')' 216 else if Item.RuleItemType = ritNonTerminal then 217 Line := Line + 'Parse' + Item.NonTerminal.Name; 226 case Item.RuleItemType of 227 ritTerminal: Line := Line + 'Expect(''' + Item.Terminal + ''')'; 228 ritNonTerminal: Line := Line + 'Parse' + Item.NonTerminal.Name; 229 ritTerminalRange: Line := Line + 'Expect(''' + Item.Terminal + ''')'; 230 end; 218 231 if Rule.Items.RuleType = rtOr then begin 219 232 Line := Line + ' then '; … … 245 258 RulesNode: TDOMNode; 246 259 Rule: TRule; 260 TopRuleName: string; 247 261 begin 248 262 Self.FileName := FileName; … … 257 271 Rules.LoadFromXmlNode(RulesNode); 258 272 end; 273 274 TopRule := Rules.FindName(ReadString(RootNode, 'TopRule', '')); 259 275 end; 260 276 finally … … 282 298 RootNode.AppendChild(RulesNode); 283 299 Rules.SaveToXmlNode(RulesNode); 300 301 if Assigned(TopRule) then 302 WriteString(RootNode, 'TopRule', TopRule.Name); 284 303 285 304 WriteXMLFile(Doc, FileName);
Note:
See TracChangeset
for help on using the changeset viewer.