Skip to content

Commit

Permalink
Allow SyntaxNode to be constructed with elements as an optional argum…
Browse files Browse the repository at this point in the history
…ent, and remove it from terminal nodes.
  • Loading branch information
jcoglan committed May 17, 2015
1 parent 51cab57 commit 90db2d4
Show file tree
Hide file tree
Showing 19 changed files with 380 additions and 377 deletions.
70 changes: 35 additions & 35 deletions examples/canopy/json.js

Large diffs are not rendered by default.

72 changes: 36 additions & 36 deletions examples/canopy/json.py

Large diffs are not rendered by default.

74 changes: 37 additions & 37 deletions examples/canopy/json.rb
Expand Up @@ -3,10 +3,10 @@ class SyntaxNode
include Enumerable
attr_reader :text, :offset, :elements

def initialize(text, offset, elements)
def initialize(text, offset, elements = [])
@text = text
@offset = offset
@elements = elements || []
@elements = elements
end

def each(&block)
Expand Down Expand Up @@ -166,7 +166,7 @@ def _read_object
chunk0 = @input[@offset...@offset + 1]
end
if chunk0 == "{"
address1 = SyntaxNode.new(@input[@offset...@offset + 1], @offset, [])
address1 = SyntaxNode.new(@input[@offset...@offset + 1], @offset)
@offset = @offset + 1
else
address1 = FAILURE
Expand Down Expand Up @@ -194,7 +194,7 @@ def _read_object
chunk1 = @input[@offset...@offset + 1]
end
if chunk1 == ","
address5 = SyntaxNode.new(@input[@offset...@offset + 1], @offset, [])
address5 = SyntaxNode.new(@input[@offset...@offset + 1], @offset)
@offset = @offset + 1
else
address5 = FAILURE
Expand Down Expand Up @@ -245,7 +245,7 @@ def _read_object
chunk2 = @input[@offset...@offset + 1]
end
if chunk2 == "}"
address7 = SyntaxNode.new(@input[@offset...@offset + 1], @offset, [])
address7 = SyntaxNode.new(@input[@offset...@offset + 1], @offset)
@offset = @offset + 1
else
address7 = FAILURE
Expand Down Expand Up @@ -290,7 +290,7 @@ def _read_object
chunk3 = @input[@offset...@offset + 1]
end
if chunk3 == "{"
address8 = SyntaxNode.new(@input[@offset...@offset + 1], @offset, [])
address8 = SyntaxNode.new(@input[@offset...@offset + 1], @offset)
@offset = @offset + 1
else
address8 = FAILURE
Expand All @@ -314,7 +314,7 @@ def _read_object
chunk4 = @input[@offset...@offset + 1]
end
if chunk4 == "}"
address10 = SyntaxNode.new(@input[@offset...@offset + 1], @offset, [])
address10 = SyntaxNode.new(@input[@offset...@offset + 1], @offset)
@offset = @offset + 1
else
address10 = FAILURE
Expand Down Expand Up @@ -380,7 +380,7 @@ def _read_pair
chunk0 = @input[@offset...@offset + 1]
end
if chunk0 == ":"
address4 = SyntaxNode.new(@input[@offset...@offset + 1], @offset, [])
address4 = SyntaxNode.new(@input[@offset...@offset + 1], @offset)
@offset = @offset + 1
else
address4 = FAILURE
Expand Down Expand Up @@ -443,7 +443,7 @@ def _read_array
chunk0 = @input[@offset...@offset + 1]
end
if chunk0 == "["
address1 = SyntaxNode.new(@input[@offset...@offset + 1], @offset, [])
address1 = SyntaxNode.new(@input[@offset...@offset + 1], @offset)
@offset = @offset + 1
else
address1 = FAILURE
Expand Down Expand Up @@ -471,7 +471,7 @@ def _read_array
chunk1 = @input[@offset...@offset + 1]
end
if chunk1 == ","
address5 = SyntaxNode.new(@input[@offset...@offset + 1], @offset, [])
address5 = SyntaxNode.new(@input[@offset...@offset + 1], @offset)
@offset = @offset + 1
else
address5 = FAILURE
Expand Down Expand Up @@ -522,7 +522,7 @@ def _read_array
chunk2 = @input[@offset...@offset + 1]
end
if chunk2 == "]"
address7 = SyntaxNode.new(@input[@offset...@offset + 1], @offset, [])
address7 = SyntaxNode.new(@input[@offset...@offset + 1], @offset)
@offset = @offset + 1
else
address7 = FAILURE
Expand Down Expand Up @@ -567,7 +567,7 @@ def _read_array
chunk3 = @input[@offset...@offset + 1]
end
if chunk3 == "["
address8 = SyntaxNode.new(@input[@offset...@offset + 1], @offset, [])
address8 = SyntaxNode.new(@input[@offset...@offset + 1], @offset)
@offset = @offset + 1
else
address8 = FAILURE
Expand All @@ -591,7 +591,7 @@ def _read_array
chunk4 = @input[@offset...@offset + 1]
end
if chunk4 == "]"
address10 = SyntaxNode.new(@input[@offset...@offset + 1], @offset, [])
address10 = SyntaxNode.new(@input[@offset...@offset + 1], @offset)
@offset = @offset + 1
else
address10 = FAILURE
Expand Down Expand Up @@ -711,7 +711,7 @@ def _read_string
chunk0 = @input[@offset...@offset + 1]
end
if chunk0 == "\""
address1 = SyntaxNode.new(@input[@offset...@offset + 1], @offset, [])
address1 = SyntaxNode.new(@input[@offset...@offset + 1], @offset)
@offset = @offset + 1
else
address1 = FAILURE
Expand All @@ -736,7 +736,7 @@ def _read_string
chunk1 = @input[@offset...@offset + 1]
end
if chunk1 == "\\"
address4 = SyntaxNode.new(@input[@offset...@offset + 1], @offset, [])
address4 = SyntaxNode.new(@input[@offset...@offset + 1], @offset)
@offset = @offset + 1
else
address4 = FAILURE
Expand Down Expand Up @@ -765,7 +765,7 @@ def _read_string
@expected << "<any char>"
end
else
address5 = SyntaxNode.new(@input[@offset...@offset + 1], @offset, [])
address5 = SyntaxNode.new(@input[@offset...@offset + 1], @offset)
@offset = @offset + 1
end
unless address5 == FAILURE
Expand All @@ -791,7 +791,7 @@ def _read_string
chunk3 = @input[@offset...@offset + 1]
end
if chunk3 =~ /\A[^"]/
address3 = SyntaxNode.new(@input[@offset...@offset + 1], @offset, [])
address3 = SyntaxNode.new(@input[@offset...@offset + 1], @offset)
@offset = @offset + 1
else
address3 = FAILURE
Expand Down Expand Up @@ -826,7 +826,7 @@ def _read_string
chunk4 = @input[@offset...@offset + 1]
end
if chunk4 == "\""
address6 = SyntaxNode.new(@input[@offset...@offset + 1], @offset, [])
address6 = SyntaxNode.new(@input[@offset...@offset + 1], @offset)
@offset = @offset + 1
else
address6 = FAILURE
Expand Down Expand Up @@ -877,7 +877,7 @@ def _read_number
chunk0 = @input[@offset...@offset + 1]
end
if chunk0 == "-"
address1 = SyntaxNode.new(@input[@offset...@offset + 1], @offset, [])
address1 = SyntaxNode.new(@input[@offset...@offset + 1], @offset)
@offset = @offset + 1
else
address1 = FAILURE
Expand All @@ -890,7 +890,7 @@ def _read_number
end
end
if address1 == FAILURE
address1 = SyntaxNode.new(@input[index2...index2], index2, [])
address1 = SyntaxNode.new(@input[index2...index2], index2)
@offset = index2
end
unless address1 == FAILURE
Expand All @@ -902,7 +902,7 @@ def _read_number
chunk1 = @input[@offset...@offset + 1]
end
if chunk1 == "0"
address2 = SyntaxNode.new(@input[@offset...@offset + 1], @offset, [])
address2 = SyntaxNode.new(@input[@offset...@offset + 1], @offset)
@offset = @offset + 1
else
address2 = FAILURE
Expand All @@ -923,7 +923,7 @@ def _read_number
chunk2 = @input[@offset...@offset + 1]
end
if chunk2 =~ /\A[1-9]/
address3 = SyntaxNode.new(@input[@offset...@offset + 1], @offset, [])
address3 = SyntaxNode.new(@input[@offset...@offset + 1], @offset)
@offset = @offset + 1
else
address3 = FAILURE
Expand All @@ -945,7 +945,7 @@ def _read_number
chunk3 = @input[@offset...@offset + 1]
end
if chunk3 =~ /\A[0-9]/
address5 = SyntaxNode.new(@input[@offset...@offset + 1], @offset, [])
address5 = SyntaxNode.new(@input[@offset...@offset + 1], @offset)
@offset = @offset + 1
else
address5 = FAILURE
Expand Down Expand Up @@ -999,7 +999,7 @@ def _read_number
chunk4 = @input[@offset...@offset + 1]
end
if chunk4 == "."
address7 = SyntaxNode.new(@input[@offset...@offset + 1], @offset, [])
address7 = SyntaxNode.new(@input[@offset...@offset + 1], @offset)
@offset = @offset + 1
else
address7 = FAILURE
Expand All @@ -1021,7 +1021,7 @@ def _read_number
chunk5 = @input[@offset...@offset + 1]
end
if chunk5 =~ /\A[0-9]/
address9 = SyntaxNode.new(@input[@offset...@offset + 1], @offset, [])
address9 = SyntaxNode.new(@input[@offset...@offset + 1], @offset)
@offset = @offset + 1
else
address9 = FAILURE
Expand Down Expand Up @@ -1061,7 +1061,7 @@ def _read_number
address6 = FAILURE
end
if address6 == FAILURE
address6 = SyntaxNode.new(@input[index6...index6], index6, [])
address6 = SyntaxNode.new(@input[index6...index6], index6)
@offset = index6
end
unless address6 == FAILURE
Expand All @@ -1076,7 +1076,7 @@ def _read_number
chunk6 = @input[@offset...@offset + 1]
end
if chunk6 == "e"
address11 = SyntaxNode.new(@input[@offset...@offset + 1], @offset, [])
address11 = SyntaxNode.new(@input[@offset...@offset + 1], @offset)
@offset = @offset + 1
else
address11 = FAILURE
Expand All @@ -1095,7 +1095,7 @@ def _read_number
chunk7 = @input[@offset...@offset + 1]
end
if chunk7 == "E"
address11 = SyntaxNode.new(@input[@offset...@offset + 1], @offset, [])
address11 = SyntaxNode.new(@input[@offset...@offset + 1], @offset)
@offset = @offset + 1
else
address11 = FAILURE
Expand All @@ -1120,7 +1120,7 @@ def _read_number
chunk8 = @input[@offset...@offset + 1]
end
if chunk8 == "+"
address12 = SyntaxNode.new(@input[@offset...@offset + 1], @offset, [])
address12 = SyntaxNode.new(@input[@offset...@offset + 1], @offset)
@offset = @offset + 1
else
address12 = FAILURE
Expand All @@ -1139,7 +1139,7 @@ def _read_number
chunk9 = @input[@offset...@offset + 1]
end
if chunk9 == "-"
address12 = SyntaxNode.new(@input[@offset...@offset + 1], @offset, [])
address12 = SyntaxNode.new(@input[@offset...@offset + 1], @offset)
@offset = @offset + 1
else
address12 = FAILURE
Expand All @@ -1158,7 +1158,7 @@ def _read_number
chunk10 = @input[@offset...@offset + 0]
end
if chunk10 == ""
address12 = SyntaxNode.new(@input[@offset...@offset + 0], @offset, [])
address12 = SyntaxNode.new(@input[@offset...@offset + 0], @offset)
@offset = @offset + 0
else
address12 = FAILURE
Expand All @@ -1185,7 +1185,7 @@ def _read_number
chunk11 = @input[@offset...@offset + 1]
end
if chunk11 =~ /\A[0-9]/
address14 = SyntaxNode.new(@input[@offset...@offset + 1], @offset, [])
address14 = SyntaxNode.new(@input[@offset...@offset + 1], @offset)
@offset = @offset + 1
else
address14 = FAILURE
Expand Down Expand Up @@ -1229,7 +1229,7 @@ def _read_number
address10 = FAILURE
end
if address10 == FAILURE
address10 = SyntaxNode.new(@input[index9...index9], index9, [])
address10 = SyntaxNode.new(@input[index9...index9], index9)
@offset = index9
end
unless address10 == FAILURE
Expand Down Expand Up @@ -1273,7 +1273,7 @@ def _read_boolean
chunk0 = @input[@offset...@offset + 4]
end
if chunk0 == "true"
address0 = SyntaxNode.new(@input[@offset...@offset + 4], @offset, [])
address0 = SyntaxNode.new(@input[@offset...@offset + 4], @offset)
@offset = @offset + 4
else
address0 = FAILURE
Expand All @@ -1292,7 +1292,7 @@ def _read_boolean
chunk1 = @input[@offset...@offset + 5]
end
if chunk1 == "false"
address0 = SyntaxNode.new(@input[@offset...@offset + 5], @offset, [])
address0 = SyntaxNode.new(@input[@offset...@offset + 5], @offset)
@offset = @offset + 5
else
address0 = FAILURE
Expand Down Expand Up @@ -1324,7 +1324,7 @@ def _read_null
chunk0 = @input[@offset...@offset + 4]
end
if chunk0 == "null"
address0 = SyntaxNode.new(@input[@offset...@offset + 4], @offset, [])
address0 = SyntaxNode.new(@input[@offset...@offset + 4], @offset)
@offset = @offset + 4
else
address0 = FAILURE
Expand Down Expand Up @@ -1354,7 +1354,7 @@ def _read___
chunk0 = @input[@offset...@offset + 1]
end
if chunk0 =~ /\A[\s]/
address1 = SyntaxNode.new(@input[@offset...@offset + 1], @offset, [])
address1 = SyntaxNode.new(@input[@offset...@offset + 1], @offset)
@offset = @offset + 1
else
address1 = FAILURE
Expand Down

0 comments on commit 90db2d4

Please sign in to comment.