add field access with tests

This commit is contained in:
Torsten Ruger
2015-09-20 12:50:06 +03:00
parent 8e07a7568f
commit be444bc687
8 changed files with 84 additions and 50 deletions

View File

@ -12,6 +12,7 @@ module Parser
rule(:call_site) { (basic_type.as(:receiver) >> str(".")).maybe >> #possibly qualified
name.as(:call_site) >> argument_list >> comment.maybe}
rule(:field_access) { name.as(:receiver) >> str(".") >> name.as(:field) }
end
end

View File

@ -2,7 +2,7 @@ module Parser
module Expression
include Parslet
rule(:value_expression) { call_site | basic_type }
rule(:value_expression) { call_site | field_access |basic_type }
rule(:expression) { (simple_return | while_do | small_conditional | conditional | operator_expression | call_site ) }

View File

@ -10,10 +10,10 @@ require_relative "module_definition"
require_relative "operators"
module Parser
# obviously a work in progress !!
# We "compose" the parser from bits, divide and hopefully conquer
# a note about .maybe : .maybe is almost every respect the same as .repeat(0,1)
# so either 0, or 1, in other words maybe. Nice feature, but there are strings attached:
# a maybe removes the 0 a sequence (array) to a single (hash). Thus 2 transformations are needed
@ -31,8 +31,9 @@ module Parser
include Operators
include ModuleDef
rule(:root_body) {(module_definition | class_definition | function_definition | expression |
operator_expression | call_site | basic_type | hash_constant | array_constant )}
rule(:root_body) {(module_definition | class_definition | function_definition |
expression | operator_expression | call_site | field_access |
basic_type | hash_constant | array_constant )}
rule(:root) { root_body.repeat.as(:expression_list) }
end
end

View File

@ -36,6 +36,9 @@ module Parser
:argument_list => sequence(:argument_list)) do
s(:call , call_site, s(:arguments , *argument_list) , s(:receiver , receiver))
end
rule( :receiver => simple(:receiver) , :field => simple(:field) ) do
s(:field_access , s(:receiver , receiver) , s(:field , field) )
end
rule(:if => simple(:if), :conditional => simple(:conditional),
:if_true => {:expressions => sequence(:if_true) , :else => simple(:else) },