PageRenderTime 123ms CodeModel.GetById 50ms app.highlight 2ms RepoModel.GetById 68ms app.codeStats 0ms

/parse-scheme.ss

http://github.com/yinwang0/ydiff
Scheme | 63 lines | 23 code | 21 blank | 19 comment | 0 complexity | 51511ec66d4dfda0bcb9bb7f153b50f4 MD5 | raw file
 1;; ydiff - a language-aware tool for comparing programs
 2;; Copyright (C) 2011 Yin Wang (yinwang0@gmail.com)
 3
 4;; This program is free software: you can redistribute it and/or modify
 5;; it under the terms of the GNU General Public License as published by
 6;; the Free Software Foundation, either version 3 of the License, or
 7;; (at your option) any later version.
 8
 9;; This program is distributed in the hope that it will be useful,
10;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12;; GNU General Public License for more details.
13
14;; You should have received a copy of the GNU General Public License
15;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17
18
19(load "parsec.ss")
20
21
22;-------------------------------------------------------------
23;                     scanner setttings
24;-------------------------------------------------------------
25
26; single quote is considered a delimeter in s-expression
27(define *delims* (list "("  ")"  "["  "]"  "{"  "}" "'"  "`"  "," ))
28(define *line-comment* (list ";"))
29(define *comment-start* "")
30(define *comment-end* "")
31(define *operators*  '())
32(define *quotation-marks* '(#\"))
33(define *lisp-char* (list "#\\" "?\\"))
34(define *significant-whitespaces* '())
35
36
37
38;-------------------------------------------------------------
39;                        parser
40;-------------------------------------------------------------
41
42(:: $open
43     (@or (@~ "(") (@~ "[")))
44
45(:: $close
46     (@or (@~ ")") (@~ "]")))
47
48(:: $non-parens
49     (@and (@! $open) (@! $close)))
50
51(::= $parens 'sexp
52     (@seq $open (@* $sexp) $close))
53
54(:: $sexp
55    (@+ (@or $parens $non-parens)))
56
57(:: $program $sexp)
58
59
60(define parse-scheme
61  (lambda (s)
62    (first-val ($eval $sexp (scan s)))))
63