Skip to content

Commit

Permalink
Started adding support for parsing 'class' and method calls (prelimin…
Browse files Browse the repository at this point in the history
…ary only)
  • Loading branch information
vidarh committed Feb 24, 2009
1 parent 068cb64 commit b5d5d72
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
10 changes: 10 additions & 0 deletions examples/class.rb
@@ -0,0 +1,10 @@

class Foo

def bar
puts("test")
end
end

f = Foo.new
f.bar
2 changes: 2 additions & 0 deletions operators.rb
Expand Up @@ -18,6 +18,8 @@

"*" => Oper.new(20, :mul, :infix),
"/" => Oper.new(20, :div, :infix),

"." => Oper.new(90, :callm, :infix),

"[" => Oper.new(99, :index, :infix),
"]" => Oper.new(99, nil, :rp),
Expand Down
17 changes: 14 additions & 3 deletions parser.rb
Expand Up @@ -84,16 +84,27 @@ def parse_def
exps = zero_or_more(:defexp)
vars = deep_collect(exps,Array) {|node| node[0] == :assign ? node[1] : nil}
exps = [:let,vars] + exps
raise "Expected expression of 'end'" if !@s.expect("end")
raise "Expected expression or 'end'" if !@s.expect("end")
return [:defun, name, args, exps]
end

def parse_sexp; @sexp.parse; end

# exp ::= ws* (def | sexp)
# class ::= "class" ws* name ws* exp* "end"
def parse_class
return nil if !@s.expect("class")
@s.ws
raise "Expected class name" if !(name = @s.expect(Atom))
@s.ws
exps = zero_or_more(:exp)
raise "Expected expression or 'end'" if !@s.expect("end")
return [:class,name,exps]
end

# exp ::= ws* (class | def | sexp)
def parse_exp
@s.ws
parse_def || parse_sexp || @shunting.parse
parse_class || parse_def || parse_sexp || @shunting.parse
end

# program ::= exp* ws*
Expand Down

0 comments on commit b5d5d72

Please sign in to comment.