-- The different sections of a TCS model have been enclosed between BEGIN and END -- comments below. Additional information is provided below each BEGIN comment. -- The main sections of interest are "Class templates", and -- "Operator table" (only for DSLs using operators). syntax RSL { -- BEGIN Primitive templates -- Specifies representation of primitive types. -- Only needs modification when default lexer is not satisfactory. -- Generally modified along with the lexer. primitiveTemplate identifier for String default using NAME: value = "%token%"; primitiveTemplate stringSymbol for String using STRING: value = "%token%", serializer="'\'' + %value%.toCString() + '\''"; primitiveTemplate treeFragmentSymbol for String using TREEFRAGMENT: value = "%token%"; primitiveTemplate integerSymbol for Integer default using INT: value = "Integer.valueOf(%token%)"; primitiveTemplate floatSymbol for Double default using FLOAT: value = "Double.valueOf(%token%)"; -- END Primitive templates -- BEGIN Class templates -- Specifies representation of classes. -- This is the main section to work on. template RSL main : [domain rslelems ] {nbNL = 2,indentIncr = 0, startNL = false} [ruleset]{nbNL = 1,indentIncr = 0} ; template RSLelements abstract; template Domain : "default" "base" "domain" dname "." ; template ExternalPattern : "external" "pattern" phead ":" ptoken ["="] {nbNL = 1,indentIncr = 1} eptext {as = stringSymbol} "in" "domain" dname "." ; template Pattern abstract : "pattern" phead ":" ptoken ["=" ptext "."] ; template PatternText abstract; template SimplePatternText : ptext{as = treeFragmentSymbol} ; template ConditionalPatternText : ptext "if" pref ; template PatternHead : name "(" params{separator = ","} ")" ; template PatternParameter : name ":" referTo ; template Condition : "external" "condition" chead "=" ctext {as = stringSymbol} "." ; template ConditionHead : name "(" [params{separator = ","} ")"] {indentIncr = 1} ; template ConditionParameter : name ":" referTo ; template Rule : "rule" rname "(" [params{separator = ","} ")"]{indentIncr = 1} ":" [type "->" type] "=" [r_lhs_pattern] "->" [r_rhs_pattern "."] ; template RuleParameter : name ":" referTo ; template RuleLHS : ruletext ; template RuleRHS : ruletext [condition] {indentIncr = 0} ; template RuleText abstract; template SimpleRuleText : text{as = treeFragmentSymbol} ; template IDRuleText : text ; template ComplexRuleText : pref ; template RuleCondition abstract; template RuleEqCondition : "if" lhs "==" pref ; template RuleNotEqCondition : "if" lhs "~=" pref ; template Parameter abstract; template PatternRef : name "(" params{separator = ","} ")" ; template RealParameter : name ; template RuleSet : "public" "ruleset" rsname "=" "{" rname {separator = ","} "}" "." ; -- END Class templates -- BEGIN Special symbols -- Possible modifications: -- - Addition of new symbols. -- - Modification of spaces information. -- - Removal of unused symbols so that using these symbols results in lexical -- error rather than parsing error. symbols { lsquare = "["; rsquare = "]" : rightSpace; excl = "!"; coma = "," : leftNone, rightSpace; lparen = "("; rparen = ")" : leftNone, rightSpace; lcurly = "{" : leftSpace; rcurly = "}" : leftNone, rightSpace; semi = ";" : leftNone, rightSpace; colon = ":" : leftSpace, rightSpace; pipe = "|" : leftSpace, rightSpace; sharp = "#" : leftSpace; qmark = "?"; coloncolon = "::" : leftNone, rightNone; -- operator symbols point = "." : leftNone; rarrow = "->" : leftNone; minus = "-" : leftSpace, rightSpace; star = "*" : leftSpace, rightSpace; slash = "/" : leftSpace, rightSpace; plus = "+" : leftSpace, rightSpace; eq = "=" : leftSpace, rightSpace; gt = ">" : leftSpace, rightSpace; lt = "<" : leftSpace, rightSpace; ge = ">=" : leftSpace, rightSpace; le = "<=" : leftSpace, rightSpace; ne = "<>" : leftSpace, rightSpace; larrow = "<-" : leftSpace, rightSpace; } -- END Special symbols -- BEGIN Operator table -- Defines all operators with their priority, arity, and associativity. -- All defined operators must be used in operator templates. -- No operator in SampleDSL. The Calc DSLs may be used as examples. -- END Operator table -- BEGIN Lexer -- Specifies the lexical entities. -- Only needs modification when default lexer is not satisfactory. -- Generally modified along with Primitive templates. token COMMENT : endOfLine(start = "--"); token TREEFRAGMENT : multiLine(start = "\"", end = "\""); lexer = " %options testLiterals = false; NL : ( '\\r' '\\n' | '\\n' '\\r' //Improbable | '\\r' | '\\n' ) {newline();} ; WS : ( ' ' | '\\t' ) ; %protected DIGIT : '0'..'9' ; %protected ALPHA : 'a'..'z' | 'A'..'Z' | '_' //For Unicode compatibility (from 0000 to 00ff) | '\\u00C0' .. '\\u00D6' | '\\u00D8' .. '\\u00F6' | '\\u00F8' .. '\\u00FF' ; %protected SNAME %v2 options { %v2 testLiterals = true; %v2 } : (ALPHA) (ALPHA | DIGIT)* ; NAME : ( %v3 SNAME %v2 s:SNAME {if(s.getType() != SNAME) $setType(s.getType());} ) ; INT : (DIGIT)+ %v2 (('.' DIGIT)=> '.' (DIGIT)+ {$setType(FLOAT);})? ; %v3 FLOAT : DIGIT+ '.' DIGIT* ; %protected ESC : '\\\\'! ( 'n' %v2{%setText(\"\\n\");} | 'r' %v2{%setText(\"\\r\");} | 't' %v2{%setText(\"\\t\");} | 'b' %v2{%setText(\"\\b\");} | 'f' %v2{%setText(\"\\f\");} | '\"' %v2{%setText(\"\\\"\");} | '\\'' %v2{%setText(\"\\'\");} | '\\\\' %v2{%setText(\"\\\\\");} | ( ('0'..'3') ( %v2 options { %v2 warnWhenFollowAmbig = false; %v2 } : ('0'..'7') ( %v2 options { %v2 warnWhenFollowAmbig = false; %v2 } : '0'..'7' )? )? | ('4'..'7') ( %v2 options { %v2 warnWhenFollowAmbig = false; %v2 } : ('0'..'7') )? ) { %v2 String s = %getText; %v2 int i; %v2 int ret = 0; %v2 String ans; %v2 for (i=0; i