Reorder parsing so calls get properly parsed inside expressions

This commit is contained in:
John Lorentzson 2025-06-21 21:04:26 +02:00
parent 4011e3b0db
commit 2c529c368a

View file

@ -105,27 +105,7 @@ parser's debug output.")
left)) left))
(define-syntax-matcher expression () (define-syntax-matcher expression ()
(match-syntax call)) (match-syntax equality))
(define-syntax-matcher arglist (arguments)
(setf arguments (list (match-syntax expression)))
(loop :while (match-token 'token-comma)
:do (push (match-syntax expression) arguments))
(nreverse arguments))
(define-syntax-matcher call (name arguments)
(setf name (match-syntax equality))
(cond ((and (typep name 'token-name)
(match-token 'token-open-paren))
(setf arguments (match-syntax arglist))
(consume-token 'token-close-paren
"Close parenthesis ')' is required to end function call argument list.")
(make-instance 'node-call
:source *syntax-source*
:comment *token-comment*
:callee (transform name 'asm-function)
:arguments arguments))
(t name)))
(define-binary-expr-matcher equality comparison (define-binary-expr-matcher equality comparison
(token-equal-equal node-expr-test-equal) (token-equal-equal node-expr-test-equal)
@ -153,7 +133,27 @@ parser's debug output.")
:comment *token-comment* :comment *token-comment*
:operator-token (previous-token) :operator-token (previous-token)
:operand (match-syntax primary)) :operand (match-syntax primary))
(match-syntax primary)))) (match-syntax call))))
(define-syntax-matcher arglist (arguments)
(setf arguments (list (match-syntax expression)))
(loop :while (match-token 'token-comma)
:do (push (match-syntax expression) arguments))
(nreverse arguments))
(define-syntax-matcher call (name arguments)
(setf name (match-syntax primary))
(cond ((and (typep name 'token-name)
(match-token 'token-open-paren))
(setf arguments (match-syntax arglist))
(consume-token 'token-close-paren
"Close parenthesis ')' is required to end function call argument list.")
(make-instance 'node-call
:source *syntax-source*
:comment *token-comment*
:callee (transform name 'asm-function)
:arguments arguments))
(t name)))
(define-syntax-matcher primary () (define-syntax-matcher primary ()
(cond ((or (match-token 'token-name) (cond ((or (match-token 'token-name)