From: Mike D. Lowis Date: Thu, 12 Jul 2012 20:23:03 +0000 (-0400) Subject: Added vim script for generating and working with CTags as well as tests for the termi... X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=a01914edca7c53381360403152ab5a9d072012a5;p=archive%2Fdlang-scm.git Added vim script for generating and working with CTags as well as tests for the terminator tokens and comma recognition --- diff --git a/project.vim b/project.vim index e69de29..c702b5e 100644 --- a/project.vim +++ b/project.vim @@ -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 +map :call RefreshCTags() +map :execute("find " . g:TestSrcPath . "/**/test_" . expand("%:t:r") . ".scm") +map :make + +"------------------------------------------------------------------------------ +" Connect To CTags +"------------------------------------------------------------------------------ +call ConnectCTags() + diff --git a/source/lexer.scm b/source/lexer.scm index e74f803..2db5bf3 100644 --- a/source/lexer.scm +++ b/source/lexer.scm @@ -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)) diff --git a/tests/test_lexer.scm b/tests/test_lexer.scm index 99787f6..91a7b8b 100644 --- a/tests/test_lexer.scm +++ b/tests/test_lexer.scm @@ -115,6 +115,33 @@ (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"