parent
90f897a379
commit
923df895c5
@ -0,0 +1,64 @@
|
|||||||
|
config.guess
|
||||||
|
config.sub
|
||||||
|
config.h.in
|
||||||
|
configure
|
||||||
|
obj/*
|
||||||
|
*.so
|
||||||
|
*.o
|
||||||
|
Makefile
|
||||||
|
.deps
|
||||||
|
.libs
|
||||||
|
autom4te.cache
|
||||||
|
config.h
|
||||||
|
*.doc
|
||||||
|
*.x
|
||||||
|
*.lo
|
||||||
|
*.la
|
||||||
|
aclocal.m4
|
||||||
|
depcomp
|
||||||
|
missing
|
||||||
|
mdate-sh
|
||||||
|
texinfo.tex
|
||||||
|
*~
|
||||||
|
,*
|
||||||
|
aclocal.m4
|
||||||
|
confdefs.h
|
||||||
|
config.build-subdirs
|
||||||
|
config.cache
|
||||||
|
config.h
|
||||||
|
config.status
|
||||||
|
conftest
|
||||||
|
conftest.c
|
||||||
|
depcomp
|
||||||
|
ltconfig
|
||||||
|
mdate-sh
|
||||||
|
missing
|
||||||
|
mkinstalldirs
|
||||||
|
stamp-h1
|
||||||
|
*.go
|
||||||
|
cscope.out
|
||||||
|
cscope.files
|
||||||
|
*.log
|
||||||
|
*.aux
|
||||||
|
*.cp
|
||||||
|
*.cps
|
||||||
|
*.dvi
|
||||||
|
*.fn
|
||||||
|
*.fns
|
||||||
|
*.ky
|
||||||
|
*.pg
|
||||||
|
*.toc
|
||||||
|
*.tp
|
||||||
|
*.vr
|
||||||
|
*.tps
|
||||||
|
*.vrs
|
||||||
|
*.pgs
|
||||||
|
*.rn
|
||||||
|
*.rns
|
||||||
|
*.scan
|
||||||
|
*.am
|
||||||
|
*.d
|
||||||
|
version.scm
|
||||||
|
*.m4
|
||||||
|
ltmain.sh
|
||||||
|
libtool
|
||||||
@ -0,0 +1,82 @@
|
|||||||
|
;; Copyright (C) 2013
|
||||||
|
;; "Mu Lei" known as "NalaGinrut" <NalaGinrut@gmail.com>
|
||||||
|
;; This file is free software: you can redistribute it and/or modify
|
||||||
|
;; it under the terms of the GNU General Public License as published by
|
||||||
|
;; the Free Software Foundation, either version 3 of the License, or
|
||||||
|
;; (at your option) any later version.
|
||||||
|
|
||||||
|
;; This file is distributed in the hope that it will be useful,
|
||||||
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
;; GNU General Public License for more details.
|
||||||
|
|
||||||
|
;; You should have received a copy of the GNU General Public License
|
||||||
|
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
(define-module (language csv compile-tree-il)
|
||||||
|
#:use-module (language tree-il)
|
||||||
|
#:use-module (ice-9 receive)
|
||||||
|
#:use-module (system base pmatch)
|
||||||
|
#:use-module (srfi srfi-1)
|
||||||
|
#:export (compile-tree-il))
|
||||||
|
|
||||||
|
(define-syntax-rule (-> (type arg ...))
|
||||||
|
`(type ,arg ...))
|
||||||
|
|
||||||
|
(define empty-lexical-environment
|
||||||
|
(make-hash-table))
|
||||||
|
|
||||||
|
(define (csv-init)
|
||||||
|
#t
|
||||||
|
;; nothing to do yet.
|
||||||
|
)
|
||||||
|
|
||||||
|
(define (compile-tree-il exp env opts)
|
||||||
|
(values
|
||||||
|
(parse-tree-il
|
||||||
|
(begin (imp-init)
|
||||||
|
(comp exp empty-lexical-environment)))
|
||||||
|
env
|
||||||
|
env))
|
||||||
|
|
||||||
|
(define (location x)
|
||||||
|
(and (pair? x)
|
||||||
|
(let ((props (source-properties x)))
|
||||||
|
(and (not (null? props))
|
||||||
|
props))))
|
||||||
|
|
||||||
|
(define-syntax-rule (->boolean x)
|
||||||
|
(not (eq? x 'false)))
|
||||||
|
|
||||||
|
;; for emacs:
|
||||||
|
;; (put 'pmatch/source 'scheme-indent-function 1)
|
||||||
|
|
||||||
|
(define-syntax-rule (pmatch/source x clause ...)
|
||||||
|
(let ((x x))
|
||||||
|
(let ((res (pmatch x
|
||||||
|
clause ...)))
|
||||||
|
(let ((loc (location x)))
|
||||||
|
(if loc
|
||||||
|
(set-source-properties! res (location x))))
|
||||||
|
res)))
|
||||||
|
|
||||||
|
(define (lookup name env)
|
||||||
|
(hash-ref env name))
|
||||||
|
|
||||||
|
(define (store name value env)
|
||||||
|
(hash-set! env name value))
|
||||||
|
|
||||||
|
(define (comp src e)
|
||||||
|
(let ((l 0));;(location src)))
|
||||||
|
(define (let1 what proc)
|
||||||
|
(let ((sym (gensym)))
|
||||||
|
(-> (let (list sym) (list sym) (list what)
|
||||||
|
(proc sym)))))
|
||||||
|
(define (begin1 what proc)
|
||||||
|
(let1 what (lambda (v)
|
||||||
|
(-> (begin (proc v)
|
||||||
|
(-> (lexical v v)))))))
|
||||||
|
(pmatch/source
|
||||||
|
src
|
||||||
|
)))
|
||||||
|
|
||||||
@ -0,0 +1,52 @@
|
|||||||
|
;; Copyright (C) 2012
|
||||||
|
;; "Mu Lei" known as "NalaGinrut" <NalaGinrut@gmail.com>
|
||||||
|
;; This file is free software: you can redistribute it and/or modify
|
||||||
|
;; it under the terms of the GNU General Public License as published by
|
||||||
|
;; the Free Software Foundation, either version 3 of the License, or
|
||||||
|
;; (at your option) any later version.
|
||||||
|
|
||||||
|
;; This file is distributed in the hope that it will be useful,
|
||||||
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
;; GNU General Public License for more details.
|
||||||
|
|
||||||
|
;; You should have received a copy of the GNU General Public License
|
||||||
|
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
(define-module (language csv lexer)
|
||||||
|
#:use-module (system base lalr)
|
||||||
|
#:use-module (ice-9 receive)
|
||||||
|
#:use-module (ice-9 rdelim)
|
||||||
|
#:export (make-csv-tokenizer))
|
||||||
|
|
||||||
|
|
||||||
|
(define (port-source-location port)
|
||||||
|
(make-source-location (port-filename port)
|
||||||
|
(port-line port)
|
||||||
|
(port-column port)
|
||||||
|
(false-if-exception (ftell port))
|
||||||
|
#f))
|
||||||
|
|
||||||
|
(define imp-tokenizer
|
||||||
|
(lambda (port)
|
||||||
|
(let* ((loc (port-source-location port))
|
||||||
|
(return (lambda (category value)
|
||||||
|
(make-lexical-token category loc value)))
|
||||||
|
(c (peek-char port)))
|
||||||
|
(cond
|
||||||
|
((eof-object? c) '*eoi*)
|
||||||
|
;; TODO
|
||||||
|
(else
|
||||||
|
(error "wrong syntax!" c))))))
|
||||||
|
|
||||||
|
(define (make-imp-tokenizer port)
|
||||||
|
(lambda ()
|
||||||
|
(imp-tokenizer port)))
|
||||||
|
|
||||||
|
;; (define imp-tokenize
|
||||||
|
;; (lambda (port)
|
||||||
|
;; (let lp ((out '()))
|
||||||
|
;; (let ((tok (imp-tokenizer port)))
|
||||||
|
;; (if (eq? tok '*eoi*)
|
||||||
|
;; (reverse! out)
|
||||||
|
;; (lp (cons tok out)))))))
|
||||||
@ -0,0 +1,49 @@
|
|||||||
|
;; Copyright (C) 2013
|
||||||
|
;; "Mu Lei" known as "NalaGinrut" <NalaGinrut@gmail.com>
|
||||||
|
;; This file is free software: you can redistribute it and/or modify
|
||||||
|
;; it under the terms of the GNU General Public License as published by
|
||||||
|
;; the Free Software Foundation, either version 3 of the License, or
|
||||||
|
;; (at your option) any later version.
|
||||||
|
|
||||||
|
;; This file is distributed in the hope that it will be useful,
|
||||||
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
;; GNU General Public License for more details.
|
||||||
|
|
||||||
|
;; You should have received a copy of the GNU General Public License
|
||||||
|
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
(define-module (language csv parser)
|
||||||
|
#:use-module (language csv lexer)
|
||||||
|
#:use-module (system base lalr)
|
||||||
|
#:export (csv-read))
|
||||||
|
|
||||||
|
(define* (syntax-error message #:optional token)
|
||||||
|
(if (lexical-token? token)
|
||||||
|
(throw 'syntax-error #f message
|
||||||
|
(and=> (lexical-token-source token)
|
||||||
|
source-location->source-properties)
|
||||||
|
(or (lexical-token-value token)
|
||||||
|
(lexical-token-category token))
|
||||||
|
#f)
|
||||||
|
(throw 'syntax-error #f message #f token #f)))
|
||||||
|
|
||||||
|
(define *eof-object*
|
||||||
|
(call-with-input-string "" read-char))
|
||||||
|
|
||||||
|
(define (csv-read port)
|
||||||
|
(let ((parse (make-parser)))
|
||||||
|
(parse (make-csv-tokenizer port) syntax-error)))
|
||||||
|
|
||||||
|
(define (make-parser)
|
||||||
|
(lalr-parser
|
||||||
|
(;; keyword
|
||||||
|
;; TODO)
|
||||||
|
|
||||||
|
(program (stmt) : $1
|
||||||
|
(*eoi*) : *eof-object*)
|
||||||
|
)))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,35 @@
|
|||||||
|
;; Copyright (C) 2013
|
||||||
|
;; "Mu Lei" known as "NalaGinrut" <NalaGinrut@gmail.com>
|
||||||
|
;; This file is free software: you can redistribute it and/or modify
|
||||||
|
;; it under the terms of the GNU General Public License as published by
|
||||||
|
;; the Free Software Foundation, either version 3 of the License, or
|
||||||
|
;; (at your option) any later version.
|
||||||
|
|
||||||
|
;; This file is distributed in the hope that it will be useful,
|
||||||
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
;; GNU General Public License for more details.
|
||||||
|
|
||||||
|
;; You should have received a copy of the GNU General Public License
|
||||||
|
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
(define-module (language csv spec)
|
||||||
|
#:use-module (system base language)
|
||||||
|
#:use-module (language csv compile-tree-il)
|
||||||
|
#:use-module (language csv parser)
|
||||||
|
#:export (csv))
|
||||||
|
|
||||||
|
;;;
|
||||||
|
;;; Language definition
|
||||||
|
;;;
|
||||||
|
|
||||||
|
;; Actually, CSV is not a language anyway, but we define this seudo language to
|
||||||
|
;; convert CSV format into s-expr.
|
||||||
|
(define-language csv
|
||||||
|
#:title "CSV language"
|
||||||
|
#:reader (lambda (port env)
|
||||||
|
(csv-read port))
|
||||||
|
#:compilers `((tree-il . ,compile-tree-il))
|
||||||
|
#:printer write
|
||||||
|
)
|
||||||
|
|
||||||
Loading…
Reference in new issue