From 76ca0a2bdedb29a74fe4890fac6acac992697332 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Wed, 26 Sep 2018 23:41:49 +0300 Subject: share lex blocks between functions and references --- src/compiler/expr.lm | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) (limited to 'src/compiler') diff --git a/src/compiler/expr.lm b/src/compiler/expr.lm index 858adf4..5b29577 100644 --- a/src/compiler/expr.lm +++ b/src/compiler/expr.lm @@ -72,40 +72,34 @@ context expr end context reference - context function - lex - # reserved - literal `struct `enum `select - literal `nul `dec `hex `str `be `le - token PRIMITIVE / [us][1-9][0-9]* / - literal `( `) `, - token NAME / [a-zA-Z_][a-zA-Z_0-9]* / - end + lex + # reserved + literal `struct `enum `select + literal `nul `dec `hex `str `be `le + literal `until `sizeof + token PRIMITIVE / [us][1-9][0-9]* / + literal `( `) `, + token NAME / [a-zA-Z_][a-zA-Z_0-9]* / + end + context function def arg [expr::arg::type `, arg] | [expr::arg::type] + def name + [`until] | [`sizeof] | [NAME] + def type - [name:NAME WS* `( args:arg* `)] + [name:name WS* `( args:arg* `)] end context variable - lex - # reserved - literal `struct `enum `select - literal `until `sizeof - literal `nul `dec `hex `str `be `le - token PRIMITIVE / [us][1-9][0-9]* / - token NAME / [a-zA-Z_][a-zA-Z_0-9]* / - end - def type [name:NAME] end def type - [function::type] - | [variable::type] + [function::type] | [variable::type] end context collapser @@ -393,13 +387,13 @@ context collapser | [lparen tok+ rparen] commit | [lsquare tok+ rsquare] commit | [tok+ question tok+ colon tok+] commit - | [otherops] { stack_op(r1.op) } + | [otherops] commit { stack_op(r1.op) } | [value] { stack_value($r1) } | [WS] { lhs = nil } def collapsed result:reducer::collapsed - [tok*] commit { flush_all() lhs.result = parse reducer::collapsed[values] if (!lhs.result) reject } + [tok+] commit { flush_all() lhs.result = parse reducer::collapsed[values] if (!lhs.result) reject } collapsed collapse(s:stream) -- cgit v1.2.3