Hi, tried it out
prequelConstructs
@init {int[] n = new int[3];}
: ( // A list of options that affect analysis and/or code
generation
{n[0]==0}?=> optionsSpec {n[0]++;}
| // A list of grammars to which this grammar will delegate certain
// parts of the parsing sequence - a set of imported grammars
{n[1]==0}?=> delegateGrammars {n[1]++;}
| // The declaration of any token types we need that are not already
// specified by a preceeding grammar, such as when a parser
declares
// imaginary tokens with which to construct the AST, or a
rewriting
// tree parser adds further imaginary tokens to ones defined in a
prior
// {tree} parser.
{n[2]==0}?=> tokensSpec {n[2]++;}
| // A declaration of a scope that may be used in multiple rules
within
// the grammar spec, rather than being delcared and therefore
associated
// with, a specific rule.
attrScope
| // A declaration of language target implemented constructs. All
such
// action sections start with '@' and are given to the language
target's
// StringTemplate group. For instance @parser::header and
@lexer::header
// are gathered here.
action
)*
;
Now I get
line 9:0 missing EOF at 'tokens {'
instead of
error(20): U.g:10:0: repeated grammar prequel spec (option, token, or import);
please merge
error(20): U.g:9:0: repeated grammar prequel spec (option, token, or import);
please merge
It exits prequelConstructs at second tokens {...} and then says oh shit I am
lost, skip remaining optional stuff...heh, where is eof? This is fixed with
jim's trick of recovering in the loops better but it seems we should let it
match what it recognizes and then check counts.
prequelConstructs
@init {int[] n = new int[3];}
: ( // A list of options that affect analysis and/or code
generation
optionsSpec {n[0]++;}
| // A list of grammars to which this grammar will delegate certain
// parts of the parsing sequence - a set of imported grammars
delegateGrammars {n[1]++;}
| // The declaration of any token types we need that are not already
// specified by a preceeding grammar, such as when a parser
declares
// imaginary tokens with which to construct the AST, or a
rewriting
// tree parser adds further imaginary tokens to ones defined in a
prior
// {tree} parser.
tokensSpec {n[2]++;}
| // A declaration of a scope that may be used in multiple rules
within
// the grammar spec, rather than being delcared and therefore
associated
// with, a specific rule.
attrScope
| // A declaration of language target implemented constructs. All
such
// action sections start with '@' and are given to the language
target's
// StringTemplate group. For instance @parser::header and
@lexer::header
// are gathered here.
action
)*
{
for (int i=0; i<3; i++) {
if ( n[i]>1 ) {
//throw new CardinalityException("...");
throw new NoViableAltException("grammar prequel", 0, 0,
input);
}
}
}
;
then i get the shit error:
line 12:0 no viable alternative at input 'a'
but i could fix that.
Ter
_______________________________________________
antlr-dev mailing list
[email protected]
http://www.antlr.org/mailman/listinfo/antlr-dev