Package org.sablecc.sablecc.xss2; Helpers letter = ['A'..'Z'] | ['a'..'z'] | [0x7F .. 0xFF]; digit = ['0'..'9']; nondigit = '_' | letter; sign = '+' | '-'; digit_seq = digit+; letter_seq = letter+; nondigit_seq = nondigit+; identifier = nondigit (digit | nondigit)*; all = [0 .. 0xFFFF]; cr = 13; lf = 10; tab = 9; eol = cr | lf | cr lf; blank = (eol | tab | ' '); a = ['a' + 'A']; b = ['b' + 'B']; c = ['c' + 'C']; d = ['d' + 'D']; e = ['e' + 'E']; f = ['f' + 'F']; g = ['g' + 'G']; h = ['h' + 'H']; i = ['i' + 'I']; j = ['j' + 'J']; k = ['k' + 'K']; l = ['l' + 'L']; m = ['m' + 'M']; n = ['n' + 'N']; o = ['o' + 'O']; p = ['p' + 'P']; q = ['q' + 'Q']; r = ['r' + 'R']; s = ['s' + 'S']; t = ['t' + 'T']; u = ['u' + 'U']; v = ['v' + 'V']; w = ['w' + 'W']; x = ['x' + 'X']; y = ['y' + 'Y']; z = ['z' + 'Z']; States data, code, xpath, ixpath; Tokens {data} data_comment = '[-!' ([all - '!'] | '!' [all - '-'] | '!-' [all - ']'])* '!-]'; {data->code} cmd_start = '[-'; {code->data} cmd_end = '-]'; {code} foreach = f o r e a c h; {code} reverse_foreach = r e v e r s e '_' f o r e a c h; {code} if = i f; {code} else = e l s e; {code} choose = c h o o s e; {code} when = w h e n; {code} end = e n d; {code} include = i n c l u d e; {code} in = i n; {code} otherwise = o t h e r w i s e; {code} set = s e t; {code} param = p a r a m; {code} output = o u t p u t; {code} template = t e m p l a t e; {code} call = c a l l; {code} sep = s e p; {code} print = p r i n t; {code} equals = '='; {code} l_par = '('; {code} r_par = ')'; {code} comma = ','; {code} plus = '+'; {data} data = ([all - ['[' + ['$' + '@']]] | '['+ [all - ['-' + ['@' + '$']]] |'['+ '--' | '$$' | '@@')+ | '['; {data->ixpath} ixpath_start = '${'; {code, data} iattrib = '@' identifier | '@{' identifier '}'; {code, data} ivar = '$' identifier; {code, xpath, ixpath} blank = blank+; {code} identifier = identifier; {code->xpath} xpath_start = '{'; {code} literal = '"' ([all - '"'] | '""')* '"' | ''' ([all - '''] | ''' ''')* '''; // ' {code} comment = '//' [all - [cr + lf]]* eol; {xpath, ixpath} xname = identifier (':' identifier)?; // XXX remove the colon part? allow only for functions? {xpath, ixpath} xvar = '$' identifier; {xpath, ixpath} xsep_any = '//'; {xpath, ixpath} xsep_one = '/'; {xpath, ixpath} xcurrent = '.'; {xpath, ixpath} xparent = '..'; {xpath, ixpath} xattrib = '@' identifier; {xpath, ixpath} xl_brace = '['; {xpath, ixpath} xr_brace = ']'; {xpath, ixpath} xl_par = '('; {xpath, ixpath} xr_par = ')'; {xpath, ixpath} xequals = '='; {xpath, ixpath} xnot_equals = '!='; {xpath, ixpath} xadd = '+'; {xpath, ixpath} xsub = '-'; {xpath, ixpath} xcomma = ','; {xpath, ixpath} xliteral = '"' ([all - '"'] | '""')* '"' | ''' ([all - '''] | ''' ''')* '''; // ' {xpath, ixpath} xnumber = digit_seq; {xpath->code, ixpath->data} xpath_end = '}'; Ignored Tokens blank, comment, data_comment; Productions script {-> script} = statement* {-> New script([statement.statement]) } ; statement {-> statement} = {empty} cmd_start cmd_end {-> New statement.empty() } | {data} data {-> New statement.data(data) } | {foreach} [cs1]:cmd_start [fe1]:foreach foreach_arg? xpath_start xpath_expr xpath_end [ce1]:cmd_end statement* [cs2]:cmd_start end [fe2]:foreach? [ce2]:cmd_end {-> New statement.foreach (foreach_arg.identifier, xpath_expr.xpath_expr, [statement.statement]) } | {include} cmd_start include literal cmd_end {-> New statement.include (literal) } | {choose} [cs1]:cmd_start [c1]:choose [ce1]:cmd_end choose_when* choose_otherwise? data? [cs2]:cmd_start end [c2]:choose? [ce2]:cmd_end {-> New statement.choose ([choose_when.choose_when], [choose_otherwise.otherwise]) } | {set} cmd_start set arg_list cmd_end {-> New statement.set([arg_list.arg]) } | {param} cmd_start param oarg_list cmd_end {-> New statement.param([oarg_list.oarg]) } | {output} [cs1]:cmd_start output expr [ce1]:cmd_end statement* [cs2]:cmd_start end [o2]:output? [ce2]:cmd_end {-> New statement.output (expr, [statement]) } | {ixpath} ixpath_start xpath_expr xpath_end {->New statement.print (New expr.xpath(xpath_expr.xpath_expr)) } | {iattrib} iattrib {->New statement.print(New expr.iattrib(iattrib)) } | {ivar} ivar {->New statement.print(New expr.ivar(ivar)) } | {template} [cs1]:cmd_start [t1]:template identifier l_par oarg_list? r_par [ce1]:cmd_end statement* [cs2]:cmd_start end [t2]:template? [ce2]:cmd_end {-> New statement.template (identifier, [oarg_list.oarg], [statement]) } | {call} [cs1]:cmd_start [c1]:call identifier l_par arg_list? r_par [ce1]:cmd_end {-> New statement.call (identifier, [arg_list.arg]) } | {if} [cs1]:cmd_start [i1]:if expr cmd_end statement* [cs2]:cmd_start end [i2]:if? [ce2]:cmd_end {-> New statement.if (expr, [statement], [New statement.empty()]) } | {if_else} [cs1]:cmd_start [i1]:if expr cmd_end statement* [cs3]:cmd_start else [ce3]:cmd_end [estmt]:statement* [cs2]:cmd_start end [i2]:if? [ce2]:cmd_end {-> New statement.if (expr, [statement], [estmt.statement]) } | {separator} cmd_start sep expr cmd_end {-> New statement.separator(expr) } | {print} cmd_start print expr cmd_end {-> New statement.print(expr) } ; foreach_arg {-> identifier}= identifier in {-> identifier} ; arg {-> arg} = identifier equals expr {-> New arg(identifier, expr) } ; arg_list {-> arg*} = {simple} arg {-> [arg.arg] } | {list} arg_list comma arg {-> [arg_list.arg, arg.arg] } ; oarg {-> oarg} = identifier oarg_tail? {-> New oarg(identifier, oarg_tail.expr) } ; oarg_tail {-> expr} = equals expr {-> expr} ; oarg_list {-> oarg*} = {simple} oarg {-> [oarg.oarg] } | {list} oarg_list comma oarg {-> [oarg_list.oarg, oarg.oarg] } ; choose_when {-> choose_when } = [d1]:data? [cs1]:cmd_start [c1]:when expr [ce1]:cmd_end statement* [cs2]:cmd_start end [c2]:when? [ce2]:cmd_end {-> New choose_when (expr, [statement]) } ; choose_otherwise {-> [otherwise]:statement* } = [d1]:data? [cs1]:cmd_start [o1]:otherwise [ce1]:cmd_end statement* [cs2]:cmd_start end [o2]:otherwise? [ce2]:cmd_end {-> [statement] } ; expr {-> expr} = {concat} [e1]:expr plus [e2]:expr2 {-> New expr.concat(e1.expr, e2.expr) } | {other} [e1]:expr2 {-> e1.expr} ; expr2 {-> expr} = {literal} literal {-> New expr.literal(literal) } | {xpath} xpath_start xpath_expr xpath_end {-> New expr.xpath(xpath_expr.xpath_expr) } | {iattrib} iattrib {-> New expr.iattrib(iattrib) } | {ivar} ivar {-> New expr.ivar(ivar) } | {group} l_par expr r_par {-> expr.expr } ; xpath_expr {-> xpath_expr} = {add} [e1]:xpath_expr xadd [e2]:xpath_compare {-> New xpath_expr.add(e1, e2.xpath_expr) } | {sub} [e1]:xpath_expr xsub [e2]:xpath_compare {-> New xpath_expr.sub(e1, e2.xpath_expr) } | {other} xpath_compare {-> xpath_compare.xpath_expr } ; xpath_compare {-> xpath_expr} = {equals} [e1]:xpath_compare xequals [e2]:xpath_simple {-> New xpath_expr.equals(e1.xpath_expr, e2.xpath_expr) } | {not_equals} [e1]:xpath_compare xnot_equals [e2]:xpath_simple {-> New xpath_expr.not_equals(e1.xpath_expr, e2.xpath_expr) } | {other} xpath_simple {-> xpath_simple.xpath_expr } ; xpath_simple {-> xpath_expr} = {path} xpath_path {-> xpath_path.xpath_expr } | {function} xpath_function {-> xpath_function.xpath_expr } | {parenthesis} xl_par xpath_expr xr_par {-> xpath_expr.xpath_expr} | {literal} xliteral {-> New xpath_expr.literal(xliteral) } | {attrib} xattrib {-> New xpath_expr.path([New xpath_path_elem(Null, New xpath_elem.attrib(xattrib), Null)]) } | {number} xnumber {-> New xpath_expr.number(xnumber) } ; xpath_path {-> xpath_expr} = {normal} xpath_separator? xpath_elem xpath_path_elem* xpath_path_tail? {-> New xpath_expr.path ([New xpath_path_elem(xpath_separator, xpath_elem.elem, xpath_elem.condition), xpath_path_elem, xpath_path_tail.xpath_path_elem]) } | {var} xvar xpath_path_elem* xpath_path_tail? {-> New xpath_expr.path ([New xpath_path_elem(Null, New xpath_elem.var(xvar), Null), xpath_path_elem, xpath_path_tail.xpath_path_elem]) } | {var_cond} xvar xl_brace xpath_expr xr_brace xpath_path_elem* xpath_path_tail? {-> New xpath_expr.path ([New xpath_path_elem(Null, New xpath_elem.var(xvar), xpath_expr.xpath_expr), xpath_path_elem, xpath_path_tail.xpath_path_elem]) } ; xpath_path_tail {->xpath_path_elem} = xsep_one xattrib {-> New xpath_path_elem(New xpath_separator.one(), New xpath_elem.attrib(xattrib), Null) } ; xpath_path_elem {->xpath_path_elem} = xpath_separator xpath_elem {-> New xpath_path_elem(xpath_separator, xpath_elem.elem, xpath_elem.condition) } ; xpath_elem {-> [elem]:xpath_elem [condition]:xpath_expr } = {name} xname {-> New xpath_elem.name(xname) New xpath_expr.empty() } | {conditional} xname xl_brace xpath_expr xr_brace {-> New xpath_elem.name(xname) xpath_expr } | {parent} xparent {-> New xpath_elem.parent() New xpath_expr.empty() } | {parent_conditional} xparent xl_brace xpath_expr xr_brace {-> New xpath_elem.parent() xpath_expr } | {current} xcurrent {-> New xpath_elem.current() New xpath_expr.empty() } | {current_conditional} xcurrent xl_brace xpath_expr xr_brace {-> New xpath_elem.current() xpath_expr } ; xpath_separator {-> xpath_separator} = {one} xsep_one {-> New xpath_separator.one() } | {any} xsep_any {-> New xpath_separator.any() } ; xpath_function {-> xpath_expr} = xname xl_par xpath_expr_list? xr_par {-> New xpath_expr.function(xname, [xpath_expr_list.xpath_expr]) } ; xpath_expr_list {-> xpath_expr*} = {one} xpath_expr {-> [xpath_expr.xpath_expr] } | {sequence} xpath_expr_list xcomma xpath_expr {-> [xpath_expr_list.xpath_expr, xpath_expr.xpath_expr] } ; Abstract Syntax Tree script = statement*; statement = {empty} | {data} data | {foreach} [var]:identifier? [xpath]:xpath_expr statement* | {include} [path]:literal | {if} [test]:expr statement* [else]:statement* | {choose} choose_when* [otherwise]:statement* | {set} [args]:arg+ | {param} [args]:oarg+ | {output} [expr]:expr statement* | {template} [name]:identifier [args]:oarg* statement* | {call} [name]:identifier [args]:arg* | {print} expr | {separator} expr ; choose_when = [test]:expr statement* ; oarg = [var]:identifier [expr]:expr? ; arg = [var]:identifier [expr]:expr ; expr = {literal} literal | {xpath} xpath_expr | {iattrib} iattrib | {ivar} ivar | {concat} [e1]:expr [e2]:expr ; xpath_expr = {empty} | {path} xpath_path_elem+ | {literal} xliteral | {number} xnumber | {function} [name]:xname [args]:xpath_expr* | {equals} [e1]:xpath_expr [e2]:xpath_expr | {not_equals} [e1]:xpath_expr [e2]:xpath_expr | {add} [e1]:xpath_expr [e2]:xpath_expr | {sub} [e1]:xpath_expr [e2]:xpath_expr ; xpath_path_elem = [separator]:xpath_separator? [elem]:xpath_elem [condition]:xpath_expr? ; xpath_elem = {name} xname | {var} xvar | {attrib} xattrib | {parent} | {current} ; xpath_separator = {one} | {any} ;