1: doctype public "-//IDN etl.sf.net//ETL//Grammar 0.2.1";
     2: grammar calculator.CalculatorLogic {
     3:     include "calculator-vars-0_2_1.g.etl";
     4:     namespace t = "http://etl.sf.net/samples/calculator";
     5:     namespace default l = "http://etl.sf.net/samples/calculator/logic";
     6:     context default Expressions {
     7:         import matchSelectors = Selectors;
     8:         import selectSelectors = Selectors;
     9:         
    10:         op composite BooleanLiteral(f) {
    11:             ^ t:BooleanLiteral {
    12:                 @ value = token(true) | token(false);
    13:             };
    14:         };
    15:         op LessThen(xfx, 1200, <) {
    16:             @ first = left;
    17:             @ second = right;
    18:         };
    19:         op LessOrEqual(xfx, 1200, <=) {
    20:             @ first = left;
    21:             @ second = right;
    22:         };
    23:         op MoreThen(xfx, 1200, >) {
    24:             @ first = left;
    25:             @ second = right;
    26:         };
    27:         op MoreOrEqual(xfx, 1200, >=) {
    28:             @ first = left;
    29:             @ second = right;
    30:         };
    31:         op Equal(xfx, 1300, ==) {
    32:             @ first = left;
    33:             @ second = right;
    34:         };
    35:         op NotEqual(xfx, 1300, !=) {
    36:             @ first = left;
    37:             @ second = right;
    38:         };
    39:         op composite RegExLiteral(f) {
    40:             ^t:RegExLiteral {
    41:                 @ value = string(prefix=R, quote='"');
    42:             };
    43:         };
    44:         op Matches(xfx, 1300, ==~) {
    45:             @ first = left;
    46:             @ second = right;
    47:         };
    48:         op LogicalNot(fy, 1400, !) {
    49:             @ value = right;
    50:         };
    51:         op ConditionalAnd(yfx, 1500, &&) {
    52:             @ first = left;
    53:             @ second = right;
    54:         };
    55:         op ConditionalOr(yfx, 1600, ||) {
    56:             @ first = left;
    57:             @ second = right;
    58:         };
    59:         op composite IfExpression(f, 1700) {
    60:             % if % (;
    61:             @ condition = expression;
    62:             %);
    63:             @ thenPart = expression(precedence = 1700);
    64:             % else {
    65:                 @ elsePart = expression(precedence = 1700);
    66:             } ?;
    67:         };
    68:         op composite IfExpressionCStyle(xfy,1700) {
    69:             ^ l:IfExpression {
    70:                 @ condition = left;
    71:                 % ?;
    72:                 @ thenPart = expression;
    73:                 % :;
    74:                 @ elsePart = right;
    75:             };
    76:         };
    77:         op composite Match(xf, 1700) {
    78:             @ value = left;
    79:             % match;
    80:             @ selectors += block(matchSelectors);
    81:         };
    82:         op composite Select(f) {
    83:             % select;
    84:             @ selectors += block(selectSelectors);
    85:         };
    86:         statement WhileStatement{
    87:             % while;
    88:             @ label = identifier?;
    89:             % (;
    90:             @ condition = expression;
    91:             % );
    92:             @ body = expression;
    93:         };
    94:         statement BreakStatement {
    95:             % break;
    96:             @ label = identifier?;
    97:         };
    98:         statement ContinueStatement {
    99:             % continue;
   100:             @ label = identifier?;
   101:         };
   102:         statement AssertStatement {
   103:             % assert;
   104:             @ condition = expression;
   105:             % : {
   106:                 @ message = expression;
   107:             } ?;
   108:         };
   109:     };
   110:     context Selectors {
   111:         import expressions = Expressions;
   112:         statement CasePart {
   113:             @ selector = expression(expressions);
   114:             % =>;
   115:             @ value = expression(expressions); 
   116:         };
   117:         statement ElsePart {
   118:             % else;
   119:             @ value = expression(expressions);
   120:         };
   121:     };
   122: };