mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-28 16:00:22 +02:00
lua/common cleanup
* module/language/lua/common.scm: Remove `or-eqv?'. Make a bit more idiomatic. * module/language/lua/compile-tree-il.scm: * module/language/lua/lexer.scm: * module/language/lua/parser.scm: * module/language/lua/runtime.scm: Replace or-eqv? instances with memq or memv.
This commit is contained in:
parent
32c58e2edd
commit
a0cecd8ff2
5 changed files with 8 additions and 19 deletions
|
@ -19,22 +19,11 @@
|
||||||
;;; Code:
|
;;; Code:
|
||||||
|
|
||||||
(define-module (language lua common)
|
(define-module (language lua common)
|
||||||
|
|
||||||
#:use-module (ice-9 format)
|
#:use-module (ice-9 format)
|
||||||
|
#:export (syntax-error))
|
||||||
#:export (syntax-error or-eqv?))
|
|
||||||
|
|
||||||
(define (syntax-error src string . args)
|
(define (syntax-error src string . args)
|
||||||
"Throw an error tagged with 'syntax-error, and print detailed source
|
"Throw an error tagged with 'syntax-error, and print detailed source
|
||||||
code information when available. STRING and ARGS are given to FORMAT."
|
code information when available. STRING and ARGS are given to FORMAT."
|
||||||
(throw 'syntax-error #f (apply format #f string args)
|
(throw 'syntax-error #f (apply format #f string args)
|
||||||
src #f #f '()))
|
src #f #f '()))
|
||||||
|
|
||||||
;; I was using CASE, but this is more succinct
|
|
||||||
;; (or-eqv? 1 #f 1) => (or (eqv? 1 #f) (eqv? 1 1))
|
|
||||||
(define-syntax or-eqv?
|
|
||||||
(syntax-rules ()
|
|
||||||
((_ test '(value ...))
|
|
||||||
(or (eqv? test 'value) ...))
|
|
||||||
((_ test value ...)
|
|
||||||
(or (eqv? test value) ...))))
|
|
||||||
|
|
|
@ -201,7 +201,7 @@
|
||||||
;; so you can't use break inside of a function inside a while loop
|
;; so you can't use break inside of a function inside a while loop
|
||||||
;; for instance
|
;; for instance
|
||||||
((ast-break src)
|
((ast-break src)
|
||||||
(unless (or-eqv? (context) 'while-loop 'list-for-loop 'numeric-for-loop)
|
(unless (memq (context) '(while-loop list-for-loop numeric-for-loop))
|
||||||
(syntax-error src "no loop to break"))
|
(syntax-error src "no loop to break"))
|
||||||
(make-application src (make-module-ref src '(guile) 'throw #t) (list (make-const src 'lua-break)))
|
(make-application src (make-module-ref src '(guile) 'throw #t) (list (make-const src 'lua-break)))
|
||||||
)
|
)
|
||||||
|
|
|
@ -58,7 +58,7 @@
|
||||||
|
|
||||||
(define (possible-keyword token)
|
(define (possible-keyword token)
|
||||||
"Convert a symbol to a keyword if it is a reserved word in Lua"
|
"Convert a symbol to a keyword if it is a reserved word in Lua"
|
||||||
(if (or-eqv? token '(return function end if then elseif else true false nil or and do while repeat until local for break in not))
|
(if (memq token '(return function end if then elseif else true false nil or and do while repeat until local for break in not))
|
||||||
(symbol->keyword token)
|
(symbol->keyword token)
|
||||||
token))
|
token))
|
||||||
|
|
||||||
|
|
|
@ -121,7 +121,7 @@
|
||||||
|
|
||||||
(define (end-of-chunk? token)
|
(define (end-of-chunk? token)
|
||||||
"Returns true if TOKEN denotes the end of a grammatical chunk."
|
"Returns true if TOKEN denotes the end of a grammatical chunk."
|
||||||
(or (or-eqv? token #:else #:elseif #:end #:until) (eof-object? token)))
|
(or (memq token '(#:else #:elseif #:end #:until)) (eof-object? token)))
|
||||||
|
|
||||||
(define (token/type t)
|
(define (token/type t)
|
||||||
(cond ((number? t) 'NUMBER)
|
(cond ((number? t) 'NUMBER)
|
||||||
|
@ -138,11 +138,11 @@
|
||||||
;; infix operator parsing
|
;; infix operator parsing
|
||||||
(define (binary-operator? t)
|
(define (binary-operator? t)
|
||||||
"Return #t if the token may be a binary operator"
|
"Return #t if the token may be a binary operator"
|
||||||
(or-eqv? t #\+ #\* #\/ #\- #\^ #\< #\> #:== #:~= #:and #:or #:concat))
|
(memv t '(#\+ #\* #\/ #\- #\^ #\< #\> #:== #:~= #:and #:or #:concat)))
|
||||||
|
|
||||||
(define (unary-operator? t)
|
(define (unary-operator? t)
|
||||||
"Return #t if the token may be a unary operator"
|
"Return #t if the token may be a unary operator"
|
||||||
(or-eqv? t #\- #\# #:not))
|
(memv t '(#\- #\# #:not)))
|
||||||
|
|
||||||
;; Operator precedence
|
;; Operator precedence
|
||||||
(define *unary-priority* 80)
|
(define *unary-priority* 80)
|
||||||
|
@ -817,7 +817,7 @@
|
||||||
(lookahead!)
|
(lookahead!)
|
||||||
(if (eq? token2 #:=)
|
(if (eq? token2 #:=)
|
||||||
(numeric-for src name)
|
(numeric-for src name)
|
||||||
(if (or-eqv? token2 #:in #\,)
|
(if (memv token2 '(#:in #\,))
|
||||||
(list-for src name)
|
(list-for src name)
|
||||||
(syntax-error src "expected = or in after for variable"))))))
|
(syntax-error src "expected = or in after for variable"))))))
|
||||||
result))
|
result))
|
||||||
|
|
|
@ -500,7 +500,7 @@
|
||||||
(lambda* (e #:optional (base 10))
|
(lambda* (e #:optional (base 10))
|
||||||
(cond ((number? e) e)
|
(cond ((number? e) e)
|
||||||
((string? e)
|
((string? e)
|
||||||
(unless (or-eqv? base 2 8 10 16)
|
(unless (memv base '(2 8 10 16))
|
||||||
(runtime-warning "tonumber cannot respect bases other than 2, 8, 10, and 16"))
|
(runtime-warning "tonumber cannot respect bases other than 2, 8, 10, and 16"))
|
||||||
(string->number e base))
|
(string->number e base))
|
||||||
(else #nil))))
|
(else #nil))))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue