Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

27 lines (20 sloc) 0.753 kb
require 'rubygems'
require 'parslet'
require 'pp'
class Parser < Parslet::Parser
rule(:lparen) { space? >> str('(') >> space? }
rule(:rparen) { space? >> str(')') }
rule(:space) { match('\s').repeat(1) }
rule(:space?) { space.maybe }
rule(:identifier) { match('[^\s\(\)]').repeat(1).as(:identifier) }
rule(:number) { match('[0-9]').repeat(1).as(:number) }
rule(:atom) { number | identifier | list }
rule(:expression) { atom >> (space >> atom).repeat }
rule(:list) { lparen >> expression.as(:list) >> rparen }
rule(:program) { list.repeat }
root :program
end
parser = Parser.new
source_file = File.open(ARGV[0])
pp parser.parse(source_file.read())
source_file.close()
Jump to Line
Something went wrong with that request. Please try again.