small poslish
This commit is contained in:
parent
9e75a50315
commit
90e2658bc0
@ -4,7 +4,7 @@ require_relative "keywords"
|
|||||||
|
|
||||||
module Parser
|
module Parser
|
||||||
|
|
||||||
#obviously a work in progress !!
|
# obviously a work in progress !!
|
||||||
# We "compose" the parser from bits, divide and hopefully conquer
|
# We "compose" the parser from bits, divide and hopefully conquer
|
||||||
|
|
||||||
class Composed < Parslet::Parser
|
class Composed < Parslet::Parser
|
||||||
@ -12,14 +12,14 @@ module Parser
|
|||||||
include Tokens
|
include Tokens
|
||||||
include Keywords
|
include Keywords
|
||||||
|
|
||||||
# Note about the lists (argument and parameter)
|
# a note about .maybe : .maybe is almost every respect the same as .repeat(0,1)
|
||||||
# Beause of the maybe for the comma ... part , the rules may return either
|
# so either 0, or 1, in other words maybe. Nice feature, but there are strings attached:
|
||||||
# - a single simple version with one element
|
# a maybe removes the 0 a sequence (array) to a single (hash). Thus 2 transformations are needed
|
||||||
# a sequence with many element.
|
# More work than the prettiness is worth, so only use .maybe on something that does not need capturing
|
||||||
# This leads to the fact that two transform rules are needed for either
|
|
||||||
rule(:argument_list) {
|
rule(:argument_list) {
|
||||||
left_parenthesis >>
|
left_parenthesis >>
|
||||||
((expression.as(:argument) >> (comma >> expression.as(:argument)).repeat(0)).maybe).as(:argument_list) >>
|
((expression.as(:argument) >> (comma >> expression.as(:argument)).repeat(0)).repeat(0,1)).as(:argument_list) >>
|
||||||
right_parenthesis
|
right_parenthesis
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ module Parser
|
|||||||
|
|
||||||
rule(:parmeter_list) {
|
rule(:parmeter_list) {
|
||||||
left_parenthesis >>
|
left_parenthesis >>
|
||||||
((name.as(:parmeter) >> (comma >> name.as(:parmeter)).repeat(0)).maybe).as(:parmeter_list) >>
|
((name.as(:parmeter) >> (comma >> name.as(:parmeter)).repeat(0)).repeat(0,1)).as(:parmeter_list) >>
|
||||||
right_parenthesis
|
right_parenthesis
|
||||||
}
|
}
|
||||||
rule(:root){ function_definition | expression | assignment }
|
rule(:root){ function_definition | expression | assignment }
|
||||||
|
@ -5,6 +5,7 @@ module Parser
|
|||||||
raise "abstract"
|
raise "abstract"
|
||||||
end
|
end
|
||||||
def compare other , attributes
|
def compare other , attributes
|
||||||
|
return false unless other.class == self.class
|
||||||
attributes.each do |a|
|
attributes.each do |a|
|
||||||
left = send(a)
|
left = send(a)
|
||||||
right = other.send( a)
|
right = other.send( a)
|
||||||
|
Loading…
Reference in New Issue
Block a user