Skip to content

Commit

Permalink
+ builders/default: implicit matches (refs #69).
Browse files Browse the repository at this point in the history
  • Loading branch information
whitequark committed Jun 16, 2013
1 parent 66473ca commit 9e9b2e5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
10 changes: 9 additions & 1 deletion doc/AST_FORMAT.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ AST and Source Location RFC

* Should we handle these cases at all? They do not have special syntax associated.
1. How to handle lvar-injecting match (`if /(?<a>foo)/ =~ bar`)?
1. How to handle magic match (`foo if /bar/`)?

## Literals

Expand Down Expand Up @@ -380,6 +379,15 @@ Format:
~~~~~ expression
~~~

### Implicit matches

Format:

~~~
(match-current-line (regexp (str "a") (regopt)))
"if /a/; end"
~~~

## Assignment

### To local variable
Expand Down
3 changes: 3 additions & 0 deletions lib/parser/builders/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,9 @@ def check_condition(cond)
check_condition(rhs)
])

when :regexp
n(:match_current_line, [ cond ], nil)

else
cond
end
Expand Down
11 changes: 11 additions & 0 deletions test/test_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3612,6 +3612,17 @@ def test_cond_eflipflop
| ~~~ operator (eflipflop)})
end

def test_cond_match_current_line
assert_parses(
s(:if,
s(:match_current_line,
s(:regexp,
s(:str, 'wat'),
s(:regopt))),
s(:nil), nil),
%q{if /wat/; end})
end

# Case matching

def test_case_expr
Expand Down

0 comments on commit 9e9b2e5

Please sign in to comment.