Class: Lispcalc::Parser
- Inherits:
-
Object
- Object
- Lispcalc::Parser
- Defined in:
- lib/lispcalc/parser.rb
Instance Method Summary collapse
-
#initialize(tokens) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
Constructor Details
#initialize(tokens) ⇒ Parser
Returns a new instance of Parser.
3 4 5 6 7 8 |
# File 'lib/lispcalc/parser.rb', line 3 def initialize(tokens) raise ArgumentError, 'expecting an Array' unless tokens.instance_of?(Array) raise ArgumentError, 'invalid token' unless tokens.all? { |t| valid_token?(t) } @tokens = tokens end |
Instance Method Details
#parse ⇒ Object
10 11 12 13 14 15 |
# File 'lib/lispcalc/parser.rb', line 10 def parse output = parse_list raise SyntaxError, 'expecting a single top-level list' unless @tokens.empty? output end |