Skip to content

Commit

Permalink
Bracket expressions can contain character classes
Browse files Browse the repository at this point in the history
  • Loading branch information
pixeltrix committed Mar 23, 2011
1 parent 57336be commit 200b856
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/regin/tokenizer.rb
@@ -1,6 +1,6 @@
#--
# DO NOT MODIFY!!!!
# This file is automatically generated by rex 1.0.5.beta1
# This file is automatically generated by rex 1.0.5
# from lexical definition file "lib/regin/tokenizer.rex".
#++

Expand Down Expand Up @@ -162,6 +162,9 @@ def _next_token
when (text = @ss.scan(/\\-/))
action { [:CHAR, text] }

when (text = @ss.scan(/\\[dDsSwW]/))
action { [:CHAR, text] }

when (text = @ss.scan(/\\(.)/))
action { [:CHAR, @ss[1]] }

Expand Down
1 change: 1 addition & 0 deletions lib/regin/tokenizer.rex
Expand Up @@ -58,6 +58,7 @@ rule
end
}
:CCLASS \\- { [:CHAR, text] }
:CCLASS \\[dDsSwW] { [:CHAR, text] }
:CCLASS \\(.) { [:CHAR, @ss[1]] }
:CCLASS . { [:CHAR, text] }

Expand Down
9 changes: 9 additions & 0 deletions spec/parser_spec.rb
Expand Up @@ -157,6 +157,15 @@
%r{[A-Za-z0-9\-\_\.]}.should parse(expr(range('A-Za-z0-9\-_.')))
end

it "should parse bracket expression with character ranges" do
%r{[\d]+}.should parse(expr(range("\\d", :quantifier => '+')))
%r{[\D]+}.should parse(expr(range("\\D", :quantifier => '+')))
%r{[\s]+}.should parse(expr(range("\\s", :quantifier => '+')))
%r{[\S]+}.should parse(expr(range("\\S", :quantifier => '+')))
%r{[\w]+}.should parse(expr(range("\\w", :quantifier => '+')))
%r{[\W]+}.should parse(expr(range("\\W", :quantifier => '+')))
end

it "should parse alternation" do
%r{foo|bar}.should parse(
expr(alt(
Expand Down

0 comments on commit 200b856

Please sign in to comment.