1 module metad.grammar.inifile;
2 
3 private import std.array;
4 
5 private import pegged.grammar;
6 private import metad.compiler;
7 private import metad.interp;
8 
9 private import metad.gen.grammar.elements;
10 
11 enum INIGrammarFilename = "grammar/inifile.peg";
12 enum INIGrammarText = import(INIGrammarFilename);
13 
14 version(INIGrammar_Generate) {
15 	static this() {
16 		import std.file;
17 		mkdirRecurse("source/metad/gen/grammar");
18 		asModule("metad.gen.grammar.inigrammar","source/metad/gen/grammar/inigrammar",INIGrammarText,"private import metad.gen.grammar.elements;");
19 	}
20 }
21 
22 version(INIGrammar_Inline) {
23 	mixin(grammar(INIGrammarText));
24 } else {
25 	private import metad.gen.grammar.inigrammar;
26 }
27 
28 struct INIGrammarCompiler(ParseTree T) {
29 	template _ident(alias id) {
30 		enum _ident = id;
31 	}
32 	template _section(alias head,T...) {
33 		//enum _section=compileNode!(T.children[0]);
34 		//enum _section = compileChildNodes;
35 	}
36 	template _sectionhead() {
37 
38 	}
39 	template _declaration() {
40 
41 	}
42 	template _literal() {
43 
44 	}
45 	//@Match!(INIGrammar.Section)
46 	@MatchCond("T.children.length>=1 && T.Name == INIGrammar.Section")
47 	static auto matchSection(ParseTree t) {
48 		return "_section!("~compileChildNodes.join(",")~")";
49 	}
50 	@MatchName("INIGrammar.SectionHead")
51 	static auto matchSectionHead(ParseTree t) {
52 		return "_sectionhead!("~compileChildNodes~")";
53 	}
54 	//@Match!(INIGrammar.Declaration)
55 	@MatchName("INIGrammar.Declaration")
56 	static auto matchDefinition(ParseTree t) {
57 		return "declaration!("~")";
58 	}
59 	//@Match!(identifier) 
60 	@MatchName("identifier") 
61 	static auto matchIdentifier(ParseTree t) {
62 		return "_ident!("~T.matches.join~")";
63 	}
64 	@MatchName("INIGrammar")
65 	static auto matchGrammar(ParseTree t) {
66 		return compileChildNodes.join;
67 	}
68 	mixin Compiler!(T,INIGrammarCompiler!T);
69 	mixin processTypeAnnotations!INIGrammarCompiler;
70 
71 }
72 
73 unittest {
74 	import std.experimental.logger;
75 	enum INIFILE = "tests/test.ini";
76 	enum INITEXT = import(INIFILE);
77 	enum compiled = INIGrammarCompiler!(INIGrammar(INITEXT)).compileNode();
78 	pragma(msg,"Compiled: " ~ compiled);
79 	//mixin(compiled);
80 }