]> git.mdlowis.com Git - archive/dlang-scm.git/commitdiff
Added vim script for generating and working with CTags as well as tests for the termi...
authorMike D. Lowis <mike@mdlowis.com>
Thu, 12 Jul 2012 20:23:03 +0000 (16:23 -0400)
committerMike D. Lowis <mike@mdlowis.com>
Thu, 12 Jul 2012 20:23:03 +0000 (16:23 -0400)
project.vim
source/lexer.scm
tests/test_lexer.scm

index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..c702b5e45ababab10641862799949169664d0e1b 100644 (file)
@@ -0,0 +1,35 @@
+"------------------------------------------------------------------------------
+" Global Config Variables
+"------------------------------------------------------------------------------
+let g:ProjectPath = getcwd()
+let g:TestSrcPath = g:ProjectPath . "/tests"
+let g:CTagsFile   = g:ProjectPath . "/tags"
+
+"------------------------------------------------------------------------------
+" Global Function Definitions
+"------------------------------------------------------------------------------
+" Connect to the Correct CTags File
+function! ConnectCTags()
+    execute("set tags=" . g:CTagsFile)
+endfunction
+
+" Update the CTags File
+function! RefreshCTags()
+     if strlen(g:CTagsFile)
+        execute('silent ! ctags -R *')
+     endif
+endfunction
+
+"------------------------------------------------------------------------------
+" Project Specific Key Mappings
+"------------------------------------------------------------------------------
+map <silent> <F2>  <F3>
+map <silent> <F3>  <ESC>:call RefreshCTags()<CR>
+map <silent> <F6>  <ESC>:execute("find " . g:TestSrcPath . "/**/test_" . expand("%:t:r") . ".scm")<CR>
+map <silent> <F10> <ESC>:make<CR>
+
+"------------------------------------------------------------------------------
+" Connect To CTags
+"------------------------------------------------------------------------------
+call ConnectCTags()
+
index e74f80344395370ddbe1d7628249b4fed8f5f13f..2db5bf31fdf790e35f89fb15f368012c4a0ec248 100644 (file)
@@ -8,42 +8,51 @@
 
 (define (dlang/tokenize in)
   (let ((ch (buf-lookahead! in 1)))
-    (cond
-      ; End of Input reached
-      ((eof-object? ch) ch)
-
-      ; Whitespace
-      ((char-whitespace? ch)
-       (dlang/whitespace in))
-
-      ; Comment
-      ((char=? ch #\#)
-       (dlang/comment in))
-
-      ; Number
-      ((or
-         (and (char=? ch #\-) (char-numeric? (buf-lookahead! in 2)))
-         (char-numeric? ch))
-       (dlang/number in))
-
-      ; Character
-      ((char=? ch #\') (dlang/character in))
-
-      ; String
-      ((char=? ch #\") (dlang/string in))
-
-      ; Symbol
-      ((char=? ch #\$) (dlang/symbol in))
-
-      ; Parentheses
-      ((char=? ch #\()
-       (token 'lpar (string (buf-consume! in))))
-      ((char=? ch #\))
-       (token 'rpar (string (buf-consume! in))))
-
-      ; Id
-      (else
-        (dlang/id in)))))
+    (define tok
+      (cond
+        ; End of Input reached
+        ((eof-object? ch) ch)
+
+        ; Whitespace
+        ((char-whitespace? ch)
+         (dlang/whitespace in))
+
+        ; Comment
+        ((char=? ch #\#)
+         (dlang/comment in))
+
+        ; Number
+        ((or
+           (and (char=? ch #\-) (char-numeric? (buf-lookahead! in 2)))
+           (char-numeric? ch))
+         (dlang/number in))
+
+        ; Character
+        ((char=? ch #\') (dlang/character in))
+
+        ; String
+        ((char=? ch #\") (dlang/string in))
+
+        ; Symbol
+        ((char=? ch #\$) (dlang/symbol in))
+
+        ; Punctuation and Parens
+        ((char=? ch #\()
+         (token 'lpar (string (buf-consume! in))))
+        ((char=? ch #\))
+         (token 'rpar (string (buf-consume! in))))
+        ((char=? ch #\,)
+         (token 'comma (string (buf-consume! in))))
+        ((char=? ch #\;)
+         (token 'term (string (buf-consume! in))))
+
+        ; Id
+        (else
+          (dlang/id in))))
+    (if (and (not (eof-object? tok))
+             (equal? "end" (token-text tok)))
+      (token-type-set! tok 'term))
+    tok))
 
 (define (dlang/whitespace in)
   (while (char-whitespace? (buf-lookahead! in 1))
index 99787f6a300b7004c3cff5211a6410bd8c32047d..91a7b8bd716b72808f394fe0d1b1c6bdcc9c86f4 100644 (file)
            (equal? 'rpar (token-type result))
            (equal? ")" (token-text result))))))
 
+(def-test "dlang/tokenize should recognize a comma"
+  (call-with-input-string ","
+    (lambda (input)
+      (define buffer (buf input read-char))
+      (define result (dlang/tokenize buffer))
+      (and (token? result)
+           (equal? 'comma (token-type result))
+           (equal? "," (token-text result))))))
+
+(def-test "dlang/tokenize should recognize a semicolon"
+  (call-with-input-string ";"
+    (lambda (input)
+      (define buffer (buf input read-char))
+      (define result (dlang/tokenize buffer))
+      (and (token? result)
+           (equal? 'term (token-type result))
+           (equal? ";" (token-text result))))))
+
+(def-test "dlang/tokenize should recognize the end keyword"
+  (call-with-input-string "end"
+    (lambda (input)
+      (define buffer (buf input read-char))
+      (define result (dlang/tokenize buffer))
+      (and (token? result)
+           (equal? 'term (token-type result))
+           (equal? "end" (token-text result))))))
+
 ; dlang/whitespace
 ;------------------------------------------------------------------------------
 (def-test "dlang/whitespace should recognize and consume whitespace"