created own directory for parser
This commit is contained in:
33
lib/parser/transform.rb
Normal file
33
lib/parser/transform.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
require 'parslet'
|
||||
require 'vm/nodes'
|
||||
|
||||
module Vm
|
||||
class Transform < Parslet::Transform
|
||||
rule(:number => simple(:value)) { NumberExpression.new(value.to_i) }
|
||||
rule(:name => simple(:name)) { NameExpression.new(name.to_s) }
|
||||
|
||||
rule(:arg => simple(:arg)) { arg }
|
||||
rule(:args => sequence(:args)) { args }
|
||||
|
||||
rule(:funcall => simple(:funcall),
|
||||
:args => simple(:args)) { FuncallExpression.new(funcall.name, [args]) }
|
||||
|
||||
rule(:funcall => simple(:funcall),
|
||||
:args => sequence(:args)) { FuncallExpression.new(funcall.name, args) }
|
||||
|
||||
rule(:cond => simple(:cond),
|
||||
:if_true => {:body => simple(:if_true)},
|
||||
:if_false => {:body => simple(:if_false)}) { ConditionalExpression.new(cond, if_true, if_false) }
|
||||
|
||||
rule(:param => simple(:param)) { param }
|
||||
rule(:params => sequence(:params)) { params }
|
||||
|
||||
rule(:func => simple(:func),
|
||||
:params => simple(:name),
|
||||
:body => simple(:body)) { FunctionExpression.new(func.name, [name], body) }
|
||||
|
||||
rule(:func => simple(:func),
|
||||
:params => sequence(:params),
|
||||
:body => simple(:body)) { FunctionExpression.new(func.name, params, body) }
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user