From 9d9ce3504e320edd9d540e859432b0bf5e454727 Mon Sep 17 00:00:00 2001 From: Fabien Fleutot Date: Thu, 29 Jan 2009 21:46:32 +0100 Subject: [PATCH] more permissive multisequence:add() definition in gg --- src/compiler/gg.lua | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/compiler/gg.lua b/src/compiler/gg.lua index 486752d..d237d28 100644 --- a/src/compiler/gg.lua +++ b/src/compiler/gg.lua @@ -260,15 +260,16 @@ function multisequence (p) -- compile if necessary: if not is_parser(s) then sequence(s) end if is_parser(s) ~= 'sequence' or type(s[1]) ~= "string" then - if self.default then - error "Invalid sequence for multiseq, there is already a default" - else - self.default = s - end - elseif self.sequences[s[1]] then + if self.default then -- two defaults + error ("In a multisequence parser, all but one sequences ".. + "must start with a keyword") + else self.default = s end -- first default + elseif self.sequences[s[1]] then -- duplicate keyword eprintf (" *** Warning: keyword %q overloaded in multisequence ***", s[1]) + self.sequences[s[1]] = s + else -- newly caught keyword + self.sequences[s[1]] = s end - self.sequences[s[1]] = s end -- ------------------------------------------------------------------- @@ -671,6 +672,8 @@ function onkeyword (p) if type(x)=="string" then table.insert (p.keywords, x) else assert (not p.primary and is_parser (x)); p.primary = x end end + if not next (p.keywords) then + eprintf("Warning, no keyword to trigger gg.onkeyword") end assert (p.primary, 'no primary parser in gg.onkeyword') return p end -- -- 2.44.0