;;; wisi-parse.el --- Wisi parser
-;; Copyright (C) 2013 Free Software Foundation, Inc.
+;; Copyright (C) 2013, 2014 Free Software Foundation, Inc.
;; This file is part of GNU Emacs.
;;; Code:
+(require 'cl-lib)
(require 'semantic/wisent)
-(eval-when-compile (require 'cl-lib))
(cl-defstruct (wisi-parser-state
(:copier nil))
If a file needs more than this, it's probably an indication that
the grammar is excessively redundant.")
-(defvar wisi-debug)
+(defvar wisi-parse-max-parallel-current (cons 0 0)
+ "Cons (count . point); Maximum number of parallel parsers used in most recent parse,
+point at which that max was spawned.")
+
+(defvar wisi-debug 0
+ "wisi debug mode:
+0 : normal - ignore parse errors, for indenting new code
+1 : report parse errors (for running tests)
+2 : show parse states, position point at parse errors, debug-on-error works in parser
+3 : also show top 10 items of parser stack.")
(defun wisi-parse (automaton lexer)
"Parse input using the automaton specified in AUTOMATON.
:label 0
:active 'shift
:stack (make-vector wisent-parse-max-stack-size nil)
- ;; FIXME: better error message when stack overflows, so
- ;; user can set wisent-parse-max-stack-size in file-local
- ;; vars.
:sp 0
:pending nil)))
(active-parser-count 1)
(token (funcall lexer))
some-pending)
+ (setq wisi-parse-max-parallel-current (cons 0 0))
+
(aset (wisi-parser-state-stack (aref parser-states 0)) 0 0) ;; Initial state
(while (not (eq active 'accept))
)))
)
(setq active-parser-count (1+ active-parser-count))
+ (when (> active-parser-count (car wisi-parse-max-parallel-current))
+ (setq wisi-parse-max-parallel-current (cons active-parser-count (point))))
(setf (wisi-parser-state-label result) j)
(aset parser-states j result))
(when (> wisi-debug 1)
(defun wisi-execute-pending (pending)
(while pending
(when (> wisi-debug 1) (message "%s" (car pending)))
- (apply (pop pending))))
+
+ (cond
+ ((and (>= emacs-major-version 24)
+ (>= emacs-minor-version 3))
+ (apply (pop pending)))
+
+ (t
+ (let ((func-args (pop pending)))
+ (apply (car func-args) (cdr func-args))))
+ )))
(defun wisi-parse-1 (token parser-state pendingp actions gotos)
"Perform one shift or reduce on PARSER-STATE.