X-Git-Url: https://code.delx.au/gnu-emacs-elpa/blobdiff_plain/7507951dd0aea01dcf22ee1d6592bdf917b0f2c5..f10533854f4c7bb54247a11981191bf37b70cb36:/packages/wisi/wisi-parse.el diff --git a/packages/wisi/wisi-parse.el b/packages/wisi/wisi-parse.el index 4fa300e6d..a16a81d72 100644 --- a/packages/wisi/wisi-parse.el +++ b/packages/wisi/wisi-parse.el @@ -111,6 +111,9 @@ point at which that max was spawned.") list (symbol text start . end), where `symbol' is the terminal symbol, `text' is the token string, `start . end' is the range in the buffer." + + ;; FIXME: (aref automaton 3) is the obarray storing the semantic actions; + ;; not used here (see related FIXME in wisi-compile) (let* ((actions (aref automaton 0)) (gotos (aref automaton 1)) (parser-states ;; vector of parallel parser states @@ -148,8 +151,8 @@ point at which that max was spawned.") (let ((state (aref (wisi-parser-state-stack parser-state) (wisi-parser-state-sp parser-state)))) (wisi-error-msg (concat "too many parallel parsers required in grammar state %d;" - " simplify grammar, or increase `wisi-parse-max-parallel'" - state))))) + " simplify grammar, or increase `wisi-parse-max-parallel'") + state)))) (let ((j (wisi-free-parser parser-states))) (cond @@ -266,20 +269,20 @@ point at which that max was spawned.") (defun wisi-parsers-active (parser-states active-count) "Return the type of parser cycle to execute. PARSER-STATES[*].active is the last action a parser took. If it -was 'shift, that parser used the input token, and should not be +was `shift', that parser used the input token, and should not be executed again until another input token is available, after all parsers have shifted the current token or terminated. Returns one of: -'accept : all PARSER-STATES have active set to nil or 'accept - +`accept' : all PARSER-STATES have active set to nil or `accept' - done parsing -'shift : all PARSER-STATES have active set to nil, 'accept, or -'shift - get a new token, execute 'shift parsers. +`shift' : all PARSER-STATES have active set to nil, `accept', or +`shift' - get a new token, execute `shift' parsers. -'reduce : some PARSER-STATES have active set to 'reduce - no new -token, execute 'reduce parsers." +`reduce' : some PARSER-STATES have active set to `reduce' - no new +token, execute `reduce' parsers." (let ((result nil) (i 0) (shift-count 0) @@ -333,7 +336,7 @@ token, execute 'reduce parsers." (defun wisi-parse-elim-identical (parser-states active-parser-count) "Check for parsers in PARSER-STATES that have reached identical states eliminate one. Return new ACTIVE-PARSER-COUNT. Assumes all parsers have active -nil, 'shift, or 'accept." +nil, `shift', or `accept'." ;; parser-states passed by reference; active-parser-count by copy ;; see test/ada_mode-slices.adb for example (dotimes (parser-i (1- (length parser-states))) @@ -381,7 +384,7 @@ nil, 'shift, or 'accept." result) ) -(defun wisi-parse-exec-action (func tokens) +(defun wisi-parse-exec-action (func nonterm tokens) "Execute action if all tokens past wisi-cache-max." ;; We don't execute actions if all tokens are before wisi-cache-max, ;; because later actions can update existing caches, and if the @@ -392,7 +395,7 @@ nil, 'shift, or 'accept." (if (< 0 (length tokens)) (if (>= (wisi-parse-max-pos tokens) wisi-cache-max) - (funcall func tokens) + (funcall func nonterm tokens) (when (> wisi-debug 1) (message "... action skipped; before wisi-cache-max %d" wisi-cache-max))) @@ -407,7 +410,7 @@ nil, 'shift, or 'accept." (when (> wisi-debug 1) (message "%s" (car pending))) (let ((func-args (pop pending))) - (wisi-parse-exec-action (car func-args) (cadr func-args))) + (wisi-parse-exec-action (nth 0 func-args) (nth 1 func-args) (cl-caddr func-args))) )) (defun wisi-parse-1 (token parser-state pendingp actions gotos) @@ -508,7 +511,7 @@ the first and last tokens of the nonterminal." "Reduce PARSER-STATE.stack, and execute or pend ACTION." (let* ((stack (wisi-parser-state-stack parser-state)); reference (sp (wisi-parser-state-sp parser-state)); copy - (token-count (or (nth 2 action) 0)) + (token-count (nth 2 action)) (nonterm (nth 0 action)) (nonterm-region (when (> token-count 0) (wisi-nonterm-bounds stack (- sp (* 2 (1- token-count)) 1) (1- sp)))) @@ -519,25 +522,29 @@ the first and last tokens of the nonterminal." (when (not new-state) (error "no goto for %s %d" nonterm post-reduce-state)) - (dotimes (i token-count) - (aset tokens (- token-count i 1) (aref stack (- sp (* 2 i) 1)))) + (when (nth 1 action) + ;; don't need wisi-tokens for a null user action + (dotimes (i token-count) + (aset tokens (- token-count i 1) (aref stack (- sp (* 2 i) 1))))) (setq sp (+ 2 (- sp (* 2 token-count)))) (aset stack (1- sp) (cons nonterm nonterm-region)) (aset stack sp new-state) (setf (wisi-parser-state-sp parser-state) sp) - (if pendingp - (if (wisi-parser-state-pending parser-state) + (when (nth 1 action) + ;; nothing to do for a null user action + (if pendingp + (if (wisi-parser-state-pending parser-state) + (setf (wisi-parser-state-pending parser-state) + (append (wisi-parser-state-pending parser-state) + (list (list (nth 1 action) nonterm tokens)))) (setf (wisi-parser-state-pending parser-state) - (append (wisi-parser-state-pending parser-state) - (list (list (nth 1 action) tokens)))) - (setf (wisi-parser-state-pending parser-state) - (list (list (nth 1 action) tokens)))) - - ;; Not pending. - (wisi-parse-exec-action (nth 1 action) tokens) - ) + (list (list (nth 1 action) nonterm tokens)))) + + ;; Not pending. + (wisi-parse-exec-action (nth 1 action) nonterm tokens) + )) )) (provide 'wisi-parse)