Add \s to expand to whitespace characters
This commit is contained in:
parent
c6bac6d3a1
commit
f67dd62b20
@ -136,6 +136,15 @@ module Imbecile
|
|||||||
case c
|
case c
|
||||||
when "d"
|
when "d"
|
||||||
CharacterRangeUnit.new("0", "9")
|
CharacterRangeUnit.new("0", "9")
|
||||||
|
when "s"
|
||||||
|
ccu = CharacterClassUnit.new
|
||||||
|
ccu << CharacterRangeUnit.new(" ")
|
||||||
|
ccu << CharacterRangeUnit.new("\t")
|
||||||
|
ccu << CharacterRangeUnit.new("\r")
|
||||||
|
ccu << CharacterRangeUnit.new("\n")
|
||||||
|
ccu << CharacterRangeUnit.new("\f")
|
||||||
|
ccu << CharacterRangeUnit.new("\v")
|
||||||
|
ccu
|
||||||
else
|
else
|
||||||
CharacterRangeUnit.new(c)
|
CharacterRangeUnit.new(c)
|
||||||
end
|
end
|
||||||
|
@ -98,6 +98,15 @@ module Imbecile
|
|||||||
def method_missing(*args)
|
def method_missing(*args)
|
||||||
@units.__send__(*args)
|
@units.__send__(*args)
|
||||||
end
|
end
|
||||||
|
def <<(thing)
|
||||||
|
if thing.is_a?(CharacterClassUnit)
|
||||||
|
thing.each do |ccu_unit|
|
||||||
|
@units << ccu_unit
|
||||||
|
end
|
||||||
|
else
|
||||||
|
@units << thing
|
||||||
|
end
|
||||||
|
end
|
||||||
def last_unit
|
def last_unit
|
||||||
@units[-1]
|
@units[-1]
|
||||||
end
|
end
|
||||||
|
@ -90,6 +90,19 @@ EOF
|
|||||||
expect(run(<<EOF, "+++")).to eq expected
|
expect(run(<<EOF, "+++")).to eq expected
|
||||||
token plus \\+
|
token plus \\+
|
||||||
token plusplus \\+\\+
|
token plusplus \\+\\+
|
||||||
|
EOF
|
||||||
|
end
|
||||||
|
|
||||||
|
it "lexes whitespace" do
|
||||||
|
expected = [
|
||||||
|
["foo", "foo"],
|
||||||
|
["WS", " \t"],
|
||||||
|
["bar", "bar"],
|
||||||
|
]
|
||||||
|
expect(run(<<EOF, "foo \tbar")).to eq expected
|
||||||
|
token foo
|
||||||
|
token bar
|
||||||
|
token WS \\s+
|
||||||
EOF
|
EOF
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user