Permalink
Browse files

simplified syntax structure

  • Loading branch information...
1 parent 839802a commit edca6575fed66e707d6372681756cb4d219424d5 Mike Aizatsky committed Jun 20, 2008
Showing with 18 additions and 17 deletions.
  1. +12 −12 scheme-parser-tests.scm
  2. +6 −5 scheme-parser.scm
View
24 scheme-parser-tests.scm
@@ -4,14 +4,14 @@
(load "scheme-parser.scm")
-(test-group "identifier"
- (test '((id . "abc") . 3) (identifier "abc" 0))
- (test '((id . "...") . 3) (identifier "..." 0))
- (test '((id . "ab@cd") . 5) (identifier "ab@cd" 0))
- (test '((id . "$ab@cd") . 6) (identifier "$ab@cd" 0))
- (test #f (identifier "@ab@cd" 0))
- (test '((id . "+") . 1) (identifier "+34abc" 0))
- (test #f (identifier "34abc" 0))
+(test-group "symbol"
+ (test '(abc . 3) (symbol "abc" 0))
+ (test '(... . 3) (symbol "..." 0))
+ (test '(ab@cd . 5) (symbol "ab@cd" 0))
+ (test '($ab@cd . 6) (symbol "$ab@cd" 0))
+ (test #f (symbol "@ab@cd" 0))
+ (test '(+ . 1) (symbol "+34abc" 0))
+ (test #f (symbol "34abc" 0))
)
(test-group "string"
@@ -22,10 +22,10 @@
)
(test-group "literal"
- (test '((literal . "abc") . 5) (literal "\"abc\"" 0))
- (test '((literal quote id . "abc") . 4) (literal "'abc" 0))
- (test '((literal quote id . "abc") . 11) (literal "(quote abc)" 0))
- (test '((literal quote id . "abc") . 14) (literal "(quote abc)" 0))
+ (test '("abc" . 5) (literal "\"abc\"" 0))
+ (test '((quote abc) . 4) (literal "'abc" 0))
+ (test '((quote abc) . 11) (literal "(quote abc)" 0))
+ (test '((quote abc) . 14) (literal "(quote abc)" 0))
)
(test-group "number"
View
11 scheme-parser.scm
@@ -187,7 +187,9 @@
(num 16)))
;; External representations
-(define symbol identifier)
+(define symbol
+ (parser i <- identifier
+ return (string->symbol i)))
(define simple-datum
(parser r <- (choice boolean
@@ -226,20 +228,19 @@
(define quotation
(choice (parser (matches "'")
d <- datum
- return (cons 'quote d))
+ return (list 'quote d))
(parser (token "(quote")
d <- datum
(token ")")
- return (cons 'quote d))))
+ return (list 'quote d))))
(define self-evaluating
(choice boolean
number
character
string))
(define literal
- (parser l <- (choice quotation self-evaluating)
- return (cons 'literal l)))
+ (choice quotation self-evaluating))
(define variable fail) ;; TODO
(define procedure-call fail) ;; TODO

0 comments on commit edca657

Please sign in to comment.