1 # Copyright 2007-2014 Greg Hurrell. All rights reserved.
2 # Licensed under the terms of the BSD 2-clause license.
7 # Make subclasses of this for use in Abstract Syntax Trees (ASTs).
9 include Walrat::LocationTracking
14 @string_value = lexeme.to_s
22 # Overrides the default initialize method to accept the defined
23 # attributes and sets up an read accessor for each.
25 # Raises an error if called directly on Node itself rather than
27 def self.production *results
28 raise 'Node#production called directly on Node' if self == Node
31 results.each { |result| attr_reader result }
34 initialize_body = "def initialize #{results.map { |symbol| symbol.to_s }.join(', ')}\n"
35 initialize_body << %Q{ @string_value = ""\n}
36 results.each do |result|
37 initialize_body << " @#{result} = #{result}\n"
38 initialize_body << " @string_value << #{result}.to_s\n"
40 initialize_body << "end\n"
41 class_eval initialize_body