diff options
Diffstat (limited to 'test/context2.lm')
-rw-r--r-- | test/context2.lm | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/test/context2.lm b/test/context2.lm new file mode 100644 index 0000000..e04354a --- /dev/null +++ b/test/context2.lm @@ -0,0 +1,124 @@ +##### LM ##### +context ruby_here + + rl ident_pattern /[a-zA-Z_][a-zA-Z_0-9]*/ + rl number_pattern /[0-9]+/ + + lex + ignore /[ \t\n]+/ + token id /ident_pattern/ + token number /number_pattern/ + literal `<< `* `, `( `) `! + end + + HereId: str + + token rest_of_line /[^\n]*'\n'/ + + lex + ignore /[ \t\n]+/ + token here_id + HereData: here_data + /ident_pattern/ + { + # Take the text of the here_id from the input stream. + HereId = input.pull( match_length ) + + # Get the data up to the rest of the line. + parse_stop ROL: rest_of_line(ctx)[ input ] + + # Parse the heredoc data. + parse_stop HereData: here_data(ctx)[ input ] + + # Push the rest-of-line data back to the input stream. + input.push( $ROL ) + + # Send the here_id token. Attach the heredoc data as an attribute. + input.push( make_token( typeid<here_id> HereId HereData ) ) + } + end + + lex + token here_close_id + / ident_pattern '\n' / + { + if match_text == HereId + '\n' { + input.push( make_token( + typeid<here_close_id> + input.pull( match_length ) ) ) + } + else + input.push( make_token( typeid<here_line> input.pull(match_length) ) ) + } + + token here_line + / [^\n]* '\n' / + end + + def here_data + [here_line* here_close_id] + + def heredoc + [`<< here_id] + + def primary + [id] + | [number] + | [heredoc] + + def arglist + [primary arglist_more*] + + def arglist_more + [`, primary] + + def call + [id `( arglist? `)] + + def statement + [primary] + | [call] + + token foobar /any+/ + + def item + [statement `!] + | [foobar] + + def start + [item*] + +end # ruby_here + +CTX: ruby_here = cons ruby_here [] + +parse S: ruby_here::start( CTX ) [ stdin ] +print_xml(S) +print('\n') +##### IN ##### +print( <<DATA1, more, <<DATA2, 99 ) +"&^#(@ almost +!arbitrary text! +DATA1 +hello +world +DATA2 +! +print( <<DATA1, more, <<DATA2, 99 ) +"&^#(@ almost +!arbitrary text! +DATA1 +hello +world +DATA2 +# error here +##### EXP ##### +<ruby_here::start><ruby_here::_repeat_item><ruby_here::item><ruby_here::statement><ruby_here::call><ruby_here::id>print</ruby_here::id><ruby_here::_literal_000d>(</ruby_here::_literal_000d><ruby_here::_opt_arglist><ruby_here::arglist><ruby_here::primary><ruby_here::heredoc><ruby_here::_literal_0007><<</ruby_here::_literal_0007><ruby_here::here_id>DATA1</ruby_here::here_id></ruby_here::heredoc></ruby_here::primary><ruby_here::_repeat_arglist_more><ruby_here::arglist_more><ruby_here::_literal_000b>,</ruby_here::_literal_000b><ruby_here::primary><ruby_here::id>more</ruby_here::id></ruby_here::primary></ruby_here::arglist_more><ruby_here::arglist_more><ruby_here::_literal_000b>,</ruby_here::_literal_000b><ruby_here::primary><ruby_here::heredoc><ruby_here::_literal_0007><<</ruby_here::_literal_0007><ruby_here::here_id>DATA2</ruby_here::here_id></ruby_here::heredoc></ruby_here::primary></ruby_here::arglist_more><ruby_here::arglist_more><ruby_here::_literal_000b>,</ruby_here::_literal_000b><ruby_here::primary><ruby_here::number>99</ruby_here::number></ruby_here::primary></ruby_here::arglist_more></ruby_here::_repeat_arglist_more></ruby_here::arglist></ruby_here::_opt_arglist><ruby_here::_literal_000f>)</ruby_here::_literal_000f></ruby_here::call></ruby_here::statement><ruby_here::_literal_0011>!</ruby_here::_literal_0011></ruby_here::item><ruby_here::item><ruby_here::foobar>print( <<DATA1, more, <<DATA2, 99 ) +"&^#(@ almost +!arbitrary text! +DATA1 +hello +world +DATA2 +# error here +</ruby_here::foobar></ruby_here::item></ruby_here::_repeat_item></ruby_here::start> |