From 30f1eae86cc28da025e6445e042a8e587c27145b Mon Sep 17 00:00:00 2001 From: Adam Wardynski <award@.(B-4.4.46a)> Date: Fri, 22 Apr 2011 11:56:44 +0200 Subject: [PATCH] Changing submatching syntax from "->" to ":" and M, MA to be shorthand for ($m:_M):1 and ($m:_M):2, respectively. Also, "M" is optional if followed by ":", "M:1" is same as ":1" --- libwccl/parser/grammar.g | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/libwccl/parser/grammar.g b/libwccl/parser/grammar.g index f0f634b..5ce65c4 100644 --- a/libwccl/parser/grammar.g +++ b/libwccl/parser/grammar.g @@ -2299,11 +2299,18 @@ match_fit } : ( ret = match_var_val [tagset, vars] - | "M" { ret.reset(new VarGetter<Match>(vars.create_accessor<Match>("_M"))); } + | {LA(1)==LITERAL_M || LA(1)==COLON}? ("M")? { + ret.reset(new VarGetter<Match>(vars.create_accessor<Match>("_M"))); + ret.reset(new Submatch(ret, 1)); + } + | "MA" { + ret.reset(new VarGetter<Match>(vars.create_accessor<Match>("_M"))); + ret.reset(new Submatch(ret, 2)); + } | LPAREN ret = match_fit [tagset, vars] RPAREN ) ( // if there's an arrow after the match, we have a submatch reference - ARROW i: UNSIGNED_INT { ret.reset(new Submatch(ret, token_ref_to_int(i))); } + COLON i: UNSIGNED_INT { ret.reset(new Submatch(ret, token_ref_to_int(i))); } )* ; @@ -2478,6 +2485,13 @@ options { : "->" ; +COLON +options { + paraphrase = ":"; +} + : ':' +; + SYMBOL options { paraphrase = "Symbol"; -- GitLab