]> git.mdlowis.com Git - archive/dlang-scm.git/commitdiff
Refactord collector functions and added comments for tests that need to be written
authorMike D. Lowis <mike@mdlowis.com>
Mon, 30 Jul 2012 20:55:01 +0000 (16:55 -0400)
committerMike D. Lowis <mike@mdlowis.com>
Mon, 30 Jul 2012 20:55:01 +0000 (16:55 -0400)
source/lexer.scm
source/parse-utils.scm
source/parser.scm
tests/test_parse_utils.scm

index 7c616db1c0dd16a322f7611b7be4c96f3790eb3c..3173b3d01796d84ff3b8d62309bbaf12509e3ed0 100644 (file)
@@ -83,7 +83,7 @@
   (if (and
         (not (eof-object? (buf-lookahead! in 1)))
         (char-numeric? (buf-lookahead! in 1)))
-    (collect-char in dlang/integer? "")
+    (collect-char in dlang/integer?)
     (abort "Expected an integer")))
 
 (define (dlang/integer? in)
   (define text
     (string-append
       (string (char-match in #\"))
-      (collect-char in dlang/string-char? "")
+      (collect-char in dlang/string-char?)
       (string (char-match in #\"))))
   (token 'string text))
 
       (token-text (dlang/id in)))))
 
 (define (dlang/id in)
-  (define str(collect-char in dlang/id-char? ""))
+  (define str(collect-char in dlang/id-char?))
   (if (> (string-length str) 0)
     (token 'id str)
     (abort "An Id was expected but none found.")))
index f23ff996cc04940355be4fe6b5bab21007262737..23172ad9b0e8ad5b7c7a3bb2571f73ee9556b47c 100644 (file)
   (buf-release! buf)
   (not (null? result)))
 
-(define (collect-char in fn str)
-  (if (fn in)
-    (collect-char in fn (string-append str (string (buf-consume! in))))
-    str))
+(define (collect-char in predfn)
+  (list->string (collect in predfn buf-consume!)))
 
-(define (consume-all in fn)
-  (when (fn in)
+(define (consume-all in predfn)
+  (when (predfn in)
     (buf-consume! in)
-    (consume-all in fn)))
+    (consume-all in predfn)))
 
-(define (collect in fn rulefn lst)
+(define (collect in fn rulefn)
   (if (fn in)
-    (collect in fn rulefn (append lst (list (rulefn in))))
-    lst))
+    (cons (rulefn in) (collect in fn rulefn))
+    '()))
+
index 28252221f2126da9fce9cb0513ae214db8dbdded..3c08fd81306f5d25c096dade5dd3232855fc8637 100644 (file)
@@ -27,7 +27,7 @@
 ;------------------------------------------------------------------------------
 
 (define (dlang/program in)
-  (collect in dlang/has-expression? dlang/expression '()))
+  (collect in dlang/has-expression? dlang/expression))
 
 (define (dlang/has-expression? in)
   (not (eof-object? (buf-lookahead! in 1))))
   (define tree (syntree 'arglist "" '()))
   (token-match in 'lpar)
   (syntree-children-set! tree
-    (collect in dlang/list-end? dlang/arg-list-item '()))
+    (collect in dlang/list-end? dlang/arg-list-item))
   (token-match in 'rpar)
   tree)
 
   (define tree (syntree 'args "" '()))
   (token-match in 'lpar)
   (syntree-children-set! tree
-    (collect in dlang/list-end? dlang/id-list-item '()))
+    (collect in dlang/list-end? dlang/id-list-item))
   (token-match in 'rpar)
   tree)
 
     (collect
       in
       (lambda (buf) (not (token-matches? buf term)))
-      dlang/expression
-      '() )))
+      dlang/expression)))
 
index 7b1229f261c2a7d86c60bc157e72a97a952a74cc..74b37369ec522aec0048a5b9810e5ffacffdc021 100644 (file)
 
 ; keyword-match
 ;------------------------------------------------------------------------------
+;(def-test "keyword-match should consume and return if next token matches"
+;(def-test "keyword-match should error if next token not an id"
+;(def-test "keyword-match should error if next token does not match"
 
 ; token->syntree
 ;------------------------------------------------------------------------------
 
 ; test-apply
 ;------------------------------------------------------------------------------
+;(def-test "test-apply should return true if the input matches the applied rule"
+;(def-test "test-apply should return false if the applied rule fails"
 
 ; collect-char
 ;------------------------------------------------------------------------------
+;(def-test "should return empty string if predicate function returns false"
+;(def-test "should return string containing chars from buffer when predicate returns true"
 
 ; consume-all
 ;------------------------------------------------------------------------------
+;(def-test "should consume nothing if predicate never returns true"
+;(def-test "should an item at a time until predicate returns false"
 
 ; collect
 ;------------------------------------------------------------------------------
-
+;(def-test "should return empty list if predicate never returns true"
+;(def-test "should return list of items for which predicate returned false"