Add "drop" grammar keyword to drop patterns

This commit is contained in:
Josh Holtrop 2021-06-09 22:48:30 -04:00
parent f67dd62b20
commit db70f8b94d
2 changed files with 16 additions and 0 deletions

View File

@ -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

View File

@ -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(<<EOF, "foo \tbar")).to eq expected
token foo
token bar
drop \\s+
EOF
end
end