Skip to content

Commit

Permalink
some playing around
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Schadek committed Oct 22, 2018
1 parent 244c6ff commit a2f601f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 30 deletions.
20 changes: 12 additions & 8 deletions graghql.yaml
@@ -1,9 +1,13 @@
Test:
FIELD: [Field#field]
NOTFIELD: [NotField#notField]

Field:
FADS: [FieldName#name, Arguments#args, Directives#dirs, SelectionsSet#ss]
FAS: [FieldName#name, Arguments#args, SelectionsSet#ss]
FAD: [FieldName#name, Arguments#args, Directives#dirs]
FDS: [FieldName#name, Directives#dirs, SelectionsSet#ss]
FS: [FieldName#name, SelectionsSet#ss]
FD: [FieldName#name, Directives#dirs]
FA: [FieldName#name, Arguments#args]
F: [FieldName#name]
FADS: [FieldName#name, number#num]

NotField:
ONE: [FieldName#name, identifier#ident]

FieldName:
FN: [identifier#ident]

40 changes: 20 additions & 20 deletions source/app.d
Expand Up @@ -17,27 +17,23 @@ void formatIndent(O,Args...)(ref O o, long indent, string str,
formattedWrite(o, str, args);
}

interface IDarser {

}

class Darser {
import std.format;
import std.array : empty;
import std.uni : isLower, isUpper;
Rule[] rules;

Rule[] rules;
bool[string][string] firstSets;

string filename;

this(string filename) {
this.filename = filename;
this.gen();
this.genFirstSet();
}

void gen() {
auto root = Loader(this.filename);
auto root = Loader.fromFile(this.filename);
foreach(ref Node it; root) {
auto jt = it.as!(Node.Pair[])();
foreach(ref kt; jt) {
Expand All @@ -59,7 +55,7 @@ class Darser {
}
}

RulePart[string] unique(Rule rule) {
static RulePart[string] unique(Rule rule) {
RulePart[string] ret;
foreach(it; rule.subRules) {
foreach(jt; it.elements) {
Expand Down Expand Up @@ -184,12 +180,18 @@ class Darser {
}

void genRules(File.LockingTextWriter ltw) {
auto t = new Trie();
foreach(rule; this.rules) {
foreach(subRule; rule.subRules) {
ruleToTrieRecur(t, subRule, subRule.elements, rule.name);
}
this.genRule(ltw, rule);
}
writeln("\n\n\n\nTrie\n");
printTrie(t, 0);
}

void genIndent(File.LockingTextWriter ltw, int indent) {
static void genIndent(File.LockingTextWriter ltw, int indent) {
while(indent > 0) {
formattedWrite(ltw, "\t");
--indent;
Expand Down Expand Up @@ -246,7 +248,7 @@ class Darser {
//writeln(this.firstSets);
}

void genVis(bool cns)(File.LockingTextWriter ltw, Rule rule) {
static void genVis(bool cns)(File.LockingTextWriter ltw, Rule rule) {
formatIndent(ltw, 0, "\n");
if(cns) {
formatIndent(ltw, 1, "void accept(const(%s) obj) {\n",
Expand Down Expand Up @@ -291,13 +293,13 @@ class Darser {
formatIndent(ltw, 0, "}\n");
}

void genParse(File.LockingTextWriter ltw, const(size_t) idx,
static void genParse(File.LockingTextWriter ltw, const(size_t) idx,
const(size_t) off, Trie t, int indent, Trie[] fail)
{
if(idx > 0) {
formattedWrite(ltw, " else ");
} else {
this.genIndent(ltw, indent);
genIndent(ltw, indent);
}

bool isRepeat = false;
Expand All @@ -316,7 +318,7 @@ class Darser {
formatIndent(ltw, indent + 1, "this.lex.popFront();\n");
} else {
formattedWrite(ltw, "%s(this.first%s()) {\n", prefix, t.value.name);
this.genIndent(ltw, indent + 1);
genIndent(ltw, indent + 1);
if(t.value.storeThis) {
formattedWrite(ltw, "%1$s %2$s = this.parse%1$s();\n",
t.value.name, t.value.storeName
Expand All @@ -343,7 +345,7 @@ class Darser {
formatIndent(ltw, indent, "}");
}

void genFirst(File.LockingTextWriter ltw, Rule rule) {
static void genFirst(File.LockingTextWriter ltw, Rule rule) {
bool[string] found;
formatIndent(ltw, 1, "bool first%s() const {\n", rule.name);
formatIndent(ltw, 2, "return ");
Expand Down Expand Up @@ -373,9 +375,7 @@ class Darser {
formattedWrite(ltw, ";\n\t}\n\n");
}

void genTrieCtor(File.LockingTextWriter ltw, Trie t, int indent)
const
{
static void genTrieCtor(File.LockingTextWriter ltw, Trie t, int indent) {
//formatIndent(ltw, indent + 1, "ret.ruleSelection = %1$sEnum.%2$s;\n",
// t.ruleName, t.subRuleName
//);
Expand All @@ -392,7 +392,7 @@ class Darser {
formatIndent(ltw, indent + 1, ");");
}

void genThrow(File.LockingTextWriter ltw, int indent, Trie[] fail) {
static void genThrow(File.LockingTextWriter ltw, int indent, Trie[] fail) {
formatIndent(ltw, indent, "auto app = appender!string();\n");
formatIndent(ltw, indent, "formattedWrite(app, \n");
formatIndent(ltw, indent + 1, "\"Was expecting an");
Expand All @@ -413,7 +413,7 @@ class Darser {
formatIndent(ltw, indent, ");\n");
}

void genRule(File.LockingTextWriter ltw, Rule rule) {
static void genRule(File.LockingTextWriter ltw, Rule rule) {
genFirst(ltw, rule);
auto t = ruleToTrie(rule);
writeln("Rule Trie Start");
Expand Down Expand Up @@ -471,7 +471,7 @@ class Darser {
formatIndent(ltw, 0, "}\n");
}

void genParseException(File.LockingTextWriter ltw) {
static void genParseException(File.LockingTextWriter ltw) {
formatIndent(ltw, 0, "module exception;\n\n");

formatIndent(ltw, 0, "class ParseException : Exception {\n");
Expand Down
4 changes: 2 additions & 2 deletions source/rules.d
Expand Up @@ -25,11 +25,11 @@ class RulePart {
}

bool terminal() pure const @safe {
return this.name.front.isUpper();
return this.name.front.isLower();
}

bool nonterminal() pure const @safe {
return this.name.front.isLower();
return this.name.front.isUpper();
}

override string toString() pure const @safe {
Expand Down
5 changes: 5 additions & 0 deletions source/rulevalidate.d
@@ -0,0 +1,5 @@
module rulevalidate;
import rules;

void ruleValidate(const(Rule)[] rules, const(bool[string][string]) firstSets) {
}

0 comments on commit a2f601f

Please sign in to comment.