Added quantity recognition from strings and vcalls
This commit is contained in:
parent
e0c08c0e6a
commit
6ce02ba05a
@ -28,16 +28,28 @@ class DemoBuilder < Ripper::SexpBuilder
|
|||||||
(PARSER_EVENTS - events).each do |event|
|
(PARSER_EVENTS - events).each do |event|
|
||||||
module_eval(<<-End, __FILE__, __LINE__ + 1)
|
module_eval(<<-End, __FILE__, __LINE__ + 1)
|
||||||
def on_#{event}(*args)
|
def on_#{event}(*args)
|
||||||
@disallowed[:token] << [args[1], event]
|
@disallowed[:token] << [args, '#{event}']
|
||||||
|
[:bt_unimplemented, args]
|
||||||
end
|
end
|
||||||
End
|
End
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_program(stmts)
|
def on_program(stmts)
|
||||||
puts @identifiers.inspect
|
|
||||||
@paramed_formula = join_stmts(stmts)
|
@paramed_formula = join_stmts(stmts)
|
||||||
puts @paramed_formula
|
[@identifiers, @paramed_formula, @arguments]
|
||||||
puts @arguments.inspect
|
end
|
||||||
|
|
||||||
|
def on_string_content
|
||||||
|
''
|
||||||
|
end
|
||||||
|
|
||||||
|
def on_string_add(str, new_str)
|
||||||
|
str << new_str
|
||||||
|
end
|
||||||
|
|
||||||
|
def on_string_literal(str)
|
||||||
|
@identifiers << str
|
||||||
|
[:bt_quantity, str]
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_args_new
|
def on_args_new
|
||||||
@ -100,7 +112,8 @@ class DemoBuilder < Ripper::SexpBuilder
|
|||||||
end <<
|
end <<
|
||||||
dot.to_s <<
|
dot.to_s <<
|
||||||
case right[0]
|
case right[0]
|
||||||
when :bt_method
|
when :bt_ident
|
||||||
|
@disallowed[:method] << right[1] unless METHODS.include?(right[1])
|
||||||
right[1]
|
right[1]
|
||||||
else
|
else
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
@ -114,8 +127,13 @@ class DemoBuilder < Ripper::SexpBuilder
|
|||||||
end
|
end
|
||||||
|
|
||||||
def on_vcall(token)
|
def on_vcall(token)
|
||||||
@identifiers << token[1]
|
case token[0]
|
||||||
[:bt_quantity, token[1]]
|
when :bt_ident
|
||||||
|
@identifiers << token[1]
|
||||||
|
[:bt_quantity, token[1]]
|
||||||
|
else
|
||||||
|
raise NotImplementedError
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_method_add_arg(method, paren)
|
def on_method_add_arg(method, paren)
|
||||||
@ -138,11 +156,13 @@ class DemoBuilder < Ripper::SexpBuilder
|
|||||||
var_ref[0] == :bt_quantity ? var_ref : raise(NotImplementedError)
|
var_ref[0] == :bt_quantity ? var_ref : raise(NotImplementedError)
|
||||||
end
|
end
|
||||||
|
|
||||||
silenced_events = [:lparen, :rparen, :op, :period, :sp, :int, :float]
|
silenced_events = [:lparen, :rparen, :op, :period, :sp, :int, :float,
|
||||||
|
:tstring_beg, :tstring_end]
|
||||||
(SCANNER_EVENTS - silenced_events).each do |event|
|
(SCANNER_EVENTS - silenced_events).each do |event|
|
||||||
module_eval(<<-End, __FILE__, __LINE__ + 1)
|
module_eval(<<-End, __FILE__, __LINE__ + 1)
|
||||||
def on_#{event}(token)
|
def on_#{event}(token)
|
||||||
@disallowed[:token] << [token, event]
|
@disallowed[:token] << [token, '#{event}']
|
||||||
|
[:bt_unimplemented, token]
|
||||||
end
|
end
|
||||||
End
|
End
|
||||||
end
|
end
|
||||||
@ -153,14 +173,17 @@ class DemoBuilder < Ripper::SexpBuilder
|
|||||||
end
|
end
|
||||||
|
|
||||||
def on_ident(token)
|
def on_ident(token)
|
||||||
@disallowed[:method] << token unless METHODS.include?(token)
|
[:bt_ident, token]
|
||||||
[:bt_method, token]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_kw(token)
|
def on_kw(token)
|
||||||
@disallowed[:keyword] << token unless token == 'nil'
|
@disallowed[:keyword] << token unless token == 'nil'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def on_tstring_content(token)
|
||||||
|
token
|
||||||
|
end
|
||||||
|
|
||||||
def join_stmts(stmts)
|
def join_stmts(stmts)
|
||||||
stmts.map do |stmt|
|
stmts.map do |stmt|
|
||||||
ttype, token = stmt
|
ttype, token = stmt
|
||||||
@ -175,8 +198,12 @@ class DemoBuilder < Ripper::SexpBuilder
|
|||||||
end
|
end
|
||||||
|
|
||||||
#src = "1 + 1"
|
#src = "1 + 1"
|
||||||
src = "(Weight/Height.all(3*Dupa).lastBefore(TakenAt)^2) + 2*Other*Other"
|
src = "(Weight/Height.all(3*Dupa).lastBefore(TakenAt)^2) + 2*Other*'Other'*other"
|
||||||
#src = "a = 2; b = a"
|
#src = "a = 2; b = a"
|
||||||
pp DemoBuilder.new(src).parse
|
#
|
||||||
puts "(params['Weight'][_index]/params['Height'].all(args['0']).lastBefore(params['TakenAt'])^2)+2*params['Other'][_index]*params['Other'][_index]"
|
|
||||||
pp Ripper.sexp_raw(src)
|
pp Ripper.sexp_raw(src)
|
||||||
|
|
||||||
|
parser = DemoBuilder.new(src)
|
||||||
|
pp parser.parse
|
||||||
|
pp parser.errors
|
||||||
|
puts "(params['Weight'][_index]/params['Height'].all(args['0']).lastBefore(params['TakenAt'])^2)+2*params['Other'][_index]*params['Other'][_index]*params['other'][_index]"
|
||||||
|
Reference in New Issue
Block a user