5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/keisan/ast/builder.rb', line 5
def initialize(string: nil, parser: nil, components: nil)
if [string, parser, components].select(&:nil?).size != 2
raise Keisan::Exceptions::InternalError.new("Require one of string, parser or components")
end
if !string.nil?
@components = Keisan::Parser.new(string: string).components
elsif !parser.nil?
@components = parser.components
else
@components = Array.wrap(components)
end
@nodes = nodes_split_by_operators(@components)
@operators = @components.select {|component| component.is_a?(Keisan::Parsing::Operator)}
consume_operators!
unless @nodes.count == 1
raise Keisan::Exceptions::ASTError.new("Should end up with a single node")
end
end
|