X-Git-Url: https://git.distorted.org.uk/~mdw/sod/blobdiff_plain/288c7651d95b3d75af6d38d8ed40e87d63886b4f..0ee8826a7359b1e1d2e594ca6bf429cb18494042:/src/pset-parse.lisp diff --git a/src/pset-parse.lisp b/src/pset-parse.lisp index 7091016..0f3e482 100644 --- a/src/pset-parse.lisp +++ b/src/pset-parse.lisp @@ -28,26 +28,8 @@ ;;;-------------------------------------------------------------------------- ;;; The expression parser. -(flet ((dispatch (name args &rest spec) - (acond ((find :invalid args :key #'car) - (cons :invalid nil)) - ((find-if (lambda (item) - (every (lambda (type arg) - (eql type (car arg))) - (cddr item) - args)) - spec) - (cons (car it) (apply (cadr it) - (mapcar #'cdr args)))) - (t - (cerror* "Type mismatch: operator `~A' applied to ~ - types ~{~(~A~)~#[~; and ~;, ~]~}" - name - (mapcar #'car args)) - (cons :invalid nil))))) - - (defun parse-expression (scanner) - "Parse and evaluate a simple expression. +(defun parse-expression (scanner) + "Parse and evaluate a simple expression. The result is a pair (TYPE . VALUE). Currently, type types are `:id', `:int', `:string', `:char', `:fragment', `:type'. If an error prevented a @@ -63,6 +45,25 @@ | `<' declspec+ declarator[empty] `>' | `?' lisp-expression Only operators for dealing with integers are provided." + + (flet ((dispatch (name args &rest spec) + (acond ((find :invalid args :key #'car) + (cons :invalid nil)) + ((find-if (lambda (item) + (every (lambda (type arg) + (eql type (car arg))) + (cddr item) + args)) + spec) + (cons (car it) (apply (cadr it) + (mapcar #'cdr args)))) + (t + (cerror* "Type mismatch: operator `~A' applied to ~ + types ~{~(~A~)~#[~; and ~;, ~]~}" + name + (mapcar #'car args)) + (cons :invalid nil))))) + (with-parser-context (token-scanner-context :scanner scanner) (parse (expr (:nestedp nestedp) (lisp (flet ((prop (type value)