Permalink
Browse files

In the Schemer lexer, EVERYTHING IS A LIST

  • Loading branch information...
Josep M. Bach
Josep M. Bach committed Mar 15, 2011
1 parent cba9f56 commit 89f058bb7cced82e0a4d72d65444924bc9bd3ca8
Showing with 16 additions and 19 deletions.
  1. +2 −3 lib/schemer/lexer.rb
  2. +14 −16 spec/schemer/lexer_spec.rb
View
@@ -36,13 +36,12 @@ class Lexer < Parslet::Parser
rule(:operator) { `+` | `-` | `*` | `/` | `>=` | `<=` | `>` | `<` | `=` }
- rule(:arg) { (symbol.as(:identifier) | quoted_list | literal | quoted_symbol | procedure | pair | vector | list) }
+ rule(:arg) { (symbol | operator | quoted_list | literal | quoted_symbol | pair | vector | list) }
rule(:args) { (arg >> space?).repeat }
rule(:comment) { `;`.repeat(1,3) >> (`\n`.absnt? >> any).repeat.as(:comment) }
- rule(:procedure) { (lparen >> ((symbol | operator).as(:identifier) | procedure).as(:proc) >> (space? >> args.as(:args)).maybe >> rparen).as(:procedure) }
- rule(:body) { (procedure | space | comment).repeat(0) }
+ rule(:body) { (list | space | comment).repeat(0) }
root :body
end
View
@@ -44,22 +44,20 @@ module Schemer
its(:list) { should parse('(1 2 3)').as(:list => [{:integer => '1'}, {:integer => '2'}, {:integer => '3'}]) }
its(:list) { should parse('()').as(:list => []) }
- its(:list) { should parse('( )') }
-
- its(:procedure) { should parse('(define some "string" #t)') }
- its(:procedure) { should parse(%q{((lambda some arg) (get_some_proc) yeah "string" ((proc-proc) "another-string"))}) }
- its(:procedure) { should parse('((lambda) "foo")') }
-
- its(:procedure) { should(parse('(lambda (x) (+ x x))')) }
-
- its(:procedure) { should parse("((lambda) (1 2 3))") }
- its(:procedure) { should parse("((lambda) '(1 2 3))") }
- its(:procedure) { should parse('((lambda) (bar))') }
- its(:procedure) { should parse('(lambda (define zara \'zara) (write (eqv? zara \'zara)))') }
- its(:procedure) { should(parse("(lambda (define (make-new-set?) '()) (define (make-new-set?) '(2 3)))").as do |output|
- output[:procedure][:args].should have(2).procedures
- output[:procedure][:args].first[:procedure][:args].should include(:quoted_list => [])
- output[:procedure][:args].last[:procedure][:args].should include(:quoted_list => [{:integer =>"2"}, {:integer => "3"}])
+ its(:list) { should parse('( )').as(:list => []) }
+
+ its(:list) { should parse('(define some "string" #t)') }
+ its(:list) { should parse(%q{((lambda some arg) (get_some_proc) yeah "string" ((proc-proc) "another-string"))}) }
+ its(:list) { should parse('((lambda) "foo")') }
+
+ its(:list) { should(parse('(lambda x (+ x x))')) }
+
+ its(:list) { should parse("((lambda) (1 2 3))") }
+ its(:list) { should parse("((lambda) '(1 2 3))") }
+ its(:list) { should parse('((lambda) (bar))') }
+ its(:list) { should parse('(lambda (define zara \'zara) (write (eqv? zara \'zara)))') }
+ its(:list) { should(parse("(lambda (define (make-new-set?) '()) (define (make-new-set?) '(2 3)))").as do |output|
+ output[:list].should have(2).lists
end) }
# Regression tests

0 comments on commit 89f058b

Please sign in to comment.