aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorLars Ingebrigtsen2019-06-19 13:47:22 +0200
committerLars Ingebrigtsen2019-06-19 13:48:49 +0200
commit390b4bc1e25fe691548d7ec982eb2f7027fe26a3 (patch)
tree3355d4c19e87fbe9814339a7f82cb30bd458fadd /lisp
parenteef48e124da251605ea05579aac196f2f8e2f534 (diff)
downloademacs-390b4bc1e25fe691548d7ec982eb2f7027fe26a3.tar.gz
emacs-390b4bc1e25fe691548d7ec982eb2f7027fe26a3.zip
Allow specifying the expected number of shift/reduce conflicts
* admin/grammars/grammar.wy: Add %expectedconflicts. * lisp/cedet/semantic/grammar-wy.el (semantic-grammar-wy--keyword-table): Ditto. * lisp/cedet/semantic/grammar.el (semantic-grammar-expected-conflicts): New function. (semantic-grammar-insert-defconst-with-eval): New function. (semantic-grammar-create-package): Output the number of expected shift/reduce conflicts. * lisp/cedet/semantic/wisent/comp.el (wisent-total-conflicts): Don't output the warning if the number of shift/reduce conflicts is expected. (wisent-expected-conflicts): Made obsolete.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/cedet/semantic/grammar-wy.el9
-rw-r--r--lisp/cedet/semantic/grammar.el20
-rw-r--r--lisp/cedet/semantic/wisent/comp.el36
3 files changed, 49 insertions, 16 deletions
diff --git a/lisp/cedet/semantic/grammar-wy.el b/lisp/cedet/semantic/grammar-wy.el
index cc5942fa323..b5066d3d27b 100644
--- a/lisp/cedet/semantic/grammar-wy.el
+++ b/lisp/cedet/semantic/grammar-wy.el
@@ -41,6 +41,7 @@
41 '(("%default-prec" . DEFAULT-PREC) 41 '(("%default-prec" . DEFAULT-PREC)
42 ("%no-default-prec" . NO-DEFAULT-PREC) 42 ("%no-default-prec" . NO-DEFAULT-PREC)
43 ("%keyword" . KEYWORD) 43 ("%keyword" . KEYWORD)
44 ("%expectedconflicts" . EXPECTEDCONFLICTS)
44 ("%languagemode" . LANGUAGEMODE) 45 ("%languagemode" . LANGUAGEMODE)
45 ("%left" . LEFT) 46 ("%left" . LEFT)
46 ("%nonassoc" . NONASSOC) 47 ("%nonassoc" . NONASSOC)
@@ -110,7 +111,7 @@
110 (eval-when-compile 111 (eval-when-compile
111 (require 'semantic/wisent/comp)) 112 (require 'semantic/wisent/comp))
112 (wisent-compile-grammar 113 (wisent-compile-grammar
113 '((DEFAULT-PREC NO-DEFAULT-PREC KEYWORD LANGUAGEMODE LEFT NONASSOC PACKAGE PROVIDE PREC PUT QUOTEMODE RIGHT SCOPESTART START TOKEN TYPE USE-MACROS STRING SYMBOL PERCENT_PERCENT CHARACTER PREFIXED_LIST SEXP PROLOGUE EPILOGUE PAREN_BLOCK BRACE_BLOCK LPAREN RPAREN LBRACE RBRACE COLON SEMI OR LT GT) 114 '((DEFAULT-PREC NO-DEFAULT-PREC KEYWORD LANGUAGEMODE EXPECTEDCONFLICTS LEFT NONASSOC PACKAGE PROVIDE PREC PUT QUOTEMODE RIGHT SCOPESTART START TOKEN TYPE USE-MACROS STRING SYMBOL PERCENT_PERCENT CHARACTER PREFIXED_LIST SEXP PROLOGUE EPILOGUE PAREN_BLOCK BRACE_BLOCK LPAREN RPAREN LBRACE RBRACE COLON SEMI OR LT GT)
114 nil 115 nil
115 (grammar 116 (grammar
116 ((prologue)) 117 ((prologue))
@@ -133,6 +134,7 @@
133 ((default_prec_decl)) 134 ((default_prec_decl))
134 ((no_default_prec_decl)) 135 ((no_default_prec_decl))
135 ((languagemode_decl)) 136 ((languagemode_decl))
137 ((expectedconflicts_decl))
136 ((package_decl)) 138 ((package_decl))
137 ((provide_decl)) 139 ((provide_decl))
138 ((precedence_decl)) 140 ((precedence_decl))
@@ -159,6 +161,11 @@
159 `(wisent-raw-tag 161 `(wisent-raw-tag
160 (semantic-tag ',(car $2) 162 (semantic-tag ',(car $2)
161 'languagemode :rest ',(cdr $2))))) 163 'languagemode :rest ',(cdr $2)))))
164 (expectedconflicts_decl
165 ((EXPECTEDCONFLICTS symbols)
166 `(wisent-raw-tag
167 (semantic-tag ',(car $2)
168 'expectedconflicts :rest ',(cdr $2)))))
162 (package_decl 169 (package_decl
163 ((PACKAGE SYMBOL) 170 ((PACKAGE SYMBOL)
164 `(wisent-raw-tag 171 `(wisent-raw-tag
diff --git a/lisp/cedet/semantic/grammar.el b/lisp/cedet/semantic/grammar.el
index 8ffa4c6d83e..3c35583dd3c 100644
--- a/lisp/cedet/semantic/grammar.el
+++ b/lisp/cedet/semantic/grammar.el
@@ -277,6 +277,10 @@ foo.by it is foo-by."
277 (i (string-match (format "\\([.]\\)%s\\'" ext) file))) 277 (i (string-match (format "\\([.]\\)%s\\'" ext) file)))
278 (concat (substring file 0 i) "-" ext)))) 278 (concat (substring file 0 i) "-" ext))))
279 279
280(defun semantic-grammar-expected-conflicts ()
281 "Return the number of expected shift/reduce conflicts in the package."
282 (semantic-grammar-tag-symbols 'expectedconflicts))
283
280(defsubst semantic-grammar-languagemode () 284(defsubst semantic-grammar-languagemode ()
281 "Return the %languagemode value as a list of symbols or nil." 285 "Return the %languagemode value as a list of symbols or nil."
282 (semantic-grammar-tag-symbols 'languagemode)) 286 (semantic-grammar-tag-symbols 'languagemode))
@@ -533,6 +537,14 @@ Also load the specified macro libraries."
533 (goto-char start) 537 (goto-char start)
534 (indent-sexp)))) 538 (indent-sexp))))
535 539
540(defun semantic-grammar-insert-defconst-with-eval (name value docstring)
541 "Insert declaration of constant NAME with VALUE and DOCSTRING."
542 (let ((start (point)))
543 (insert (format "(eval-and-compile (defconst %s\n%s%S))\n\n" name value docstring))
544 (save-excursion
545 (goto-char start)
546 (indent-sexp))))
547
536(defun semantic-grammar-insert-defun (name body docstring) 548(defun semantic-grammar-insert-defun (name body docstring)
537 "Insert declaration of function NAME with BODY and DOCSTRING." 549 "Insert declaration of function NAME with BODY and DOCSTRING."
538 (let ((start (point))) 550 (let ((start (point)))
@@ -890,6 +902,12 @@ Lisp code."
890 902
891 (insert " \n;;; Declarations\n;;\n") 903 (insert " \n;;; Declarations\n;;\n")
892 904
905 (semantic-grammar-insert-defconst-with-eval
906 (concat semantic--grammar-package "--expected-conflicts")
907 (with-current-buffer semantic--grammar-input-buffer
908 (format "%s\n" (car (semantic-grammar-expected-conflicts))))
909 "The number of expected shift/reduce conflicts in this grammar.")
910
893 ;; `eval-defun' is not necessary to reset `defconst' values. 911 ;; `eval-defun' is not necessary to reset `defconst' values.
894 (semantic-grammar-insert-defconst 912 (semantic-grammar-insert-defconst
895 (semantic-grammar-keywordtable) 913 (semantic-grammar-keywordtable)
@@ -987,7 +1005,7 @@ Return non-nil if there were no errors, nil if errors."
987 (vc-handled-backends nil)) 1005 (vc-handled-backends nil))
988 (setq semanticdb-new-database-class 'semanticdb-project-database) 1006 (setq semanticdb-new-database-class 'semanticdb-project-database)
989 (semantic-mode 1) 1007 (semantic-mode 1)
990 (semantic-grammar-create-package))) 1008 (semantic-grammar-create-package t)))
991 (error 1009 (error
992 (message "%s" (error-message-string err)) 1010 (message "%s" (error-message-string err))
993 nil)))) 1011 nil))))
diff --git a/lisp/cedet/semantic/wisent/comp.el b/lisp/cedet/semantic/wisent/comp.el
index 051b898ed78..4e222fa70eb 100644
--- a/lisp/cedet/semantic/wisent/comp.el
+++ b/lisp/cedet/semantic/wisent/comp.el
@@ -2263,26 +2263,34 @@ warning is given if there are either more or fewer conflicts, or if
2263there are any reduce/reduce conflicts." 2263there are any reduce/reduce conflicts."
2264 :group 'wisent 2264 :group 'wisent
2265 :type '(choice (const nil) integer)) 2265 :type '(choice (const nil) integer))
2266(make-obsolete-variable 'wisent-expected-conflicts
2267 "use %expectedconflicts in the .wy file instead"
2268 "27.1")
2266 2269
2267(defun wisent-total-conflicts () 2270(defun wisent-total-conflicts ()
2268 "Report the total number of conflicts." 2271 "Report the total number of conflicts."
2269 (unless (and (zerop rrc-total) 2272 (let* ((src (wisent-source))
2270 (or (zerop src-total) 2273 (symbol (intern (format "wisent-%s--expected-conflicts"
2271 (= src-total (or wisent-expected-conflicts 0)))) 2274 (replace-regexp-in-string "\\.el$" "" src))
2272 (let* ((src (wisent-source)) 2275 obarray)))
2273 (src (if src (concat " in " src) "")) 2276 (when (or (not (zerop rrc-total))
2274 (msg (format "Grammar%s contains" src))) 2277 (and (not (zerop src-total))
2275 (if (> src-total 0) 2278 (not (= src-total (or wisent-expected-conflicts 0)))
2279 (or (not (boundp symbol))
2280 (not (equal (symbol-value symbol) src-total)))))
2281 (let* ((src (if src (concat " in " src) ""))
2282 (msg (format "Grammar%s contains" src)))
2283 (when (and (> src-total 0))
2276 (setq msg (format "%s %d shift/reduce conflict%s" 2284 (setq msg (format "%s %d shift/reduce conflict%s"
2277 msg src-total (if (> src-total 1) 2285 msg src-total (if (> src-total 1)
2278 "s" "")))) 2286 "s" ""))))
2279 (if (and (> src-total 0) (> rrc-total 0)) 2287 (if (and (> src-total 0) (> rrc-total 0))
2280 (setq msg (format "%s and" msg))) 2288 (setq msg (format "%s and" msg)))
2281 (if (> rrc-total 0) 2289 (if (> rrc-total 0)
2282 (setq msg (format "%s %d reduce/reduce conflict%s" 2290 (setq msg (format "%s %d reduce/reduce conflict%s"
2283 msg rrc-total (if (> rrc-total 1) 2291 msg rrc-total (if (> rrc-total 1)
2284 "s" "")))) 2292 "s" ""))))
2285 (message msg)))) 2293 (message msg)))))
2286 2294
2287(defun wisent-print-conflicts () 2295(defun wisent-print-conflicts ()
2288 "Report conflicts." 2296 "Report conflicts."