Hi Eric,
[...]
> Yes, I can imagine just a few:
>
> %type <symbol>
> %type <punctuation>
>
> to build a default analyzer.
Following is a new patch that implements your suggestion above ;-)
I also modified the Java grammars to use the default values of the
well known token types <block>, <punctuation>, <symbol>, <string>,
<number> and <keyword>.
So now, for "standard" cases it is very easy to auto-generate the
basic type analyzers :-)
Finally, I added an optional argument `force' to the command
`semantic-grammar-create-package', to unconditionally re-generate
Lisp code from the grammar. It is very useful to test generation
without modifying the grammar, by typing C-u C-c C-c.
If you don't have objections, I will commit the changes.
Here is the change log:
* cedet/semantic/wisent/wisent-java.wy
(<block>, <punctuation>, <symbol>, <string>)
(<number>, <keyword>): Use default values in %type declarations.
* cedet/semantic/wisent/wisent-java-tags.wy
(<block>, <punctuation>, <symbol>, <string>)
(<number>, <keyword>): Use default values in %type declarations.
* cedet/semantic/semantic-grammar.el
(semantic-grammar-token-%type-properties): Remember types
explicitly declared with a %type statement.
(semantic-grammar-insert-defanalyzer): Generate analyzer for
explicitly declared types.
(semantic-grammar-create-package): Add optional argument force to
unconditionally re-generate Lisp code.
* cedet/semantic/semantic-grammar-wy.el
Re-generated.
* cedet/semantic/semantic-grammar.wy
(plist_opt): New rule.
(type_decl): Use it.
* cedet/semantic/semantic-lex.el
(semantic-lex-preset-default-types): New function.
(semantic-lex-make-type-table): Use it.
Enjoy!
David
Index: semantic/semantic-grammar-wy.el
===================================================================
RCS file: /cvsroot/cedet/cedet/semantic/semantic-grammar-wy.el,v
retrieving revision 1.9
diff -c -r1.9 semantic-grammar-wy.el
*** semantic/semantic-grammar-wy.el 14 Jan 2004 09:54:24 -0000 1.9
--- semantic/semantic-grammar-wy.el 18 Jan 2004 09:55:37 -0000
***************
*** 3,11 ****
;; Copyright (C) 2002, 2003, 2004 David Ponce
;; Author: David Ponce <david@...>
! ;; Created: 2004-01-14 10:33:53+0100
;; Keywords: syntax
! ;; X-RCS: $Id: semantic-grammar-wy.el,v 1.9 2004/01/14 09:54:24 ponced Exp $
;; This file is not part of GNU Emacs.
;;
--- 3,11 ----
;; Copyright (C) 2002, 2003, 2004 David Ponce
;; Author: David Ponce <david@...>
! ;; Created: 2004-01-18 10:52:15+0100
;; Keywords: syntax
! ;; X-RCS: $Id$
;; This file is not part of GNU Emacs.
;;
***************
*** 258,266 ****
((LT SYMBOL GT)
(progn $2)))
(type_decl
! ((TYPE token_type plist)
`(wisent-raw-tag
(semantic-tag ',$2 'type :value ',$3))))
(plist
((plist put_value)
(append
--- 258,269 ----
((LT SYMBOL GT)
(progn $2)))
(type_decl
! ((TYPE token_type plist_opt)
`(wisent-raw-tag
(semantic-tag ',$2 'type :value ',$3))))
+ (plist_opt
+ (nil)
+ ((plist)))
(plist
((plist put_value)
(append
Index: semantic/semantic-grammar.el
===================================================================
RCS file: /cvsroot/cedet/cedet/semantic/semantic-grammar.el,v
retrieving revision 1.52
diff -c -r1.52 semantic-grammar.el
*** semantic/semantic-grammar.el 16 Jan 2004 15:43:18 -0000 1.52
--- semantic/semantic-grammar.el 18 Jan 2004 09:55:38 -0000
***************
*** 438,443 ****
--- 438,445 ----
(let (type)
(dolist (tag (semantic-find-tags-by-class 'type (current-buffer)))
(setq type (semantic-tag-name tag))
+ ;; Indicate to auto-generate the analyzer for this type
+ (push (list type :declared t) props)
(dolist (e (semantic-tag-get-attribute tag :value))
(push (list type (intern (car e)) (read (or (cdr e) "nil")))
props)))
***************
*** 796,805 ****
(let* ((type-name (symbol-name type))
(type-value (symbol-value type))
(syntax (get type 'syntax))
spec mtype prefix name doc)
! ;; Generate an analyzer if at least syntactic/lexical matches are
! ;; provided.
! (when syntax
(setq prefix (file-name-sans-extension
(semantic-grammar-buffer-file
semantic--grammar-output-buffer))
--- 798,809 ----
(let* ((type-name (symbol-name type))
(type-value (symbol-value type))
(syntax (get type 'syntax))
+ (declared (get type :declared))
spec mtype prefix name doc)
! ;; Generate an analyzer if the corresponding type has been
! ;; explicitly declared in a %type statement, and if at least the
! ;; syntax property has been provided.
! (when (and declared syntax)
(setq prefix (file-name-sans-extension
(semantic-grammar-buffer-file
semantic--grammar-output-buffer))
***************
*** 873,881 ****
(noninteractive)
noninteractive))
! (defun semantic-grammar-create-package ()
! "Create package Lisp code from grammar in current buffer."
! (interactive)
(semantic-bovinate-toplevel t)
(let* (
;; Values of the following local variables are obtained from
--- 877,889 ----
(noninteractive)
noninteractive))
! (defun semantic-grammar-create-package (&optional force)
! "Create package Lisp code from grammar in current buffer.
! Does nothing if the Lisp code seems up to date.
! If optional argument FORCE is non-nil, unconditionally re-generate the
! Lisp code."
! (interactive "P")
! (setq force (or force current-prefix-arg))
(semantic-bovinate-toplevel t)
(let* (
;; Values of the following local variables are obtained from
***************
*** 890,896 ****
(epilogue (semantic-grammar-epilogue))
(footer (semantic-grammar-footer))
)
! (if (and (not (buffer-modified-p))
(file-newer-than-file-p
(buffer-file-name semantic--grammar-output-buffer)
(buffer-file-name semantic--grammar-input-buffer)))
--- 898,905 ----
(epilogue (semantic-grammar-epilogue))
(footer (semantic-grammar-footer))
)
! (if (and (not force)
! (not (buffer-modified-p))
(file-newer-than-file-p
(buffer-file-name semantic--grammar-output-buffer)
(buffer-file-name semantic--grammar-input-buffer)))
Index: semantic/semantic-grammar.wy
===================================================================
RCS file: /cvsroot/cedet/cedet/semantic/semantic-grammar.wy,v
retrieving revision 1.12
diff -c -r1.12 semantic-grammar.wy
*** semantic/semantic-grammar.wy 14 Jan 2004 09:53:56 -0000 1.12
--- semantic/semantic-grammar.wy 18 Jan 2004 09:55:38 -0000
***************
*** 258,267 ****
;
type_decl:
! TYPE token_type plist
`(TAG ',$2 'type :value ',$3)
;
plist:
plist put_value
(append (list $2) $1)
--- 258,272 ----
;
type_decl:
! TYPE token_type plist_opt
`(TAG ',$2 'type :value ',$3)
;
+ plist_opt:
+ ;;EMPTY
+ | plist
+ ;
+
plist:
plist put_value
(append (list $2) $1)
Index: semantic/semantic-lex.el
===================================================================
RCS file: /cvsroot/cedet/cedet/semantic/semantic-lex.el,v
retrieving revision 1.30
diff -c -r1.30 semantic-lex.el
*** semantic/semantic-lex.el 16 Jan 2004 08:56:43 -0000 1.30
--- semantic/semantic-lex.el 18 Jan 2004 09:55:39 -0000
***************
*** 26,32 ****
;; In semantic 1.x, the lexical analyzer was an all purpose routine.
;; To boost efficiency, the analyzer is now a series of routines that
;; are constructed at build time into a single routine. This will
! ;; eliminate uneeded if statements to speed the lexer.
(require 'semantic-fw)
;;; Code:
--- 26,32 ----
;; In semantic 1.x, the lexical analyzer was an all purpose routine.
;; To boost efficiency, the analyzer is now a series of routines that
;; are constructed at build time into a single routine. This will
! ;; eliminate unneeded if statements to speed the lexer.
(require 'semantic-fw)
;;; Code:
***************
*** 217,222 ****
--- 217,238 ----
(unless noerror
(semantic-lex-type-invalid type)))))
+ (defun semantic-lex-preset-default-types ()
+ "Install useful default properties for well known types."
+ (semantic-lex-type-put "punctuation" 'matchdatatype 'string t)
+ (semantic-lex-type-put "punctuation" 'syntax "\\s.\\|\\s$\\|\\s'")
+ (semantic-lex-type-put "keyword" 'matchdatatype 'keyword t)
+ (semantic-lex-type-put "keyword" 'syntax "\\(\\sw\\|\\s_\\)+")
+ (semantic-lex-type-put "symbol" 'matchdatatype 'regexp t)
+ (semantic-lex-type-put "symbol" 'syntax "\\(\\sw\\|\\s_\\)+")
+ (semantic-lex-type-put "string" 'matchdatatype 'sexp t)
+ (semantic-lex-type-put "string" 'syntax "\\s\"")
+ (semantic-lex-type-put "number" 'matchdatatype 'regexp t)
+ (semantic-lex-type-put "number" 'syntax 'semantic-lex-number-expression)
+ (semantic-lex-type-put "block" 'matchdatatype 'block t)
+ (semantic-lex-type-put "block" 'syntax "\\s(\\|\\s)")
+ )
+
(defun semantic-lex-make-type-table (specs &optional propspecs)
"Convert type SPECS into an obarray and return it.
SPECS must be a list of (TYPE . TOKENS) elements, where:
***************
*** 255,260 ****
--- 271,278 ----
(setq default token)))
;; Ensure the default matching spec is the first one.
(semantic-lex-type-set type (cons default (nreverse alist))))
+ ;; Install useful default types & properties
+ (semantic-lex-preset-default-types)
;; Apply all properties
(while propspecs
(setq spec (car propspecs)
Index: semantic/wisent/wisent-java-tags.wy
===================================================================
RCS file: /cvsroot/cedet/cedet/semantic/wisent/wisent-java-tags.wy,v
retrieving revision 1.12
diff -c -r1.12 wisent-java-tags.wy
*** semantic/wisent/wisent-java-tags.wy 16 Jan 2004 08:57:53 -0000 1.12
--- semantic/wisent/wisent-java-tags.wy 18 Jan 2004 09:55:41 -0000
***************
*** 49,55 ****
;; -----------------------------
;; Block & Parenthesis terminals
;; -----------------------------
! %type <block> syntax "\\s(\\|\\s)" matchdatatype block
%token <block> PAREN_BLOCK "(LPAREN RPAREN)"
%token <block> BRACE_BLOCK "(LBRACE RBRACE)"
--- 49,55 ----
;; -----------------------------
;; Block & Parenthesis terminals
;; -----------------------------
! %type <block> ;;syntax "\\s(\\|\\s)" matchdatatype block
%token <block> PAREN_BLOCK "(LPAREN RPAREN)"
%token <block> BRACE_BLOCK "(LBRACE RBRACE)"
***************
*** 65,71 ****
;; ------------------
;; Operator terminals
;; ------------------
! %type <punctuation> syntax "\\(\\s.\\|\\s$\\|\\s'\\)+" matchdatatype string
%token <punctuation> NOT "!"
%token <punctuation> NOTEQ "!="
--- 65,71 ----
;; ------------------
;; Operator terminals
;; ------------------
! %type <punctuation> ;;syntax "\\(\\s.\\|\\s$\\|\\s'\\)+" matchdatatype string
%token <punctuation> NOT "!"
%token <punctuation> NOTEQ "!="
***************
*** 111,123 ****
;; -----------------
;; Literal terminals
;; -----------------
! %type <symbol> syntax "\\(\\sw\\|\\s_\\)+"
%token <symbol> IDENTIFIER
! %type <string> syntax "\\s\"" matchdatatype sexp
%token <string> STRING_LITERAL
! %type <number> syntax semantic-lex-number-expression
%token <number> NUMBER_LITERAL
;; -----------------
--- 111,123 ----
;; -----------------
;; Literal terminals
;; -----------------
! %type <symbol> ;;syntax "\\(\\sw\\|\\s_\\)+"
%token <symbol> IDENTIFIER
! %type <string> ;;syntax "\\s\"" matchdatatype sexp
%token <string> STRING_LITERAL
! %type <number> ;;syntax semantic-lex-number-expression
%token <number> NUMBER_LITERAL
;; -----------------
***************
*** 125,131 ****
;; -----------------
;; Generate a keyword analyzer
! %type <keyword> syntax "\\(\\sw\\|\\s_\\)+" matchdatatype keyword
%keyword ABSTRACT "abstract"
%put ABSTRACT summary
--- 125,131 ----
;; -----------------
;; Generate a keyword analyzer
! %type <keyword> ;;syntax "\\(\\sw\\|\\s_\\)+" matchdatatype keyword
%keyword ABSTRACT "abstract"
%put ABSTRACT summary
Index: semantic/wisent/wisent-java.wy
===================================================================
RCS file: /cvsroot/cedet/cedet/semantic/wisent/wisent-java.wy,v
retrieving revision 1.14
diff -c -r1.14 wisent-java.wy
*** semantic/wisent/wisent-java.wy 16 Jan 2004 13:14:11 -0000 1.14
--- semantic/wisent/wisent-java.wy 18 Jan 2004 09:55:41 -0000
***************
*** 46,52 ****
;; -----------------------------
;; Block & Parenthesis terminals
;; -----------------------------
! %type <block> syntax "\\s(\\|\\s)" matchdatatype block
%token <block> PAREN_BLOCK "(LPAREN RPAREN)"
%token <block> BRACE_BLOCK "(LBRACE RBRACE)"
--- 46,52 ----
;; -----------------------------
;; Block & Parenthesis terminals
;; -----------------------------
! %type <block> ;;syntax "\\s(\\|\\s)" matchdatatype block
%token <block> PAREN_BLOCK "(LPAREN RPAREN)"
%token <block> BRACE_BLOCK "(LBRACE RBRACE)"
***************
*** 62,68 ****
;; ------------------
;; Operator terminals
;; ------------------
! %type <punctuation> syntax "\\(\\s.\\|\\s$\\|\\s'\\)+" matchdatatype string
%token <punctuation> NOT "!"
%token <punctuation> NOTEQ "!="
--- 62,68 ----
;; ------------------
;; Operator terminals
;; ------------------
! %type <punctuation> ;;syntax "\\(\\s.\\|\\s$\\|\\s'\\)+" matchdatatype string
%token <punctuation> NOT "!"
%token <punctuation> NOTEQ "!="
***************
*** 108,130 ****
;; -----------------
;; Literal terminals
;; -----------------
! %type <symbol> syntax "\\(\\sw\\|\\s_\\)+"
%token <symbol> NULL_LITERAL "\\`null\\'"
%token <symbol> BOOLEAN_LITERAL "\\`false\\'"
%token <symbol> BOOLEAN_LITERAL "\\`true\\'"
%token <symbol> IDENTIFIER
! %type <string> syntax "\\s\"" matchdatatype sexp
%token <string> STRING_LITERAL
! %type <number> syntax semantic-lex-number-expression
%token <number> NUMBER_LITERAL
;; -----------------
;; Keyword terminals
;; -----------------
;; Generate a keyword analyzer
! %type <keyword> syntax "\\(\\sw\\|\\s_\\)+" matchdatatype keyword
%keyword ABSTRACT "abstract"
%put ABSTRACT summary
--- 108,130 ----
;; -----------------
;; Literal terminals
;; -----------------
! %type <symbol> ;;syntax "\\(\\sw\\|\\s_\\)+"
%token <symbol> NULL_LITERAL "\\`null\\'"
%token <symbol> BOOLEAN_LITERAL "\\`false\\'"
%token <symbol> BOOLEAN_LITERAL "\\`true\\'"
%token <symbol> IDENTIFIER
! %type <string> ;;syntax "\\s\"" matchdatatype sexp
%token <string> STRING_LITERAL
! %type <number> ;;syntax semantic-lex-number-expression
%token <number> NUMBER_LITERAL
;; -----------------
;; Keyword terminals
;; -----------------
;; Generate a keyword analyzer
! %type <keyword> ;;syntax "\\(\\sw\\|\\s_\\)+" matchdatatype keyword
%keyword ABSTRACT "abstract"
%put ABSTRACT summary
|