diff options
author | Adrian Thurston <thurston@complang.org> | 2009-03-06 03:32:41 +0000 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2009-03-06 03:32:41 +0000 |
commit | 43710153be28444536f527a05db2df81b9a1a095 (patch) | |
tree | 3b234e400fc1e2cf98e5db5f4aadbd5ea20cc34a /test/rubyhere.lm | |
parent | 99bad941034ba014cdae7eae6ddd3f11121c67ae (diff) | |
parent | a56c3a5d4b9b2139fb203b6adf93b93c88b75f52 (diff) | |
download | colm-43710153be28444536f527a05db2df81b9a1a095.tar.gz |
Redid the branch for the pull scanner, this time at the root of the project and
not the colm subdir.
Diffstat (limited to 'test/rubyhere.lm')
-rw-r--r-- | test/rubyhere.lm | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/test/rubyhere.lm b/test/rubyhere.lm new file mode 100644 index 00000000..33fff4b7 --- /dev/null +++ b/test/rubyhere.lm @@ -0,0 +1,89 @@ +rl ident_pattern /[a-zA-Z_][a-zA-Z_0-9]*/ +rl number_pattern /[0-9]+/ + +lex start +{ + ignore /[ \t\n]+/ + token id /ident_pattern/ + token number /number_pattern/ + literal '<<', '*', ',', '(', ')' +} + +global str HereId + +token rest_of_line /[^\n]*'\n'/ + +lex here_start +{ + ignore /[ \t\n]+/ + token here_id + here_data HereData + /ident_pattern/ + { + # Take the text of the here_id from the input stream. + HereId = pull( stdin, match_length ) + + # Get the data up to the rest of the line. + rest_of_line ROL = parse_stop rest_of_line( stdin ) + + # Parse the heredoc data. + here_data HereData = parse_stop here_data( stdin ) + + # Push the rest-of-line data back to the input stream. + push( stdin, ROL ) + + # Send the here_id token. Attach the heredoc data as an attribute. + send( make_token( typeid here_id, HereId, HereData ) ) + } +} + +lex here_data +{ + token here_close_id + / ident_pattern '\n' / + { + if match_text == HereId + '\n' { + send( make_token( + typeid here_close_id, + pull(stdin, match_length) ) ) + } + else + send( make_token( typeid here_line, pull(stdin, match_length) ) ) + } + + token here_line + / [^\n]* '\n' / +} + +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 start + [statement*] +| [foobar] + +start S = parse start( stdin ) +print_xml(S) |