[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] GNU Guile branch, lua, updated. release_1-9-10-198-gfe95
From: |
No Itisnt |
Subject: |
[Guile-commits] GNU Guile branch, lua, updated. release_1-9-10-198-gfe959e0 |
Date: |
Wed, 26 May 2010 20:27:32 +0000 |
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Guile".
http://git.savannah.gnu.org/cgit/guile.git/commit/?id=fe959e02a1f042c435c08518b1498d22fa94bf98
The branch, lua has been updated
via fe959e02a1f042c435c08518b1498d22fa94bf98 (commit)
via f0b995a207dc0ed1ba13a10a79c03e765d97561a (commit)
via 6942d86409130df766f6ce16a15c0de7b207db61 (commit)
via 81cc6a84e69c36d10bb1d4a1e44b3ebb968312c8 (commit)
via e525e4e4995ea9115bd91e0fd6ce25b1bcdb6790 (commit)
via d365b8d31d6424d42c579dc098801570aa9cca80 (commit)
from b10c4e52116f01860e159abe42b935560abbbb8c (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit fe959e02a1f042c435c08518b1498d22fa94bf98
Author: No Itisnt <address@hidden>
Date: Wed May 26 15:18:37 2010 -0500
Lua lexer now supports single-line comments and source code information.
* module/language/lua/common.scm: New module for shared guile-lua
implementation
code, currently contains the source code location record.
* module/language/lua/lexer.scm: Refactored; supports single-line comments
commit f0b995a207dc0ed1ba13a10a79c03e765d97561a
Merge: 81cc6a84e69c36d10bb1d4a1e44b3ebb968312c8
6942d86409130df766f6ce16a15c0de7b207db61
Author: No Itisnt <address@hidden>
Date: Tue May 25 16:16:45 2010 -0500
Merge branch 'master' into lua
commit 6942d86409130df766f6ce16a15c0de7b207db61
Author: No Itisnt <address@hidden>
Date: Tue May 25 15:53:24 2010 -0500
* doc/ref/srfi-modules.texi:
* module/srfi/srfi-9/gnu.scm: rename `define-record-printer' to
`set-record-printer!' to reflect the fact that the printer is set at
runtime
commit 81cc6a84e69c36d10bb1d4a1e44b3ebb968312c8
Merge: d365b8d31d6424d42c579dc098801570aa9cca80
e525e4e4995ea9115bd91e0fd6ce25b1bcdb6790
Author: No Itisnt <address@hidden>
Date: Tue May 25 15:49:45 2010 -0500
Merge branch 'master' into lua
commit e525e4e4995ea9115bd91e0fd6ce25b1bcdb6790
Author: No Itisnt <address@hidden>
Date: Tue May 25 15:47:35 2010 -0500
add custom record printers
* doc/ref/srfi-modules.texi: update documentation
* module/srfi/srfi-9/gnu.scm: add `define-record-printer'
commit d365b8d31d6424d42c579dc098801570aa9cca80
Author: No Itisnt <address@hidden>
Date: Tue May 25 14:47:43 2010 -0500
* test-suite/tests/lua.test: fix tests
-----------------------------------------------------------------------
Summary of changes:
NOTES-LUA | 4 +
doc/ref/srfi-modules.texi | 29 +++++++++
module/language/lua/common.scm | 11 +++
module/language/lua/lexer.scm | 84 ++++++++++++++++---------
module/srfi/{srfi-8.scm => srfi-9/gnu.scm} | 16 ++---
test-suite/tests/{lua.test => lua-lexer.test} | 29 +++++++--
6 files changed, 128 insertions(+), 45 deletions(-)
create mode 100644 module/language/lua/common.scm
copy module/srfi/{srfi-8.scm => srfi-9/gnu.scm} (70%)
rename test-suite/tests/{lua.test => lua-lexer.test} (52%)
diff --git a/NOTES-LUA b/NOTES-LUA
index e69de29..0ccc0b8 100644
--- a/NOTES-LUA
+++ b/NOTES-LUA
@@ -0,0 +1,4 @@
+* To-do list
+** TODO String escape sequences
+** TODO Multiline strings (the ones in brackets)
+** TODO Single-quoted strings
diff --git a/doc/ref/srfi-modules.texi b/doc/ref/srfi-modules.texi
index 0d192fa..b3f9946 100644
--- a/doc/ref/srfi-modules.texi
+++ b/doc/ref/srfi-modules.texi
@@ -1922,6 +1922,35 @@ The functions created by @code{define-record-type} are
ordinary
top-level @code{define}s. They can be redefined or @code{set!} as
desired, exported from a module, etc.
address@hidden
+* SRFI-9 Custom printers:: Customizing print behavior.
address@hidden menu
+
address@hidden SRFI-9 Custom printers
address@hidden Custom printers
address@hidden record printer
+
+You may use @code{set-record-printer!} to customize the default printing
+behavior of records. This is a GUILE extension and is not part of SRFI-9. It is
+located in the @nicode{(srfi srfi-9 gnu)} module.
+
address@hidden {library syntax} set-record-printer! name thunk
+Where @var{type} corresponds to the first argument of
@code{define-record-type},
+and @var{thunk} is a procedure accepting two arguments, the record to print,
and
+an output port.
+
address@hidden deffn
+
address@hidden
+This example prints the employee's name in brackets, for instance
address@hidden''.
+
address@hidden
+(set-record-printer! employee-type
+ (lambda (record port)
+ (write-char #\[ port)
+ (display (get-employee-name record) port)
+ (write-char #\] port)))
address@hidden example
@node SRFI-10
@subsection SRFI-10 - Hash-Comma Reader Extension
diff --git a/module/language/lua/common.scm b/module/language/lua/common.scm
new file mode 100644
index 0000000..78852fb
--- /dev/null
+++ b/module/language/lua/common.scm
@@ -0,0 +1,11 @@
+(define-module (language lua common)
+ #:use-module (srfi srfi-9)
+
+ #:export (make-location location?))
+
+(define-record-type location
+ (make-location file line column)
+ location?
+ (file location/file)
+ (line location/line)
+ (column location/column))
\ No newline at end of file
diff --git a/module/language/lua/lexer.scm b/module/language/lua/lexer.scm
index 8c38e47..3bb0292 100644
--- a/module/language/lua/lexer.scm
+++ b/module/language/lua/lexer.scm
@@ -1,44 +1,68 @@
(define-module (language lua lexer)
#:use-module (srfi srfi-9)
#:use-module ((rnrs control) #:version (6))
- #:export (make-token make-lexer token/type token/value))
-(define (assert-no-eof port desc)
- (when (eof-object? (peek-char port))
- (throw 'lua-unexpected-eof (string-append "unexpected end-of-file "
desc))))
+ #:use-module (language lua common)
+ #:export (make-token lex token/type token/value))
-(define-syntax define-record-printer
- (syntax-rules ()
- ((_ name thunk)
- (struct-set! name vtable-index-printer thunk))))
+;;;;; TOKENS
(define-record-type token
- (make-token type value)
+ (%make-token type location value)
token?
(type token/type)
+ (location token/location)
(value token/value))
-(define-record-printer token
- (lambda (r p)
- (write-char #\<)
- (write (token/type r))
- (write-char #\space)
- (write (token/value r))
- (write-char #\>)))
+;; This is a macro to make sure the location is retrieved before the token is
+;; consumed
+(define-syntax make-token
+ (syntax-rules ()
+ ;; auxilliary pattern to make the location, used below
+ ((_ (port))
+ (make-location (port-filename port) (port-line port) (port-column port)))
+ ;; actual pattern
+ ((_ port type value)
+ (let* ((location (make-token (port))))
+ (%make-token type location value)))))
+
+;;;;; UTILITIES
+
+(define (assert-no-eof port desc)
+ (when (eof-object? (peek-char port))
+ (throw 'lua-unexpected-eof (string-append "unexpected end-of-file "
desc))))
(define (eat-char port) (read-char port) (if #f #f))
-(define (make-lexer port)
- (define (lex-string)
- (eat-char port)
- (with-output-to-string
- (lambda ()
- (let loop ((c (peek-char port)))
- (assert-no-eof port "in string")
- (cond ((eq? c #\") (get-output-string (current-output-port)))
- (else (write-char (read-char port)) (loop (peek-char
port))))))))
- (lambda ()
- (define c (peek-char port))
- (cond ((eof-object? c) c)
- ((eq? c #\") (make-token 'string (lex-string)))
- (else #f))))
+(define (newline? c) (or (eq? c #\newline) (eq? c #\cr)))
+
+;;;;; LEXER
+
+;; Strings
+(define (lex-string port quote-character allow-newlines?)
+ (make-token port 'string
+ (with-output-to-string
+ (lambda ()
+ (eat-char port)
+ (let loop ((c (peek-char port)))
+ (assert-no-eof port "in string")
+ (cond ((eq? c quote-character) (get-output-string
(current-output-port)))
+ (else (write-char (read-char port)) (loop (peek-char port)))))))))
+
+(define (lex-comment port)
+ (while (not (or (eof-object? (peek-char port)) (newline? (peek-char port))))
+ (eat-char port))
+ #f)
+
+;; Main loop
+(define (lex port)
+ (define c (peek-char port))
+ (cond ((eof-object? c) c)
+ ((eq? c #\-)
+ (read-char port)
+ (if (eq? (peek-char port) #\-)
+ (lex-comment port)
+ (error)))
+ ((eq? c #\") (lex-string port #\" #f))
+ ((eq? c #\') (lex-string port #\' #f))
+ (else (error))))
diff --git a/module/srfi/srfi-8.scm b/module/srfi/srfi-9/gnu.scm
similarity index 70%
copy from module/srfi/srfi-8.scm
copy to module/srfi/srfi-9/gnu.scm
index ced1238..3a37471 100644
--- a/module/srfi/srfi-8.scm
+++ b/module/srfi/srfi-9/gnu.scm
@@ -1,6 +1,6 @@
-;;; srfi-8.scm --- receive
+;;; Extensions to SRFI-9
-;; Copyright (C) 2000, 2001, 2002, 2006 Free Software Foundation, Inc.
+;; Copyright (C) 2010 Free Software Foundation, Inc.
;;
;; This library is free software; you can redistribute it and/or
;; modify it under the terms of the GNU Lesser General Public
@@ -18,14 +18,12 @@
;;; Commentary:
-;; This module is fully documented in the Guile Reference Manual.
+;; Extensions to SRFI-9. Fully documented in the Guile Reference Manual.
;;; Code:
-(define-module (srfi srfi-8)
- :use-module (ice-9 receive)
- :re-export-syntax (receive))
+(define-module (srfi srfi-9 gnu)
+ #:export (set-record-printer!))
-(cond-expand-provide (current-module) '(srfi-8))
-
-;;; srfi-8.scm ends here
+(define (set-record-printer! type thunk)
+ (struct-set! type vtable-index-printer thunk))
diff --git a/test-suite/tests/lua.test b/test-suite/tests/lua-lexer.test
similarity index 52%
rename from test-suite/tests/lua.test
rename to test-suite/tests/lua-lexer.test
index fb2a26c..400af94 100644
--- a/test-suite/tests/lua.test
+++ b/test-suite/tests/lua-lexer.test
@@ -15,16 +15,19 @@
(and (eq? type (token/type token)) (equal? value (token/value token))))
(define (read-token-from-string string)
- ((make-lexer (open-input-string string))))
+ (lex (open-input-string string)))
+;; Test that an improperly terminated bit of code is properly handled by
+;; throwing 'lua-unexpected-eof
(define-syntax eof
(syntax-rules ()
((_ name string)
(pass-if name
- ((catch 'lua-unexpected-eof
- (lambda () (read-token-from-string string) #f)
- (lambda (key val) #t)))))))
+ (catch 'lua-unexpected-eof
+ (lambda () (read-token-from-string string) #f)
+ (lambda (key . args) #t))))))
+;; Test return value of lexer against a token
(define-syntax token
(syntax-rules ()
((_ name string result-type result-value)
@@ -32,10 +35,24 @@
(token-equal=?
result-type result-value
(read-token-from-string string))))))
-
+
+;; Assert that no token is returned (such as if a comment is consumed)
+(define-syntax no-token
+ (syntax-rules ()
+ ((_ name string)
+ (pass-if name
+ (equal? #f (read-token-from-string string))))))
+
(with-test-prefix "lua"
+ ;; Strings
+ (display (read-token-from-string "\"hello world\""))
+ (newline)
+
(token "string" "\"hello world\"" 'string "hello world")
+ (eof "string without end quote" "\"hell")
- (eof "string without terminator" "\"hell")
+ ;; Comments
+ (no-token "comment" "-- comment")
+ ;; Numbers
)
\ No newline at end of file
hooks/post-receive
--
GNU Guile
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Guile-commits] GNU Guile branch, lua, updated. release_1-9-10-198-gfe959e0,
No Itisnt <=