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