Permalink
Browse files

Merge pull request #32 from bogdan/refactor_ast

AST: generalized a way to handle STAR node type
  • Loading branch information...
2 parents 622f535 + d59c75e commit 47aaabf986b154cfce2a13cacfb50fc5ffc8dd14 @tenderlove tenderlove committed May 23, 2012
@@ -29,7 +29,7 @@ def to_sym
end
def name
- left.tr ':', ''
+ left.tr '*:', ''
end
def type
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -20,7 +20,7 @@ rule
: expressions OR expression { result = Or.new([val.first, val.last]) }
;
star
- : STAR literal { result = Star.new(Symbol.new(val.last.left)) }
+ : STAR { result = Star.new(Symbol.new(val.last)) }
;
terminal
: symbol
View
@@ -35,7 +35,7 @@ def scan
# /
when text = @ss.scan(/\//)
[:SLASH, text]
- when text = @ss.scan(/\*/)
+ when text = @ss.scan(/\*\w+/)
[:STAR, text]
when text = @ss.scan(/\(/)
[:LPAREN, text]
View
@@ -68,10 +68,6 @@ def terminal node
node.left
end
- def visit_STAR node
- "*" + super
- end
-
def visit_GROUP node
"(#{visit node.left})"
end
@@ -11,7 +11,7 @@ def setup
def test_tokens
[
['/', [[:SLASH, '/']]],
- ['*omg', [[:STAR, '*'], [:LITERAL, 'omg']]],
+ ['*omg', [[:STAR, '*omg']]],
['/page', [[:SLASH, '/'], [:LITERAL, 'page']]],
['/~page', [[:SLASH, '/'], [:LITERAL, '~page']]],
['/pa-ge', [[:SLASH, '/'], [:LITERAL, 'pa-ge']]],

0 comments on commit 47aaabf

Please sign in to comment.