Sha256: 2ba923c912fc1960783bb59e2d2d85cf19147b9b61d9add8932cb8e861910941
Contents?: true
Size: 998 Bytes
Versions: 4
Compression:
Stored size: 998 Bytes
Contents
Treetop.load(File.join(File.dirname(__FILE__), "assignments.treetop")) module AssignmentsLanguage module Grammar include TireSwing::NodeDefinition node :assignments, :assignments node :assignment, :lhs, :rhs node :blank_line node :variable, :value end include TireSwing::VisitorDefinition visitor :string_visitor do visits Grammar::Assignments do |assignments| assignments.assignments.map { |child| visit(child) }.compact.join("") end visits Grammar::Assignment do |assignment| visit(assignment.lhs) + " = " + visit(assignment.rhs) + "\n" end visits Grammar::BlankLine do nil end visits Grammar::Variable do |variable| variable.value end end # This uses an external eval method to build the TireSwing AST manually. Don't do this, but it's here for # an example. class Parser < ::Treetop::Runtime::CompiledParser include Grammar def self.parse(io) new.parse(io).eval end end end
Version data entries
4 entries across 4 versions & 1 rubygems