nuthatchery / metaxa

MetaXa – an experimental language definition meta-system
1 stars 0 forks source link

metaxa descriptions which begin with whitespace or a comment do not parse #2

Open LemmingAvalanche opened 9 years ago

LemmingAvalanche commented 9 years ago

This works:

construct Empty() { // Language that only accepts the empty string.
    syntax {}
}

But not this:

// Language that only accepts the empty string.
construct Empty() {
    syntax {}
}

Nor this (file/text starts with whitespace):


construct Empty() { // Language that only accepts the empty string.
    syntax {}
}
anyahelene commented 9 years ago

You need to tell the parser to parse start[P]. You'll then get a parsetree with the root representing the start symbol, which has layout/comments to the left and right of it, and a top field containing your actual tree.

From the tutor (http://tutor.rascal-mpl.org/Rascal/Declarations/SyntaxDefinition/SyntaxDefinition.html):

The start modifier identifies the start of a grammar. The effect of a start modifier is that Rascal will generate an extra syntax definition before generating a parser that allows layout to before and after the start non-terminal. For example: layout L = [\ ]; start Program = Statement; will produce syntax start[Program] = L Program top L;. Note that the start[Program] type is now available in your program, and ParseTrees assigned to variable of that type will allow access to the top field.