diff --git a/lib/imbecile/grammar.rb b/lib/imbecile/grammar.rb index 80b3dfe..b268f7c 100644 --- a/lib/imbecile/grammar.rb +++ b/lib/imbecile/grammar.rb @@ -40,6 +40,9 @@ module Imbecile end @tokens << Token.new(name, pattern, @tokens.size) token_names << name + elsif line =~ /^\s*drop\s+(\S+)$/ + pattern = $1 + @tokens << Token.new(nil, pattern, @tokens.size) else raise Error.new("Unexpected input on line #{line_number}: #{line}") end diff --git a/spec/imbecile_spec.rb b/spec/imbecile_spec.rb index d175035..4ef47d4 100644 --- a/spec/imbecile_spec.rb +++ b/spec/imbecile_spec.rb @@ -103,6 +103,19 @@ EOF token foo token bar token WS \\s+ +EOF + end + + it "allows dropping a matched pattern" do + expected = [ + ["foo", "foo"], + [nil, " \t"], + ["bar", "bar"], + ] + expect(run(<