From 84f764672525cd475114b76b104fc1bc0e6ce5b2 Mon Sep 17 00:00:00 2001 From: Adrian Thurston Date: Sat, 1 Oct 2016 09:34:21 -0700 Subject: auto-trim in print, send and construct, disable with @ Now automatically trimming when building trees and printing. This is consistent with the $ operator. Rationale is to standardize on the most commonly desired behaviour and provide options for the less-needed. Also much less likely to result in surprising output. There are many cases where test inputs won't have any surrounding ignores, making it easy to forget a trim is required. Then the occasional tree with surrounding ignores will give an undesired result. Better to standardize on trim, making the default behaviour more consistent. The trim can be turned off with the @ operator in front of an expression. --- src/colm.lm | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/colm.lm') diff --git a/src/colm.lm b/src/colm.lm index b87bad4f..cc0a6260 100644 --- a/src/colm.lm +++ b/src/colm.lm @@ -114,6 +114,7 @@ lex token BANG /'!'/ token DOLLAR /'$'/ token CARET /'^'/ + token AT /'@'/ token PERCENT /'%'/ token PLUS /'+'/ token MINUS /'-'/ @@ -722,6 +723,10 @@ def pattern # Constructor List # +def opt_no_trim + [AT] :At +| [] :Trim + def E1 [] def E2 [] def E3 [] @@ -732,7 +737,7 @@ def cons_el | [E1 DQ LitConsElList: lit_cons_el* dq_lit_term] :Dq | [E1 SQ SqConsDataList: sq_cons_data* sq_lit_term] :Sq | [E1 TILDE opt_tilde_data TILDE_NL] :Tilde -| [E2 code_expr] :CodeExpr +| [E2 opt_no_trim code_expr] :CodeExpr def lit_cons_el [dq_cons_data] :ConsData @@ -759,7 +764,7 @@ def accum_el [E1 DQ LitAccumElList: lit_accum_el* dq_lit_term] :Dq | [E1 SQ SqConsDataList: sq_cons_data* sq_lit_term] :Sq | [E1 TILDE opt_tilde_data TILDE_NL] :Tilde -| [E2 code_expr] :CodeExpr +| [E2 opt_no_trim code_expr] :CodeExpr def lit_accum_el [dq_cons_data] :ConsData @@ -786,7 +791,7 @@ def string_el [E1 DQ LitStringElList: lit_string_el* dq_lit_term] :Dq | [E1 SQ SqConsDataList: sq_cons_data* sq_lit_term] :Sq | [E1 TILDE opt_tilde_data TILDE_NL] :Tilde -| [E2 code_expr] :CodeExpr +| [E2 opt_no_trim code_expr] :CodeExpr def lit_string_el [dq_cons_data] :ConsData -- cgit v1.2.1