dlang-community / Pegged

A Parsing Expression Grammar (PEG) module, using the D programming language.
533 stars 66 forks source link

How do you use dub + pegged + asModule? #321

Closed enjoysmath closed 1 year ago

enjoysmath commented 1 year ago

Following the arithmetic example as in the Wiki. I put:

module variable;

import language;
import pegged.grammar;

class Variable : Language
{

package:
   static enum grammar = `
      Variable:
         Var <- identifier;
   `;
}

static this() {
   asModule("grammar.variable", "grammar/variable", Variable.grammar);
}

The wiki says that it will generate grammar/variable.d in the current directory but it doesn't generate jack shit.

enjoysmath commented 1 year ago

Got it to build the fucking grammar module:

module variable;

import language;
import pegged.grammar;

class Variable : Language
{

package:
   static enum grammar = `
      Variable:
         Var <- "C"
   `;
}

static this() {
   try {
      asModule(__MODULE__ ~ "_grammar", "source/" ~ __MODULE__ ~ "_grammar", Variable.grammar);
   }
   catch (Exception e)
   {
      import std.stdio;
      writeln(e);
   }
}