1 /++ 2 This module was automatically generated from the following grammar: 3 4 INIGrammar: 5 6 INI < (Section / Comment)* :eoi 7 8 9 10 Comment <~ :"#" (!eol .)* (:eol/:eoi) 11 12 13 14 Section < Header :Comment? (Decl :Comment? / :Comment)* 15 16 17 18 Header < :"[" identifier (:"." identifier)? :"]" 19 20 21 22 Decl < identifier :"=" Terminals.Literal 23 24 25 26 +/ 27 module coregrammars.gen.ini; 28 29 import coregrammars.gen.terms; 30 31 32 public import pegged.peg; 33 import std.algorithm: startsWith; 34 import std.functional: toDelegate; 35 36 struct GenericINIGrammar(TParseTree) 37 { 38 import std.functional : toDelegate; 39 import pegged.dynamic.grammar; 40 static import pegged.peg; 41 struct INIGrammar 42 { 43 enum name = "INIGrammar"; 44 static ParseTree delegate(ParseTree)[string] before; 45 static ParseTree delegate(ParseTree)[string] after; 46 static ParseTree delegate(ParseTree)[string] rules; 47 import std.typecons:Tuple, tuple; 48 static TParseTree[Tuple!(string, size_t)] memo; 49 static this() 50 { 51 rules["INI"] = toDelegate(&INI); 52 rules["Comment"] = toDelegate(&Comment); 53 rules["Section"] = toDelegate(&Section); 54 rules["Header"] = toDelegate(&Header); 55 rules["Decl"] = toDelegate(&Decl); 56 rules["Spacing"] = toDelegate(&Spacing); 57 } 58 59 template hooked(alias r, string name) 60 { 61 static ParseTree hooked(ParseTree p) 62 { 63 ParseTree result; 64 65 if (name in before) 66 { 67 result = before[name](p); 68 if (result.successful) 69 return result; 70 } 71 72 result = r(p); 73 if (result.successful || name !in after) 74 return result; 75 76 result = after[name](p); 77 return result; 78 } 79 80 static ParseTree hooked(string input) 81 { 82 return hooked!(r, name)(ParseTree("",false,[],input)); 83 } 84 } 85 86 static void addRuleBefore(string parentRule, string ruleSyntax) 87 { 88 // enum name is the current grammar name 89 DynamicGrammar dg = pegged.dynamic.grammar.grammar(name ~ ": " ~ ruleSyntax, rules); 90 foreach(ruleName,rule; dg.rules) 91 if (ruleName != "Spacing") // Keep the local Spacing rule, do not overwrite it 92 rules[ruleName] = rule; 93 before[parentRule] = rules[dg.startingRule]; 94 } 95 96 static void addRuleAfter(string parentRule, string ruleSyntax) 97 { 98 // enum name is the current grammar named 99 DynamicGrammar dg = pegged.dynamic.grammar.grammar(name ~ ": " ~ ruleSyntax, rules); 100 foreach(ruleName,rule; dg.rules) 101 { 102 if (ruleName != "Spacing") 103 rules[ruleName] = rule; 104 } 105 after[parentRule] = rules[dg.startingRule]; 106 } 107 108 static bool isRule(string s) 109 { 110 import std.algorithm : startsWith; 111 return s.startsWith("INIGrammar."); 112 } 113 mixin decimateTree; 114 115 alias spacing Spacing; 116 117 static TParseTree INI(TParseTree p) 118 { 119 if(__ctfe) 120 { 121 return pegged.peg.defined!(pegged.peg.and!(pegged.peg.zeroOrMore!(pegged.peg.wrapAround!(Spacing, pegged.peg.or!(pegged.peg.wrapAround!(Spacing, Section, Spacing), pegged.peg.wrapAround!(Spacing, Comment, Spacing)), Spacing)), pegged.peg.discard!(pegged.peg.wrapAround!(Spacing, eoi, Spacing))), "INIGrammar.INI")(p); 122 } 123 else 124 { 125 if (auto m = tuple(`INI`, p.end) in memo) 126 return *m; 127 else 128 { 129 TParseTree result = hooked!(pegged.peg.defined!(pegged.peg.and!(pegged.peg.zeroOrMore!(pegged.peg.wrapAround!(Spacing, pegged.peg.or!(pegged.peg.wrapAround!(Spacing, Section, Spacing), pegged.peg.wrapAround!(Spacing, Comment, Spacing)), Spacing)), pegged.peg.discard!(pegged.peg.wrapAround!(Spacing, eoi, Spacing))), "INIGrammar.INI"), "INI")(p); 130 memo[tuple(`INI`, p.end)] = result; 131 return result; 132 } 133 } 134 } 135 136 static TParseTree INI(string s) 137 { 138 if(__ctfe) 139 { 140 return pegged.peg.defined!(pegged.peg.and!(pegged.peg.zeroOrMore!(pegged.peg.wrapAround!(Spacing, pegged.peg.or!(pegged.peg.wrapAround!(Spacing, Section, Spacing), pegged.peg.wrapAround!(Spacing, Comment, Spacing)), Spacing)), pegged.peg.discard!(pegged.peg.wrapAround!(Spacing, eoi, Spacing))), "INIGrammar.INI")(TParseTree("", false,[], s)); 141 } 142 else 143 { 144 forgetMemo(); 145 return hooked!(pegged.peg.defined!(pegged.peg.and!(pegged.peg.zeroOrMore!(pegged.peg.wrapAround!(Spacing, pegged.peg.or!(pegged.peg.wrapAround!(Spacing, Section, Spacing), pegged.peg.wrapAround!(Spacing, Comment, Spacing)), Spacing)), pegged.peg.discard!(pegged.peg.wrapAround!(Spacing, eoi, Spacing))), "INIGrammar.INI"), "INI")(TParseTree("", false,[], s)); 146 } 147 } 148 static string INI(GetName g) 149 { 150 return "INIGrammar.INI"; 151 } 152 153 static TParseTree Comment(TParseTree p) 154 { 155 if(__ctfe) 156 { 157 return pegged.peg.defined!(pegged.peg.fuse!(pegged.peg.and!(pegged.peg.discard!(pegged.peg.literal!("#")), pegged.peg.zeroOrMore!(pegged.peg.and!(pegged.peg.negLookahead!(eol), pegged.peg.any)), pegged.peg.or!(pegged.peg.discard!(eol), pegged.peg.discard!(eoi)))), "INIGrammar.Comment")(p); 158 } 159 else 160 { 161 if (auto m = tuple(`Comment`, p.end) in memo) 162 return *m; 163 else 164 { 165 TParseTree result = hooked!(pegged.peg.defined!(pegged.peg.fuse!(pegged.peg.and!(pegged.peg.discard!(pegged.peg.literal!("#")), pegged.peg.zeroOrMore!(pegged.peg.and!(pegged.peg.negLookahead!(eol), pegged.peg.any)), pegged.peg.or!(pegged.peg.discard!(eol), pegged.peg.discard!(eoi)))), "INIGrammar.Comment"), "Comment")(p); 166 memo[tuple(`Comment`, p.end)] = result; 167 return result; 168 } 169 } 170 } 171 172 static TParseTree Comment(string s) 173 { 174 if(__ctfe) 175 { 176 return pegged.peg.defined!(pegged.peg.fuse!(pegged.peg.and!(pegged.peg.discard!(pegged.peg.literal!("#")), pegged.peg.zeroOrMore!(pegged.peg.and!(pegged.peg.negLookahead!(eol), pegged.peg.any)), pegged.peg.or!(pegged.peg.discard!(eol), pegged.peg.discard!(eoi)))), "INIGrammar.Comment")(TParseTree("", false,[], s)); 177 } 178 else 179 { 180 forgetMemo(); 181 return hooked!(pegged.peg.defined!(pegged.peg.fuse!(pegged.peg.and!(pegged.peg.discard!(pegged.peg.literal!("#")), pegged.peg.zeroOrMore!(pegged.peg.and!(pegged.peg.negLookahead!(eol), pegged.peg.any)), pegged.peg.or!(pegged.peg.discard!(eol), pegged.peg.discard!(eoi)))), "INIGrammar.Comment"), "Comment")(TParseTree("", false,[], s)); 182 } 183 } 184 static string Comment(GetName g) 185 { 186 return "INIGrammar.Comment"; 187 } 188 189 static TParseTree Section(TParseTree p) 190 { 191 if(__ctfe) 192 { 193 return pegged.peg.defined!(pegged.peg.and!(pegged.peg.wrapAround!(Spacing, Header, Spacing), pegged.peg.discard!(pegged.peg.option!(pegged.peg.wrapAround!(Spacing, Comment, Spacing))), pegged.peg.zeroOrMore!(pegged.peg.wrapAround!(Spacing, pegged.peg.or!(pegged.peg.and!(pegged.peg.wrapAround!(Spacing, Decl, Spacing), pegged.peg.discard!(pegged.peg.option!(pegged.peg.wrapAround!(Spacing, Comment, Spacing)))), pegged.peg.discard!(pegged.peg.wrapAround!(Spacing, Comment, Spacing))), Spacing))), "INIGrammar.Section")(p); 194 } 195 else 196 { 197 if (auto m = tuple(`Section`, p.end) in memo) 198 return *m; 199 else 200 { 201 TParseTree result = hooked!(pegged.peg.defined!(pegged.peg.and!(pegged.peg.wrapAround!(Spacing, Header, Spacing), pegged.peg.discard!(pegged.peg.option!(pegged.peg.wrapAround!(Spacing, Comment, Spacing))), pegged.peg.zeroOrMore!(pegged.peg.wrapAround!(Spacing, pegged.peg.or!(pegged.peg.and!(pegged.peg.wrapAround!(Spacing, Decl, Spacing), pegged.peg.discard!(pegged.peg.option!(pegged.peg.wrapAround!(Spacing, Comment, Spacing)))), pegged.peg.discard!(pegged.peg.wrapAround!(Spacing, Comment, Spacing))), Spacing))), "INIGrammar.Section"), "Section")(p); 202 memo[tuple(`Section`, p.end)] = result; 203 return result; 204 } 205 } 206 } 207 208 static TParseTree Section(string s) 209 { 210 if(__ctfe) 211 { 212 return pegged.peg.defined!(pegged.peg.and!(pegged.peg.wrapAround!(Spacing, Header, Spacing), pegged.peg.discard!(pegged.peg.option!(pegged.peg.wrapAround!(Spacing, Comment, Spacing))), pegged.peg.zeroOrMore!(pegged.peg.wrapAround!(Spacing, pegged.peg.or!(pegged.peg.and!(pegged.peg.wrapAround!(Spacing, Decl, Spacing), pegged.peg.discard!(pegged.peg.option!(pegged.peg.wrapAround!(Spacing, Comment, Spacing)))), pegged.peg.discard!(pegged.peg.wrapAround!(Spacing, Comment, Spacing))), Spacing))), "INIGrammar.Section")(TParseTree("", false,[], s)); 213 } 214 else 215 { 216 forgetMemo(); 217 return hooked!(pegged.peg.defined!(pegged.peg.and!(pegged.peg.wrapAround!(Spacing, Header, Spacing), pegged.peg.discard!(pegged.peg.option!(pegged.peg.wrapAround!(Spacing, Comment, Spacing))), pegged.peg.zeroOrMore!(pegged.peg.wrapAround!(Spacing, pegged.peg.or!(pegged.peg.and!(pegged.peg.wrapAround!(Spacing, Decl, Spacing), pegged.peg.discard!(pegged.peg.option!(pegged.peg.wrapAround!(Spacing, Comment, Spacing)))), pegged.peg.discard!(pegged.peg.wrapAround!(Spacing, Comment, Spacing))), Spacing))), "INIGrammar.Section"), "Section")(TParseTree("", false,[], s)); 218 } 219 } 220 static string Section(GetName g) 221 { 222 return "INIGrammar.Section"; 223 } 224 225 static TParseTree Header(TParseTree p) 226 { 227 if(__ctfe) 228 { 229 return pegged.peg.defined!(pegged.peg.and!(pegged.peg.discard!(pegged.peg.wrapAround!(Spacing, pegged.peg.literal!("["), Spacing)), pegged.peg.wrapAround!(Spacing, identifier, Spacing), pegged.peg.option!(pegged.peg.wrapAround!(Spacing, pegged.peg.and!(pegged.peg.discard!(pegged.peg.wrapAround!(Spacing, pegged.peg.literal!("."), Spacing)), pegged.peg.wrapAround!(Spacing, identifier, Spacing)), Spacing)), pegged.peg.discard!(pegged.peg.wrapAround!(Spacing, pegged.peg.literal!("]"), Spacing))), "INIGrammar.Header")(p); 230 } 231 else 232 { 233 if (auto m = tuple(`Header`, p.end) in memo) 234 return *m; 235 else 236 { 237 TParseTree result = hooked!(pegged.peg.defined!(pegged.peg.and!(pegged.peg.discard!(pegged.peg.wrapAround!(Spacing, pegged.peg.literal!("["), Spacing)), pegged.peg.wrapAround!(Spacing, identifier, Spacing), pegged.peg.option!(pegged.peg.wrapAround!(Spacing, pegged.peg.and!(pegged.peg.discard!(pegged.peg.wrapAround!(Spacing, pegged.peg.literal!("."), Spacing)), pegged.peg.wrapAround!(Spacing, identifier, Spacing)), Spacing)), pegged.peg.discard!(pegged.peg.wrapAround!(Spacing, pegged.peg.literal!("]"), Spacing))), "INIGrammar.Header"), "Header")(p); 238 memo[tuple(`Header`, p.end)] = result; 239 return result; 240 } 241 } 242 } 243 244 static TParseTree Header(string s) 245 { 246 if(__ctfe) 247 { 248 return pegged.peg.defined!(pegged.peg.and!(pegged.peg.discard!(pegged.peg.wrapAround!(Spacing, pegged.peg.literal!("["), Spacing)), pegged.peg.wrapAround!(Spacing, identifier, Spacing), pegged.peg.option!(pegged.peg.wrapAround!(Spacing, pegged.peg.and!(pegged.peg.discard!(pegged.peg.wrapAround!(Spacing, pegged.peg.literal!("."), Spacing)), pegged.peg.wrapAround!(Spacing, identifier, Spacing)), Spacing)), pegged.peg.discard!(pegged.peg.wrapAround!(Spacing, pegged.peg.literal!("]"), Spacing))), "INIGrammar.Header")(TParseTree("", false,[], s)); 249 } 250 else 251 { 252 forgetMemo(); 253 return hooked!(pegged.peg.defined!(pegged.peg.and!(pegged.peg.discard!(pegged.peg.wrapAround!(Spacing, pegged.peg.literal!("["), Spacing)), pegged.peg.wrapAround!(Spacing, identifier, Spacing), pegged.peg.option!(pegged.peg.wrapAround!(Spacing, pegged.peg.and!(pegged.peg.discard!(pegged.peg.wrapAround!(Spacing, pegged.peg.literal!("."), Spacing)), pegged.peg.wrapAround!(Spacing, identifier, Spacing)), Spacing)), pegged.peg.discard!(pegged.peg.wrapAround!(Spacing, pegged.peg.literal!("]"), Spacing))), "INIGrammar.Header"), "Header")(TParseTree("", false,[], s)); 254 } 255 } 256 static string Header(GetName g) 257 { 258 return "INIGrammar.Header"; 259 } 260 261 static TParseTree Decl(TParseTree p) 262 { 263 if(__ctfe) 264 { 265 return pegged.peg.defined!(pegged.peg.and!(pegged.peg.wrapAround!(Spacing, identifier, Spacing), pegged.peg.discard!(pegged.peg.wrapAround!(Spacing, pegged.peg.literal!("="), Spacing)), pegged.peg.wrapAround!(Spacing, Terminals.Literal, Spacing)), "INIGrammar.Decl")(p); 266 } 267 else 268 { 269 if (auto m = tuple(`Decl`, p.end) in memo) 270 return *m; 271 else 272 { 273 TParseTree result = hooked!(pegged.peg.defined!(pegged.peg.and!(pegged.peg.wrapAround!(Spacing, identifier, Spacing), pegged.peg.discard!(pegged.peg.wrapAround!(Spacing, pegged.peg.literal!("="), Spacing)), pegged.peg.wrapAround!(Spacing, Terminals.Literal, Spacing)), "INIGrammar.Decl"), "Decl")(p); 274 memo[tuple(`Decl`, p.end)] = result; 275 return result; 276 } 277 } 278 } 279 280 static TParseTree Decl(string s) 281 { 282 if(__ctfe) 283 { 284 return pegged.peg.defined!(pegged.peg.and!(pegged.peg.wrapAround!(Spacing, identifier, Spacing), pegged.peg.discard!(pegged.peg.wrapAround!(Spacing, pegged.peg.literal!("="), Spacing)), pegged.peg.wrapAround!(Spacing, Terminals.Literal, Spacing)), "INIGrammar.Decl")(TParseTree("", false,[], s)); 285 } 286 else 287 { 288 forgetMemo(); 289 return hooked!(pegged.peg.defined!(pegged.peg.and!(pegged.peg.wrapAround!(Spacing, identifier, Spacing), pegged.peg.discard!(pegged.peg.wrapAround!(Spacing, pegged.peg.literal!("="), Spacing)), pegged.peg.wrapAround!(Spacing, Terminals.Literal, Spacing)), "INIGrammar.Decl"), "Decl")(TParseTree("", false,[], s)); 290 } 291 } 292 static string Decl(GetName g) 293 { 294 return "INIGrammar.Decl"; 295 } 296 297 static TParseTree opCall(TParseTree p) 298 { 299 TParseTree result = decimateTree(INI(p)); 300 result.children = [result]; 301 result.name = "INIGrammar"; 302 return result; 303 } 304 305 static TParseTree opCall(string input) 306 { 307 if(__ctfe) 308 { 309 return INIGrammar(TParseTree(``, false, [], input, 0, 0)); 310 } 311 else 312 { 313 forgetMemo(); 314 return INIGrammar(TParseTree(``, false, [], input, 0, 0)); 315 } 316 } 317 static string opCall(GetName g) 318 { 319 return "INIGrammar"; 320 } 321 322 323 static void forgetMemo() 324 { 325 memo = null; 326 import std.traits; 327 static if (is(typeof(Terminals.forgetMemo))) 328 Terminals.forgetMemo(); 329 } 330 } 331 } 332 333 alias GenericINIGrammar!(ParseTree).INIGrammar INIGrammar; 334