Get started
Grammars and edition
API Documentation
Release Notes
It is possible to make one grammar inherit from one or more grammars. This means that all terminals, variables, and their associated lexical and syntactic rules defined in the inherited grammars will be understood in the inheriting one as if defined in it. This is expressed in the following manner:
grammar MyGrammar : BaseGram1, BaseGram2 {}
BaseGram1
and BaseGram2
are understood in MyGrammar
as if defined in there. The priority of the lexical rules is then, from the lowest to the highest:BaseGram1
BaseGram1
BaseGram2
BaseGram2
MyGrammar
MyGrammar
BaseGram1
and BaseGram2
are understood in MyGrammar
as if defined in there.BaseGram1
and BaseGram2
are understood in MyGrammar
as if defined in there.Example:
grammar Commons
{
options { }
terminals
{
IDENTIFIER -> [_a-zA-Z] [_a-zA-Z0-9]* ;
}
grammar { }
}
grammar CSharp : Commons
{
options
rules
{
class -> 'class' IDENTIFIER '</span> <span style={{color:"darkorange"}}>' ;
}
}
grammar Python : Commons
{
options
rules
{
class -> 'class' IDENTIFIER ':' ;
}
}