Package org.sablecc.sablecc.expander; Helpers all = [0 .. 0xffff]; letter = [['a'..'z']+['A'..'Z']]; digit = ['0'..'9']; letter_or_digit = [letter + digit]; 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']; cr = 13; lf = 10; eol = cr | lf | cr lf; not_eol = [all - [cr + lf]]; marker = '$'; not_eol_marker = [not_eol - marker]; space = ' '; tab = 9; blank = [space + tab]; not_macro_line = eol | [not_eol - m] not_eol* eol? | m [not_eol - a] not_eol* eol? | m a [not_eol - c] not_eol* eol? | m a c [not_eol - r] not_eol* eol? | m a c r [not_eol - o] not_eol* eol?; States normal, macro_header, macro_body, reference; Tokens {normal->macro_header} macro = m a c r o; {macro_header, reference} expand = e x p a n d; {macro_header, reference} colon = ':'; {macro_header} l_par = '('; {macro_header, reference} comma = ','; {macro_header} r_par = ')'; {macro_body->reference, reference->macro_body} marker = marker; {macro_body} double_marker = marker marker; {macro_header->macro_body, macro_body} eol = eol; {macro_header, reference} blanks = blank+; {macro_header, reference} ident = letter letter_or_digit*; {macro_body} text = not_eol_marker+; {macro_body->normal} macro_end = eol marker blank* eol; {normal} comment = not_macro_line+; Ignored Tokens comment, blanks; Productions macro_file = macro_definition+; macro_definition = macro colon ident l_par params? r_par eol macro_body macro_end {-> New macro_definition(ident, [params.ident], macro_body) }; params // {-> ident+ } = {-> ident* } = ident params_tail* {-> [ident, params_tail.ident] }; params_tail {-> ident } = comma ident {-> ident }; macro_body = [body_elements]:body_element*; body_element = {text} text | {eol} eol {-> New body_element.eol () } | {double_marker} double_marker {-> New body_element.double_marker () } | {var} [start_marker]:marker ident [end_marker]:marker {-> New body_element.var (ident) } | {expansion} [start_marker]:marker expand colon macro_names [end_marker]:marker {-> New body_element.expansion ([macro_names.ident]) }; macro_names // {-> ident+ } = {-> ident* } = ident macro_names_tail* {-> [ident, macro_names_tail.ident] }; macro_names_tail {-> ident } = comma ident {-> ident }; Abstract Syntax Tree macro_file = macro_definition+; macro_definition = [name]:ident [params]:ident* macro_body; macro_body = [body_elements]:body_element*; body_element = {text} text | {eol} | {double_marker} | {var} [var]:ident | {expansion} [macro_names]:ident+;