-- @authors Frédéric Jouault -- @date 2007/09/19 -- @description This TCS model defines the syntax of the ANTLRv2 language. -- REMARK: this model can only be used for serialization so far. -- NOT TO BE USED as a typical example of TCS model. syntax ANTLR { primitiveTemplate identifier for String default using NAME: value = "%token%"; primitiveTemplate stringSymbol for String using STRING: value = "%token%", serializer="'\'' + %value%.toCString() + '\''"; primitiveTemplate integerSymbol for Integer default using INT: value = "Integer.valueOf(%token%)"; primitiveTemplate floatSymbol for Double default using FLOAT: value = "Double.valueOf(%token%)"; primitiveTemplate booleanSymbol for Boolean default using BOOLEAN: value = "Boolean.valueOf(%token%)"; template Grammar main : (isDefined(package) ? "header" "{" "package" package ";" "}" ) "class" name "Parser" "extends" "Parser" ";" "options" "{" [ options ] "}" (isDefined(actions) ? "{" [ actions ] "}" ) [ rules ] {indentIncr = 0, nbNL = 2} (isDefined('lexer') ? 'lexer' [ lexerRules ] {indentIncr = 0, nbNL = 2} ) ; template ProductionRule : name (isDefined(parameters) ? "[" parameters{separator = ","} "]" ) (isDefined(returns) ? "returns" "[" returns "]" ) (isDefined(options) ? "options" "{" options "}" ) -- OR not possible in TCS yet --(isDefined(declarations) or isDefined(labelDeclarations) ? "{" (isDefined(declarations) ? declarations ) (isDefined(labelDeclarations) ? labelDeclarations ) "}" --) ":" (isDefined(expression) ? expression ) (isDefined(actions) ? [ "{" [ actions ] "}" ] {indentIncr = 2} ) ";" ; template VariableDeclaration : type name (isDefined(initialValue) ? "=" initialValue ) ";" ; template Parameter : type name ; template Variable : declaration{refersTo = name} ; template Expression abstract; template Alternative : (isDefined(options) ? "options" "{" options "}" ":" ) (one(expressions) ? expressions : "(" expressions{separator = "|"} ")" ) ; template Concatenation : (isDefined(syntacticPredicate) ? "(" syntacticPredicate ")" "=>" ) (isDefined(options) ? -- was after "(", same for Alternative "options" "{" options "}" ":" ) (one(expressions) ? expressions : "(" expressions ")" ) (isDefined(action) ? "{" action "}" ) ; template Terminal : "\"" 'value' "\"" (isDefined(action) ? "{" action "}" ) ; -- @begin ForLexer template CharTerminal : "\'" 'value' "\'" (isDefined(action) ? "{" action "}" ) ; template Negation : "~" expression ; template Drop : expression "!" ; template Interval : start ".." end ; -- @end ForLexer template RuleCall : (isDefined(syntacticPredicate) ? "(" syntacticPredicate ")" "=>" ) (isDefined(storeTo) ? storeTo "=" ) calledRule{refersTo = name} (isDefined(arguments) ? "[" arguments{separator = ","} "]" ) (isDefined(action) ? "{" action "}" ) ; template TokenCall : (isDefined(storeASTTo) ? storeASTTo ":" ) name (isDefined(action) ? "{" action "}" ) ; template SemanticAction abstract; template SimpleSemanticAction : 'value' ; template SemanticActionBlock : actions ; template ActionExpression abstract; template TextualExpression : 'value' ; template LiteralExpression : 'value' ; template Sequence_ : "(" (isDefined(options) ? "options" "{" options "}" ":" ) expression ")" (lower = 0 ? (upper = 1 ? "?") (upper = -1 ? "*") ) (lower = 1 ? (upper = -1 ? "+") ) ; symbols { lsquare = "["; rsquare = "]" : rightSpace; excl = "!"; coma = ","; lparen = "("; rparen = ")"; lcurly = "{" : leftSpace; rcurly = "}"; semi = ";"; colon = ":" : leftSpace, rightSpace; colons = "::"; pipe = "|"; sharp = "#"; qmark = "?"; -- operator symbols point = "."; rarrow = "->"; minus = "-"; star = "*"; slash = "/"; plus = "+"; eq = "="; gt = ">"; lt = "<"; ge = ">="; le = "<="; ne = "<>"; larrow = "<-"; } lexer = " // no need for lexer for a serialization-only TCS model "; }