Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed some argument ambiguity with syntax rules.

  • Loading branch information...
commit cd896a2cbefaf375dbee79721a48ef331dfa0cf5 1 parent 2c995ea
Phil Hagelberg authored
14 lib/bus_scheme/syntax.rb
View
@@ -1,15 +1,14 @@
module BusScheme
# Mwahahah
special_form 'define-syntax', primitive { |keyword, transformer|
- BusScheme::SYMBOL_TABLE[keyword.sym] =
- BusScheme['syntax-rules'.sym].call([transformer])
- }
+ BusScheme::SYMBOL_TABLE[keyword.sym] = eval(transformer); keyword.sym }
- special_form 'syntax-rules', primitive { |rules| SyntaxRules.new(rules) }
+ special_form 'syntax-rules', primitive { |literals, *rules|
+ Transformer.new(literals, rules) }
- class SyntaxRules
- def initialize(rules)
- @rules = rules.cdr.cdr
+ class Transformer
+ def initialize(literals, rules)
+ @rules = rules
end
def call(body)
@@ -27,6 +26,7 @@ def find_matching_rule(rules, body)
end
def matches?(rule, body)
+ # puts "Matching #{rule.inspect} with #{body.inspect}..."
if rule.null? and body.null?
true
elsif rule.is_a?(Sym) and !body.is_a?(Cons)
2  test/test_parser.rb
View
@@ -27,7 +27,7 @@ def test_tokenize
assert_equal([:'(', :'+'.sym, 2, :'(', :'+'.sym, 22, 2, :')', :')'],
BusScheme.tokenize("(+ 2 (+ 22 2))"))
assert_equal([:'(', :plus.sym, 2, 2, :')'], BusScheme.tokenize('(plus 2 2)'))
- assert_equal([:'(', :'...', :')'], BusScheme.tokenize('(...)'))
+ assert_equal([:'(', :'...'.sym, :')'], BusScheme.tokenize('(...)'))
end
def test_parse_numbers
4 test/test_syntax.rb
View
@@ -2,10 +2,10 @@
class TestSyntax < Test::Unit::TestCase
def test_definition
- assert_kind_of SyntaxRules, eval_either('(syntax-rules () ())')
+ assert_kind_of Transformer, eval_either('(syntax-rules () ())')
assert_kind_of Primitive, BusScheme['define-syntax'.sym]
eval_either('(define-syntax my-syntax (syntax-rules ()))')
- assert_kind_of SyntaxRules, BusScheme['my-syntax'.sym]
+ assert_kind_of Transformer, BusScheme['my-syntax'.sym]
end
def test_find_matching_rule
Please sign in to comment.
Something went wrong with that request. Please try again.