Skip to content

Commit

Permalink
Regenerate the parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
veelo committed May 10, 2022
1 parent 913c545 commit 9636af7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pegged/dev/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ The files used for Pegged development. Also, some files for possible, yet-to-com
Regenerates `parser.d` according to the Pegged grammar in `examples/peggedgrammar.d`. Depends on an existing and functioning `parser.d`.

```
rdmd -I../.. regenerate.d
rdmd -I../.. -I../../examples/peggedgrammar/src -I../../examples/misc/src regenerate.d
```
26 changes: 12 additions & 14 deletions pegged/parser.d
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/++
/+ DO NOT EDIT BY HAND!
This module was automatically generated from the following grammar:
Expand Down Expand Up @@ -109,7 +109,7 @@ TKNString <- (&'q{' ('q' NestedList('{',DString,'}')))
DLMString <- ('q' doublequote) ( (&'{' NestedList('{',DString,'}'))
/ (&'[' NestedList('[',DString,']'))
/ (&'$(LPAREN)' NestedList('(',DString,')'))
/ (&'(' NestedList('(',DString,')'))
/ (&'<' NestedList('<',DString,'>'))
) doublequote
Expand Down Expand Up @@ -137,14 +137,12 @@ public import pegged.peg;
import std.algorithm: startsWith;
import std.functional: toDelegate;

@safe:

struct GenericPegged(TParseTree)
@safe struct GenericPegged(TParseTree)
{
import std.functional : toDelegate;
import pegged.dynamic.grammar;
static import pegged.peg;
@safe struct Pegged
struct Pegged
{
enum name = "Pegged";
static ParseTree delegate(ParseTree) @safe [string] before;
Expand Down Expand Up @@ -209,7 +207,7 @@ struct GenericPegged(TParseTree)

template hooked(alias r, string name)
{
static ParseTree hooked(ParseTree p)
static ParseTree hooked(ParseTree p) @safe
{
ParseTree result;

Expand All @@ -228,13 +226,13 @@ struct GenericPegged(TParseTree)
return result;
}

static ParseTree hooked(string input)
static ParseTree hooked(string input) @safe
{
return hooked!(r, name)(ParseTree("",false,[],input));
}
}

static void addRuleBefore(string parentRule, string ruleSyntax)
static void addRuleBefore(string parentRule, string ruleSyntax) @safe
{
// enum name is the current grammar name
DynamicGrammar dg = pegged.dynamic.grammar.grammar(name ~ ": " ~ ruleSyntax, rules);
Expand All @@ -244,19 +242,19 @@ struct GenericPegged(TParseTree)
before[parentRule] = rules[dg.startingRule];
}

static void addRuleAfter(string parentRule, string ruleSyntax)
static void addRuleAfter(string parentRule, string ruleSyntax) @safe
{
// enum name is the current grammar named
DynamicGrammar dg = pegged.dynamic.grammar.grammar(name ~ ": " ~ ruleSyntax, rules);
foreach(name,rule; dg.rules)
foreach(ruleName,rule; dg.rules)
{
if (name != "Spacing")
rules[name] = rule;
if (ruleName != "Spacing")
rules[ruleName] = rule;
}
after[parentRule] = rules[dg.startingRule];
}

static bool isRule(string s)
static bool isRule(string s) pure nothrow @nogc
{
import std.algorithm : startsWith;
return s.startsWith("Pegged.");
Expand Down

0 comments on commit 9636af7

Please sign in to comment.