Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix parser

  • Loading branch information...
commit eed83a6340990899ecb178e546ccec78e523b702 1 parent c850649
@txus authored
View
6 examples/fn.clj
@@ -0,0 +1,6 @@
+; Add two numbers.
+(def adder
+ (fn [x y]
+ (+ x y)))
+
+(adder 123 123)
View
12 lib/lambra/parser.rb
@@ -1,8 +1,8 @@
require 'lambra/parser/parser'
class Lambra::Parser
- def self.parse_to_sexp(string)
- parser = new string
+ def self.parse_to_sexp(string, debug=false)
+ parser = new string, debug
unless parser.parse
parser.raise_error
end
@@ -10,8 +10,8 @@ def self.parse_to_sexp(string)
parser.result.to_sexp
end
- def self.parse(string)
- parser = new string
+ def self.parse(string, debug=false)
+ parser = new string, debug
unless parser.parse
parser.raise_error
end
@@ -19,8 +19,8 @@ def self.parse(string)
parser.result
end
- def self.parse_file(name)
- parser = new IO.read(name)
+ def self.parse_file(name, debug=false)
+ parser = new IO.read(name), debug
unless parser.parse
parser.raise_error
end
View
2  lib/lambra/parser/lambra.kpeg
@@ -86,7 +86,7 @@ expr = list
| literal
many_expr = comment:e many_expr:m { [e] + m }
- | expr:e sp many_expr:m { [e] + m }
+ | expr:e br-sp many_expr:m { [e] + m }
| expr:e { [e] }
sequence = many_expr:e { e.size > 1 ? seq(current_line, current_column, e) : e.first }
View
6 lib/lambra/parser/parser.rb
@@ -1399,7 +1399,7 @@ def _expr
return _tmp
end
- # many_expr = (comment:e many_expr:m { [e] + m } | expr:e sp many_expr:m { [e] + m } | expr:e { [e] })
+ # many_expr = (comment:e many_expr:m { [e] + m } | expr:e br-sp many_expr:m { [e] + m } | expr:e { [e] })
def _many_expr
_save = self.pos
@@ -1438,7 +1438,7 @@ def _many_expr
self.pos = _save2
break
end
- _tmp = apply(:_sp)
+ _tmp = apply(:_br_hyphen_sp)
unless _tmp
self.pos = _save2
break
@@ -1660,7 +1660,7 @@ def _root
Rules[:_set] = rule_info("set", "(\"\#{\" expr_list:e \"}\" {set(current_line, current_column, e)} | \"\#{\" \"}\" {set(current_line, current_column, [])})")
Rules[:_map] = rule_info("map", "(\"{\" expr_list:e \"}\" {map(current_line, current_column, Hash[*e])} | \"{\" \"}\" {map(current_line, current_column, {})})")
Rules[:_expr] = rule_info("expr", "(list | literal)")
- Rules[:_many_expr] = rule_info("many_expr", "(comment:e many_expr:m { [e] + m } | expr:e sp many_expr:m { [e] + m } | expr:e { [e] })")
+ Rules[:_many_expr] = rule_info("many_expr", "(comment:e many_expr:m { [e] + m } | expr:e br-sp many_expr:m { [e] + m } | expr:e { [e] })")
Rules[:_sequence] = rule_info("sequence", "many_expr:e { e.size > 1 ? seq(current_line, current_column, e) : e.first }")
Rules[:_expr_list_b] = rule_info("expr_list_b", "(expr:e br-sp expr_list_b:l { [e] + l } | expr:e { [e] })")
Rules[:_expr_list] = rule_info("expr_list", "br-sp expr_list_b:b br-sp { b }")
View
2  spec/custom/matchers/parse_as.rb
@@ -4,7 +4,7 @@ def initialize(expected)
end
def matches?(actual)
- @actual = Lambra::Parser.parse_to_sexp actual
+ @actual = Lambra::Parser.parse_to_sexp actual, true
@actual == @expected
end
Please sign in to comment.
Something went wrong with that request. Please try again.