mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-20 11:40:18 +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:
|
||||
|
||||
(define-module (language lua common)
|
||||
|
||||
#:use-module (ice-9 format)
|
||||
|
||||
#:export (syntax-error or-eqv?))
|
||||
#:export (syntax-error))
|
||||
|
||||
(define (syntax-error src string . args)
|
||||
"Throw an error tagged with 'syntax-error, and print detailed source
|
||||
code information when available. STRING and ARGS are given to FORMAT."
|
||||
(throw 'syntax-error #f (apply format #f string args)
|
||||
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
|
||||
;; for instance
|
||||
((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"))
|
||||
(make-application src (make-module-ref src '(guile) 'throw #t) (list (make-const src 'lua-break)))
|
||||
)
|
||||
|
|
|
@ -58,7 +58,7 @@
|
|||
|
||||
(define (possible-keyword token)
|
||||
"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)
|
||||
token))
|
||||
|
||||
|
|
|
@ -121,7 +121,7 @@
|
|||
|
||||
(define (end-of-chunk? token)
|
||||
"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)
|
||||
(cond ((number? t) 'NUMBER)
|
||||
|
@ -138,11 +138,11 @@
|
|||
;; infix operator parsing
|
||||
(define (binary-operator? t)
|
||||
"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)
|
||||
"Return #t if the token may be a unary operator"
|
||||
(or-eqv? t #\- #\# #:not))
|
||||
(memv t '(#\- #\# #:not)))
|
||||
|
||||
;; Operator precedence
|
||||
(define *unary-priority* 80)
|
||||
|
@ -817,7 +817,7 @@
|
|||
(lookahead!)
|
||||
(if (eq? token2 #:=)
|
||||
(numeric-for src name)
|
||||
(if (or-eqv? token2 #:in #\,)
|
||||
(if (memv token2 '(#:in #\,))
|
||||
(list-for src name)
|
||||
(syntax-error src "expected = or in after for variable"))))))
|
||||
result))
|
||||
|
|
|
@ -500,7 +500,7 @@
|
|||
(lambda* (e #:optional (base 10))
|
||||
(cond ((number? e) 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"))
|
||||
(string->number e base))
|
||||
(else #nil))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue