Skip to content
Browse files

AST: generalized a way to handle STAR node type

  • Loading branch information...
1 parent 622f535 commit d59c75ed3b6fac4b8b8af7213bc1bd11b991a328 @bogdan bogdan committed May 23, 2012
View
2 lib/journey/nodes/node.rb
@@ -29,7 +29,7 @@ def to_sym
end
def name
- left.tr ':', ''
+ left.tr '*:', ''
end
def type
View
38 lib/journey/parser.rb
@@ -1,6 +1,6 @@
#
# DO NOT MODIFY!!!!
-# This file is automatically generated by Racc 1.4.6
+# This file is automatically generated by Racc 1.4.8
# from Racc grammer file "".
#
@@ -13,41 +13,41 @@ class Parser < Racc::Parser
##### State transition tables begin ###
racc_action_table = [
- 17, 22, 13, 15, 14, 7, 15, 16, 8, 19,
- 13, 15, 14, 7, 24, 16, 8, 19, 13, 15,
+ 17, 21, 13, 15, 14, 7, nil, 16, 8, 19,
+ 13, 15, 14, 7, 23, 16, 8, 19, 13, 15,
14, 7, nil, 16, 8, 13, 15, 14, 7, nil,
16, 8, 13, 15, 14, 7, nil, 16, 8 ]
racc_action_check = [
- 1, 17, 1, 1, 1, 1, 8, 1, 1, 1,
+ 1, 17, 1, 1, 1, 1, nil, 1, 1, 1,
20, 20, 20, 20, 20, 20, 20, 20, 7, 7,
7, 7, nil, 7, 7, 19, 19, 19, 19, nil,
19, 19, 0, 0, 0, 0, nil, 0, 0 ]
racc_action_pointer = [
- 30, 0, nil, nil, nil, nil, nil, 16, 3, nil,
+ 30, 0, nil, nil, nil, nil, nil, 16, nil, nil,
nil, nil, nil, nil, nil, nil, nil, 1, nil, 23,
- 8, nil, nil, nil, nil ]
+ 8, nil, nil, nil ]
racc_action_default = [
- -18, -18, -2, -3, -4, -5, -6, -18, -18, -10,
+ -18, -18, -2, -3, -4, -5, -6, -18, -9, -10,
-11, -12, -13, -14, -15, -16, -17, -18, -1, -18,
- -18, -9, 25, -8, -7 ]
+ -18, 24, -8, -7 ]
racc_goto_table = [
- 18, 1, 21, nil, nil, nil, nil, nil, 20, nil,
- nil, nil, nil, nil, nil, nil, nil, nil, 23, 18 ]
+ 18, 1, nil, nil, nil, nil, nil, nil, 20, nil,
+ nil, nil, nil, nil, nil, nil, nil, nil, 22, 18 ]
racc_goto_check = [
- 2, 1, 7, nil, nil, nil, nil, nil, 1, nil,
+ 2, 1, nil, nil, nil, nil, nil, nil, 1, nil,
nil, nil, nil, nil, nil, nil, nil, nil, 2, 2 ]
racc_goto_pointer = [
- nil, 1, -1, nil, nil, nil, nil, -6, nil, nil,
+ nil, 1, -1, nil, nil, nil, nil, nil, nil, nil,
nil ]
racc_goto_default = [
- nil, nil, 2, 3, 4, 5, 6, 10, 9, 11,
+ nil, nil, 2, 3, 4, 5, 6, 9, 10, 11,
12 ]
racc_reduce_table = [
@@ -60,19 +60,19 @@ class Parser < Racc::Parser
1, 12, :_reduce_none,
3, 15, :_reduce_7,
3, 13, :_reduce_8,
- 2, 16, :_reduce_9,
+ 1, 16, :_reduce_9,
1, 14, :_reduce_none,
1, 14, :_reduce_none,
1, 14, :_reduce_none,
1, 14, :_reduce_none,
1, 19, :_reduce_14,
- 1, 18, :_reduce_15,
- 1, 17, :_reduce_16,
+ 1, 17, :_reduce_15,
+ 1, 18, :_reduce_16,
1, 20, :_reduce_17 ]
racc_reduce_n = 18
-racc_shift_n = 25
+racc_shift_n = 24
racc_token_table = {
false => 0,
@@ -124,8 +124,8 @@ class Parser < Racc::Parser
"terminal",
"group",
"star",
- "literal",
"symbol",
+ "literal",
"slash",
"dot" ]
@@ -164,7 +164,7 @@ def _reduce_8(val, _values, result)
end
def _reduce_9(val, _values, result)
- result = Star.new(Symbol.new(val.last.left))
+ result = Star.new(Symbol.new(val.last))
result
end
View
2 lib/journey/parser.y
@@ -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
2 lib/journey/scanner.rb
@@ -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
4 lib/journey/visitors.rb
@@ -68,10 +68,6 @@ def terminal node
node.left
end
- def visit_STAR node
- "*" + super
- end
-
def visit_GROUP node
"(#{visit node.left})"
end
View
2 test/route/definition/test_scanner.rb
@@ -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 d59c75e

Please sign in to comment.
Something went wrong with that request. Please try again.