Method: Keisan::Parser#initialize
- Defined in:
- lib/keisan/parser.rb
#initialize(string: nil, tokens: nil) ⇒ Parser
Returns a new instance of Parser.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/keisan/parser.rb', line 5 def initialize(string: nil, tokens: nil) if string.nil? && tokens.nil? raise Keisan::Exceptions::InternalError.new("Invalid arguments") end if !string.nil? @tokens = Tokenizer.new(string).tokens else raise Keisan::Exceptions::InternalError.new("Invalid argument: tokens = #{tokens}") if tokens.nil? || !tokens.is_a?(Array) @tokens = tokens end @components = [] parse_components! end |