diff options
Diffstat (limited to 'test/rediv.lm')
-rw-r--r-- | test/rediv.lm | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/test/rediv.lm b/test/rediv.lm new file mode 100644 index 0000000..c5ac955 --- /dev/null +++ b/test/rediv.lm @@ -0,0 +1,99 @@ +##### LM ##### +# Or-literal scanner +lex + token orlit_dash /'-' / + token orlit_close /']'/ + + rl orlit_specials /[\-\]]/ + token orlit_chr /^orlit_specials | '\\' any/ +end + +def orlit_item + [orlit_chr] +| [orlit_chr orlit_dash orlit_chr] + +def orlit + [orlit_item*] + +# Regex scanner +lex + token orlit_open /'['/ + token orlit_neg_open /'[^'/ + token regex_dot /'.'/ + token regex_star /'*'/ + token regex_close /'/'/ + + rl regex_specials /[\[\.\*\/\\]/ + token regex_chr /(^regex_specials)+ | '\\' any/ +end + +def regex_rep + [regex_star] +| [] + +def regex_base + [regex_chr] +| [regex_dot] +| [orlit_open orlit orlit_close] +| [orlit_neg_open orlit orlit_close] + +def regex_item + [regex_base regex_rep] + +def regex_body + [regex_item*] + +rl s_string /"'" ([^'\\\n] | '\\' any )* "'"/ +rl d_string /'"' ([^"\\\n] | '\\' any )* '"'/ + +# Root scanner +lex + token ident /[a-zA-Z_]+/ + token number /[0-9]+/ + token string /s_string | d_string/ + + literal `+ `- `* `; `/ + token slash /'/'/ + token semi /';'/ + + ignore wp /[ \t\n]+/ +end + +def factor + [ident] +| [number] +| [string] +| [`/ regex_body regex_close] + +def term + [term `* factor] +| [term `/ factor] +| [factor] + +def expr + [expr `+ term] +| [expr `- term] +| [term] + +def statement + [expr `;] + +def start + [statement*] + +parse S: start[ stdin ] + +for I:orlit_item in S { + if match I [orlit_chr] { + print( I '\n' ) + } +} +print_xml( S ) +print( '\n' ) +##### IN ##### +2 / /[^gu-zy].*o[\d-xa]*/; +##### EXP ##### +g +y +a +<start><_repeat_statement><statement><expr><term><term><factor><number>2</number></factor></term><_literal_0021>/</_literal_0021><factor><_literal_0021>/</_literal_0021><regex_body><_repeat_regex_item><regex_item><regex_base><orlit_neg_open>[^</orlit_neg_open><orlit><_repeat_orlit_item><orlit_item><orlit_chr>g</orlit_chr></orlit_item><orlit_item><orlit_chr>u</orlit_chr><orlit_dash>-</orlit_dash><orlit_chr>z</orlit_chr></orlit_item><orlit_item><orlit_chr>y</orlit_chr></orlit_item></_repeat_orlit_item></orlit><orlit_close>]</orlit_close></regex_base><regex_rep></regex_rep></regex_item><regex_item><regex_base><regex_dot>.</regex_dot></regex_base><regex_rep><regex_star>*</regex_star></regex_rep></regex_item><regex_item><regex_base><regex_chr>o</regex_chr></regex_base><regex_rep></regex_rep></regex_item><regex_item><regex_base><orlit_open>[</orlit_open><orlit><_repeat_orlit_item><orlit_item><orlit_chr>\d</orlit_chr><orlit_dash>-</orlit_dash><orlit_chr>x</orlit_chr></orlit_item><orlit_item><orlit_chr>a</orlit_chr></orlit_item></_repeat_orlit_item></orlit><orlit_close>]</orlit_close></regex_base><regex_rep><regex_star>*</regex_star></regex_rep></regex_item></_repeat_regex_item></regex_body><regex_close>/</regex_close></factor></term></expr><_literal_001f>;</_literal_001f></statement></_repeat_statement></start> |