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
(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
(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)
(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)))
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
(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)))
(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)
"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))))
(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)