Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: ef25dba16a
Fetching contributors…

Cannot retrieve contributors at this time

56 lines (41 sloc) 0.94 kb
require 'and'
require 'or'
require 'bigger'
require 'file_name'
require 'writable'
class Parser
def initialize(text)
@tokens = text.scan(/\(|\)|[\w\.\*]+/)
end
def next_token
@tokens.shift
end
def expression
token = next_token
if token == nil
return nil
elsif token == '('
result = expression
raise 'Expected )' unless next_token == ')'
result
elsif token == 'all'
return All.new
elsif token == 'writable'
return Writable.new
elsif token == 'bigger'
return Bigger.new(next_token.to_i)
elsif token == 'filename'
return FileName.new(next_token)
elsif token == 'not'
return Not.new(expression)
elsif token == 'and'
return And.new(expression, expression)
elsif token == 'or'
return Or.new(expression, expression)
else
raise "Unexpected token: #{token}"
end
end
end
parser = Parser.new("and (and(bigger 1024)(filename *.mp3)) writable")
ast = parser.expression
Jump to Line
Something went wrong with that request. Please try again.