Add CEDET grammar files to emacs-23 branch.

This commit is contained in:
Chong Yidong 2012-01-09 13:42:57 +08:00
parent 9ca4c014c8
commit 866b58d61a
19 changed files with 5673 additions and 16 deletions

8
etc/grammars/README Normal file
View file

@ -0,0 +1,8 @@
This directory contains grammar files in Bison and Wisent, used to
generate the parser data in the lisp/semantic/bovine/ and
lisp/semantic/wisent/ directories. Currently, the parser files in
lisp/ are generated by hand, not automatically. You can run the
parser generators with
emacs -batch -Q -l bovine-grammar.el -f bovine-make-parsers
emacs -batch -Q -l wisent-grammar.el -f wisent-make-parsers

View file

@ -0,0 +1,501 @@
;;; bovine-grammar.el --- Bovine's input grammar mode
;;
;; Copyright (C) 2002-2011 Free Software Foundation, Inc.
;;
;; Author: David Ponce <david@dponce.com>
;; Maintainer: David Ponce <david@dponce.com>
;; Created: 26 Aug 2002
;; Keywords: syntax
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;; Major mode for editing Bovine's input grammar (.by) files.
;;; History:
;;; Code:
(require 'semantic)
(require 'semantic/grammar)
(require 'semantic/find)
(require 'semantic/lex)
(require 'semantic/wisent)
(require 'semantic/bovine)
(defun bovine-grammar-EXPAND (bounds nonterm)
"Expand call to EXPAND grammar macro.
Return the form to parse from within a nonterminal between BOUNDS.
NONTERM is the nonterminal symbol to start with."
`(semantic-bovinate-from-nonterminal
(car ,bounds) (cdr ,bounds) ',nonterm))
(defun bovine-grammar-EXPANDFULL (bounds nonterm)
"Expand call to EXPANDFULL grammar macro.
Return the form to recursively parse the area between BOUNDS.
NONTERM is the nonterminal symbol to start with."
`(semantic-parse-region
(car ,bounds) (cdr ,bounds) ',nonterm 1))
(defun bovine-grammar-TAG (name class &rest attributes)
"Expand call to TAG grammar macro.
Return the form to create a generic semantic tag.
See the function `semantic-tag' for the meaning of arguments NAME,
CLASS and ATTRIBUTES."
`(semantic-tag ,name ,class ,@attributes))
(defun bovine-grammar-VARIABLE-TAG (name type default-value &rest attributes)
"Expand call to VARIABLE-TAG grammar macro.
Return the form to create a semantic tag of class variable.
See the function `semantic-tag-new-variable' for the meaning of
arguments NAME, TYPE, DEFAULT-VALUE and ATTRIBUTES."
`(semantic-tag-new-variable ,name ,type ,default-value ,@attributes))
(defun bovine-grammar-FUNCTION-TAG (name type arg-list &rest attributes)
"Expand call to FUNCTION-TAG grammar macro.
Return the form to create a semantic tag of class function.
See the function `semantic-tag-new-function' for the meaning of
arguments NAME, TYPE, ARG-LIST and ATTRIBUTES."
`(semantic-tag-new-function ,name ,type ,arg-list ,@attributes))
(defun bovine-grammar-TYPE-TAG (name type members parents &rest attributes)
"Expand call to TYPE-TAG grammar macro.
Return the form to create a semantic tag of class type.
See the function `semantic-tag-new-type' for the meaning of arguments
NAME, TYPE, MEMBERS, PARENTS and ATTRIBUTES."
`(semantic-tag-new-type ,name ,type ,members ,parents ,@attributes))
(defun bovine-grammar-INCLUDE-TAG (name system-flag &rest attributes)
"Expand call to INCLUDE-TAG grammar macro.
Return the form to create a semantic tag of class include.
See the function `semantic-tag-new-include' for the meaning of
arguments NAME, SYSTEM-FLAG and ATTRIBUTES."
`(semantic-tag-new-include ,name ,system-flag ,@attributes))
(defun bovine-grammar-PACKAGE-TAG (name detail &rest attributes)
"Expand call to PACKAGE-TAG grammar macro.
Return the form to create a semantic tag of class package.
See the function `semantic-tag-new-package' for the meaning of
arguments NAME, DETAIL and ATTRIBUTES."
`(semantic-tag-new-package ,name ,detail ,@attributes))
(defun bovine-grammar-CODE-TAG (name detail &rest attributes)
"Expand call to CODE-TAG grammar macro.
Return the form to create a semantic tag of class code.
See the function `semantic-tag-new-code' for the meaning of arguments
NAME, DETAIL and ATTRIBUTES."
`(semantic-tag-new-code ,name ,detail ,@attributes))
(defun bovine-grammar-ALIAS-TAG (name aliasclass definition &rest attributes)
"Expand call to ALIAS-TAG grammar macro.
Return the form to create a semantic tag of class alias.
See the function `semantic-tag-new-alias' for the meaning of arguments
NAME, ALIASCLASS, DEFINITION and ATTRIBUTES."
`(semantic-tag-new-alias ,name ,aliasclass ,definition ,@attributes))
;; Cache of macro definitions currently in use.
(defvar bovine--grammar-macros nil)
(defun bovine-grammar-expand-form (form quotemode &optional inplace)
"Expand FORM into a new one suitable to the bovine parser.
FORM is a list in which we are substituting.
Argument QUOTEMODE is non-nil if we are in backquote mode.
When non-nil, optional argument INPLACE indicates that FORM is being
expanded from elsewhere."
(when (eq (car form) 'quote)
(setq form (cdr form))
(cond
((and (= (length form) 1) (listp (car form)))
(insert "\n(append")
(bovine-grammar-expand-form (car form) quotemode nil)
(insert ")")
(setq form nil inplace nil)
)
((and (= (length form) 1) (symbolp (car form)))
(insert "\n'" (symbol-name (car form)))
(setq form nil inplace nil)
)
(t
(insert "\n(list")
(setq inplace t)
)))
(let ((macro (assq (car form) bovine--grammar-macros))
inlist first n q x)
(if macro
(bovine-grammar-expand-form
(apply (cdr macro) (cdr form))
quotemode t)
(if inplace (insert "\n("))
(while form
(setq first (car form)
form (cdr form))
(cond
((eq first nil)
(when (and (not inlist) (not inplace))
(insert "\n(list")
(setq inlist t))
(insert " nil")
)
((listp first)
;;(let ((fn (and (symbolp (caar form)) (fboundp (caar form)))))
(when (and (not inlist) (not inplace))
(insert "\n(list")
(setq inlist t))
;;(if (and inplace (not fn) (not (eq (caar form) 'EXPAND)))
;; (insert " (append"))
(bovine-grammar-expand-form
first quotemode t) ;;(and fn (not (eq fn 'quote))))
;;(if (and inplace (not fn) (not (eq (caar form) 'EXPAND)))
;; (insert ")"))
;;)
)
((symbolp first)
(setq n (symbol-name first) ;the name
q quotemode ;implied quote flag
x nil) ;expand flag
(if (eq (aref n 0) ?,)
(if quotemode
;; backquote mode needs the @
(if (eq (aref n 1) ?@)
(setq n (substring n 2)
q nil
x t)
;; non backquote mode behaves normally.
(setq n (substring n 1)
q nil))
(setq n (substring n 1)
x t)))
(if (string= n "")
(progn
;; We expand only the next item in place (a list?)
;; A regular inline-list...
(bovine-grammar-expand-form (car form) quotemode t)
(setq form (cdr form)))
(if (and (eq (aref n 0) ?$)
;; Don't expand $ tokens in implied quote mode.
;; This acts like quoting in other symbols.
(not q))
(progn
(cond
((and (not x) (not inlist) (not inplace))
(insert "\n(list"))
((and x inlist (not inplace))
(insert ")")
(setq inlist nil)))
(insert "\n(nth " (int-to-string
(1- (string-to-number
(substring n 1))))
" vals)")
(and (not x) (not inplace)
(setq inlist t)))
(when (and (not inlist) (not inplace))
(insert "\n(list")
(setq inlist t))
(or (char-equal (char-before) ?\()
(insert " "))
(insert (if (or inplace (eq first t))
"" "'")
n))) ;; " "
)
(t
(when (and (not inlist) (not inplace))
(insert "\n(list")
(setq inlist t))
(insert (format "\n%S" first))
)
))
(if inlist (insert ")"))
(if inplace (insert ")")))
))
(defun bovine-grammar-expand-action (textform quotemode)
"Expand semantic action string TEXTFORM into Lisp code.
QUOTEMODE is the mode in which quoted symbols are slurred."
(if (string= "" textform)
nil
(let ((sexp (read textform)))
;; We converted the lambda string into a list. Now write it
;; out as the bovine lambda expression, and do macro-like
;; conversion upon it.
(insert "\n")
(cond
((eq (car sexp) 'EXPAND)
(insert ",(lambda (vals start end)")
;; The EXPAND macro definition is mandatory
(bovine-grammar-expand-form
(apply (cdr (assq 'EXPAND bovine--grammar-macros)) (cdr sexp))
quotemode t)
)
((and (listp (car sexp)) (eq (caar sexp) 'EVAL))
;; The user wants to evaluate the following args.
;; Use a simpler expander
)
(t
(insert ",(semantic-lambda")
(bovine-grammar-expand-form sexp quotemode)
))
(insert ")\n")))
)
(defun bovine-grammar-parsetable-builder ()
"Return the parser table expression as a string value.
The format of a bovine parser table is:
( ( NONTERMINAL-SYMBOL1 MATCH-LIST1 )
( NONTERMINAL-SYMBOL2 MATCH-LIST2 )
...
( NONTERMINAL-SYMBOLn MATCH-LISTn )
Where each NONTERMINAL-SYMBOL is an artificial symbol which can appear
in any child state. As a starting place, one of the NONTERMINAL-SYMBOLS
must be `bovine-toplevel'.
A MATCH-LIST is a list of possible matches of the form:
( STATE-LIST1
STATE-LIST2
...
STATE-LISTN )
where STATE-LIST is of the form:
( TYPE1 [ \"VALUE1\" ] TYPE2 [ \"VALUE2\" ] ... LAMBDA )
where TYPE is one of the returned types of the token stream.
VALUE is a value, or range of values to match against. For
example, a SYMBOL might need to match \"foo\". Some TYPES will not
have matching criteria.
LAMBDA is a lambda expression which is evaled with the text of the
type when it is found. It is passed the list of all buffer text
elements found since the last lambda expression. It should return a
semantic element (see below.)
For consistency between languages, try to use common return values
from your parser. Please reference the chapter \"Writing Parsers\" in
the \"Language Support Developer's Guide -\" in the semantic texinfo
manual."
(let* ((start (semantic-grammar-start))
(scopestart (semantic-grammar-scopestart))
(quotemode (semantic-grammar-quotemode))
(tags (semantic-find-tags-by-class
'token (current-buffer)))
(nterms (semantic-find-tags-by-class
'nonterminal (current-buffer)))
;; Setup the cache of macro definitions.
(bovine--grammar-macros (semantic-grammar-macros))
nterm rules items item actn prec tag type regex)
;; Check some trivial things
(cond
((null nterms)
(error "Bad input grammar"))
(start
(if (cdr start)
(message "Extra start symbols %S ignored" (cdr start)))
(setq start (symbol-name (car start)))
(unless (semantic-find-first-tag-by-name start nterms)
(error "start symbol `%s' has no rule" start)))
(t
;; Default to the first grammar rule.
(setq start (semantic-tag-name (car nterms)))))
(when scopestart
(setq scopestart (symbol-name scopestart))
(unless (semantic-find-first-tag-by-name scopestart nterms)
(error "scopestart symbol `%s' has no rule" scopestart)))
;; Generate the grammar Lisp form.
(with-temp-buffer
(erase-buffer)
(insert "`(")
;; Insert the start/scopestart rules
(insert "\n(bovine-toplevel \n("
start
")\n) ;; end bovine-toplevel\n")
(when scopestart
(insert "\n(bovine-inner-scope \n("
scopestart
")\n) ;; end bovine-inner-scope\n"))
;; Process each nonterminal
(while nterms
(setq nterm (car nterms)
;; We can't use the override form because the current buffer
;; is not the originator of the tag.
rules (semantic-tag-components-semantic-grammar-mode nterm)
nterm (semantic-tag-name nterm)
nterms (cdr nterms))
(when (member nterm '("bovine-toplevel" "bovine-inner-scope"))
(error "`%s' is a reserved internal name" nterm))
(insert "\n(" nterm)
;; Process each rule
(while rules
(setq items (semantic-tag-get-attribute (car rules) :value)
prec (semantic-tag-get-attribute (car rules) :prec)
actn (semantic-tag-get-attribute (car rules) :expr)
rules (cdr rules))
;; Process each item
(insert "\n(")
(if (null items)
;; EMPTY rule
(insert ";;EMPTY" (if actn "" "\n"))
;; Expand items
(while items
(setq item (car items)
items (cdr items))
(if (consp item) ;; mid-rule action
(message "Mid-rule action %S ignored" item)
(or (char-equal (char-before) ?\()
(insert "\n"))
(cond
((member item '("bovine-toplevel" "bovine-inner-scope"))
(error "`%s' is a reserved internal name" item))
;; Replace ITEM by its %token definition.
;; If a '%token TYPE ITEM [REGEX]' definition exists
;; in the grammar, ITEM is replaced by TYPE [REGEX].
((setq tag (semantic-find-first-tag-by-name
item tags)
type (semantic-tag-get-attribute tag :type))
(insert type)
(if (setq regex (semantic-tag-get-attribute tag :value))
(insert (format "\n%S" regex))))
;; Don't change ITEM
(t
(insert (semantic-grammar-item-text item)))
))))
(if prec
(message "%%prec %S ignored" prec))
(if actn
(bovine-grammar-expand-action actn quotemode))
(insert ")"))
(insert "\n) ;; end " nterm "\n"))
(insert ")\n")
(buffer-string))))
(defun bovine-grammar-setupcode-builder ()
"Return the text of the setup code."
(format
"(setq semantic--parse-table %s\n\
semantic-debug-parser-source %S\n\
semantic-debug-parser-class 'semantic-bovine-debug-parser
semantic-flex-keywords-obarray %s\n\
%s)"
(semantic-grammar-parsetable)
(buffer-name)
(semantic-grammar-keywordtable)
(let ((mode (semantic-grammar-languagemode)))
;; Is there more than one major mode?
(if (and (listp mode) (> (length mode) 1))
(format "semantic-equivalent-major-modes '%S\n" mode)
""))))
(defvar bovine-grammar-menu
'("BY Grammar"
)
"BY mode specific grammar menu.
Menu items are appended to the common grammar menu.")
(define-derived-mode bovine-grammar-mode semantic-grammar-mode "BY"
"Major mode for editing Bovine grammars."
(semantic-grammar-setup-menu bovine-grammar-menu)
(semantic-install-function-overrides
'((grammar-parsetable-builder . bovine-grammar-parsetable-builder)
(grammar-setupcode-builder . bovine-grammar-setupcode-builder)
)))
(add-to-list 'auto-mode-alist '("\\.by$" . bovine-grammar-mode))
(defvar-mode-local bovine-grammar-mode semantic-grammar-macros
'(
(ASSOC . semantic-grammar-ASSOC)
(EXPAND . bovine-grammar-EXPAND)
(EXPANDFULL . bovine-grammar-EXPANDFULL)
(TAG . bovine-grammar-TAG)
(VARIABLE-TAG . bovine-grammar-VARIABLE-TAG)
(FUNCTION-TAG . bovine-grammar-FUNCTION-TAG)
(TYPE-TAG . bovine-grammar-TYPE-TAG)
(INCLUDE-TAG . bovine-grammar-INCLUDE-TAG)
(PACKAGE-TAG . bovine-grammar-PACKAGE-TAG)
(CODE-TAG . bovine-grammar-CODE-TAG)
(ALIAS-TAG . bovine-grammar-ALIAS-TAG)
)
"Semantic grammar macros used in bovine grammars.")
(provide 'semantic/bovine/grammar)
(defun bovine-make-parsers ()
"Generate Emacs' built-in Bovine-based parser files."
(semantic-mode 1)
;; Loop through each .by file in current directory, and run
;; `semantic-grammar-batch-build-one-package' to build the grammar.
(dolist (f (directory-files default-directory nil ".by$"))
(let ((packagename
(condition-case err
(with-current-buffer (find-file-noselect f)
(semantic-grammar-create-package))
(error (message "%s" (error-message-string err)) nil)))
lang)
(when (and packagename
(string-match "^semantic-\\(.*\\)-by.el$" packagename))
(setq lang (match-string 1 packagename))
(with-temp-buffer
(insert-file-contents packagename)
(setq buffer-file-name (expand-file-name packagename))
;; Fix copyright header:
(goto-char (point-min))
(re-search-forward "^;; Author:")
(setq copyright-end (match-beginning 0))
(re-search-forward "^;;; Code:\n")
(delete-region copyright-end (match-end 0))
(goto-char copyright-end)
(insert ";; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;; This file was generated from etc/grammars/"
lang ".by.
;;; Code:
\(require 'semantic/lex)
\(eval-when-compile (require 'semantic/bovine))\n")
(goto-char (point-min))
(delete-region (point-min) (line-end-position))
(insert ";;; semantic/bovine/" lang
"-by.el --- Generated parser support file")
(delete-trailing-whitespace)
;; Fix footer:
(goto-char (point-max))
(re-search-backward ".\n;;; Analyzers")
(delete-region (point) (point-max))
(insert "(provide 'semantic/bovine/" lang "-by)\n\n")
(insert ";;; semantic/bovine/" lang "-by.el ends here\n")
(save-buffer))))))
;;; bovine-grammar.el ends here

1202
etc/grammars/c.by Normal file

File diff suppressed because it is too large Load diff

432
etc/grammars/grammar.wy Normal file
View file

@ -0,0 +1,432 @@
;;; semantic-grammar.wy -- LALR grammar of Semantic input grammars
;;
;; Copyright (C) 2002-2011 Free Software Foundation, Inc.
;;
;; Author: David Ponce <david@dponce.com>
;; Maintainer: David Ponce <david@dponce.com>
;; Created: 26 Aug 2002
;; Keywords: syntax
;; X-RCS: $Id: semantic-grammar.wy,v 1.16 2005/09/30 20:20:27 zappo Exp $
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
%{
;; Current parsed nonterminal name.
(defvar semantic-grammar-wy--nterm nil)
;; Index of rule in a nonterminal clause.
(defvar semantic-grammar-wy--rindx nil)
}
%package semantic-grammar-wy
%languagemode wy-mode
;; Main
%start grammar
;; Reparse
%start prologue epilogue declaration nonterminal rule
;; EXPANDFULL
%start put_names put_values use_names
;; Keywords
%type <keyword>
%keyword DEFAULT-PREC "%default-prec"
%keyword NO-DEFAULT-PREC "%no-default-prec"
%keyword KEYWORD "%keyword"
%keyword LANGUAGEMODE "%languagemode"
%keyword LEFT "%left"
%keyword NONASSOC "%nonassoc"
%keyword PACKAGE "%package"
%keyword PREC "%prec"
%keyword PUT "%put"
%keyword QUOTEMODE "%quotemode"
%keyword RIGHT "%right"
%keyword SCOPESTART "%scopestart"
%keyword START "%start"
%keyword TOKEN "%token"
%keyword TYPE "%type"
%keyword USE-MACROS "%use-macros"
;; Literals
%type <string>
%token <string> STRING
%type <symbol> syntax ":?\\(\\sw\\|\\s_\\)+"
%token <symbol> SYMBOL
%token <symbol> PERCENT_PERCENT "\\`%%\\'"
%type <char> syntax semantic-grammar-lex-c-char-re
%token <char> CHARACTER
%type <qlist> matchdatatype sexp syntax "\\s'\\s-*("
%token <qlist> PREFIXED_LIST
%type <sexp> matchdatatype sexp syntax "\\="
%token <sexp> SEXP
;; Don't generate these analyzers which needs special handling code.
%token <code> PROLOGUE "%{...%}"
%token <code> EPILOGUE "%%...EOF"
;; Blocks & Parenthesis
%type <block>
%token <block> PAREN_BLOCK "(LPAREN RPAREN)"
%token <block> BRACE_BLOCK "(LBRACE RBRACE)"
%token <open-paren> LPAREN "("
%token <close-paren> RPAREN ")"
%token <open-paren> LBRACE "{"
%token <close-paren> RBRACE "}"
;; Punctuations
%type <punctuation>
%token <punctuation> COLON ":"
%token <punctuation> SEMI ";"
%token <punctuation> OR "|"
%token <punctuation> LT "<"
%token <punctuation> GT ">"
%%
grammar:
prologue
| epilogue
| declaration
| nonterminal
| PERCENT_PERCENT
;
;;; Prologue/Epilogue
;;
prologue:
PROLOGUE
(CODE-TAG "prologue" nil)
;
epilogue:
EPILOGUE
(CODE-TAG "epilogue" nil)
;
;;; Declarations
;;
declaration:
decl
(eval $1)
;
decl:
default_prec_decl
| no_default_prec_decl
| languagemode_decl
| package_decl
| precedence_decl
| put_decl
| quotemode_decl
| scopestart_decl
| start_decl
| keyword_decl
| token_decl
| type_decl
| use_macros_decl
;
default_prec_decl:
DEFAULT-PREC
`(TAG "default-prec" 'assoc :value '("t"))
;
no_default_prec_decl:
NO-DEFAULT-PREC
`(TAG "default-prec" 'assoc :value '("nil"))
;
languagemode_decl:
LANGUAGEMODE symbols
`(TAG ',(car $2) 'languagemode :rest ',(cdr $2))
;
package_decl:
PACKAGE SYMBOL
`(PACKAGE-TAG ',$2 nil)
;
precedence_decl:
associativity token_type_opt items
`(TAG ',$1 'assoc :type ',$2 :value ',$3)
;
associativity:
LEFT
(progn "left")
| RIGHT
(progn "right")
| NONASSOC
(progn "nonassoc")
;
put_decl:
PUT put_name put_value
`(TAG ',$2 'put :value ',(list $3))
| PUT put_name put_value_list
`(TAG ',$2 'put :value ',$3)
| PUT put_name_list put_value
`(TAG ',(car $2) 'put :rest ',(cdr $2) :value ',(list $3))
| PUT put_name_list put_value_list
`(TAG ',(car $2) 'put :rest ',(cdr $2) :value ',$3)
;
put_name_list:
BRACE_BLOCK
(mapcar 'semantic-tag-name (EXPANDFULL $1 put_names))
;
put_names:
LBRACE
()
| RBRACE
()
| put_name
;; Must return a list of Semantic tags to EXPANDFULL!
(TAG $1 'put-name)
;
put_name:
SYMBOL
| token_type
;
put_value_list:
BRACE_BLOCK
(mapcar 'semantic-tag-code-detail (EXPANDFULL $1 put_values))
;
put_values:
LBRACE
()
| RBRACE
()
| put_value
;; Must return a list of Semantic tags to EXPANDFULL!
(CODE-TAG "put-value" $1)
;
put_value:
SYMBOL any_value
(cons $1 $2)
;
scopestart_decl:
SCOPESTART SYMBOL
`(TAG ',$2 'scopestart)
;
quotemode_decl:
QUOTEMODE SYMBOL
`(TAG ',$2 'quotemode)
;
start_decl:
START symbols
`(TAG ',(car $2) 'start :rest ',(cdr $2))
;
keyword_decl:
KEYWORD SYMBOL string_value
`(TAG ',$2 'keyword :value ',$3)
;
token_decl:
TOKEN token_type_opt SYMBOL string_value
`(TAG ',$3 ',(if $2 'token 'keyword) :type ',$2 :value ',$4)
| TOKEN token_type_opt symbols
`(TAG ',(car $3) 'token :type ',$2 :rest ',(cdr $3))
;
token_type_opt:
;; EMPTY
| token_type
;
token_type:
LT SYMBOL GT
(progn $2)
;
type_decl:
TYPE token_type plist_opt
`(TAG ',$2 'type :value ',$3)
;
plist_opt:
;;EMPTY
| plist
;
plist:
plist put_value
(append (list $2) $1)
| put_value
(list $1)
;
use_name_list:
BRACE_BLOCK
(mapcar 'semantic-tag-name (EXPANDFULL $1 use_names))
;
use_names:
LBRACE
()
| RBRACE
()
| SYMBOL
;; Must return a list of Semantic tags to EXPANDFULL!
(TAG $1 'use-name)
;
use_macros_decl:
USE-MACROS SYMBOL use_name_list
`(TAG "macro" 'macro :type ',$2 :value ',$3)
;
string_value:
STRING
(read $1)
;
;; Return a Lisp readable form
any_value:
SYMBOL
| STRING
| PAREN_BLOCK
| PREFIXED_LIST
| SEXP
;
symbols:
lifo_symbols
(nreverse $1)
;
lifo_symbols:
lifo_symbols SYMBOL
(cons $2 $1)
| SYMBOL
(list $1)
;
;;; Grammar rules
;;
nonterminal:
SYMBOL
(setq semantic-grammar-wy--nterm $1
semantic-grammar-wy--rindx 0)
COLON rules SEMI
(TAG $1 'nonterminal :children $4)
;
rules:
lifo_rules
(apply 'nconc (nreverse $1))
;
lifo_rules:
lifo_rules OR rule
(cons $3 $1)
| rule
(list $1)
;
rule:
rhs
(let* ((nterm semantic-grammar-wy--nterm)
(rindx semantic-grammar-wy--rindx)
(rhs $1)
comps prec action elt)
(setq semantic-grammar-wy--rindx (1+ semantic-grammar-wy--rindx))
(while rhs
(setq elt (car rhs)
rhs (cdr rhs))
(cond
;; precedence level
((vectorp elt)
(if prec
(error "Duplicate %%prec in `%s:%d' rule" nterm rindx))
(setq prec (aref elt 0)))
;; action
((consp elt)
;; don't forget that rhs items are in reverse order, so
;; the end-of-rule semantic action is the first item.
(if (or action comps)
;; a mid-rule action
(setq comps (cons elt comps)
;; keep rule and action index synchronized
semantic-grammar-wy--rindx
(1+ semantic-grammar-wy--rindx))
;; the end-of-rule action
(setq action (car elt))))
;; item
(t
(setq comps (cons elt comps)))))
(EXPANDTAG
(TAG (format "%s:%d" nterm rindx) 'rule
:type (if comps "group" "empty")
:value comps :prec prec :expr action)))
;
rhs:
;; EMPTY
| rhs item
(cons $2 $1)
| rhs action
(cons (list $2) $1)
| rhs PREC item
(cons (vector $3) $1)
;
action:
PAREN_BLOCK
| PREFIXED_LIST
| BRACE_BLOCK
(format "(progn\n%s)"
(let ((s $1))
(if (string-match "^{[\r\n\t ]*" s)
(setq s (substring s (match-end 0))))
(if (string-match "[\r\n\t ]*}$" s)
(setq s (substring s 0 (match-beginning 0))))
s))
;
items:
lifo_items
(nreverse $1)
;
lifo_items:
lifo_items item
(cons $2 $1)
| item
(list $1)
;
item:
SYMBOL
| CHARACTER
;
%%
;;; grammar.wy ends here

750
etc/grammars/java-tags.wy Normal file
View file

@ -0,0 +1,750 @@
;;; java-tags.wy -- Semantic LALR grammar for Java
;; Copyright (C) 2002-2011 Free Software Foundation, Inc.
;;
;; Author: David Ponce <david@dponce.com>
;; Maintainer: David Ponce <david@dponce.com>
;; Created: 26 Aug 2002
;; Keywords: syntax
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
%package wisent-java-tags-wy
%languagemode java-mode
;; The default start symbol
%start compilation_unit
;; Alternate entry points
;; - Needed by partial re-parse
%start package_declaration
%start import_declaration
%start class_declaration
%start field_declaration
%start method_declaration
%start formal_parameter
%start constructor_declaration
%start interface_declaration
;; - Needed by EXPANDFULL clauses
%start class_member_declaration
%start interface_member_declaration
%start formal_parameters
;; -----------------------------
;; Block & Parenthesis terminals
;; -----------------------------
%type <block> ;;syntax "\\s(\\|\\s)" matchdatatype block
%token <block> PAREN_BLOCK "(LPAREN RPAREN)"
%token <block> BRACE_BLOCK "(LBRACE RBRACE)"
%token <block> BRACK_BLOCK "(LBRACK RBRACK)"
%token <open-paren> LPAREN "("
%token <close-paren> RPAREN ")"
%token <open-paren> LBRACE "{"
%token <close-paren> RBRACE "}"
%token <open-paren> LBRACK "["
%token <close-paren> RBRACK "]"
;; ------------------
;; Operator terminals
;; ------------------
%type <punctuation> ;;syntax "\\(\\s.\\|\\s$\\|\\s'\\)+" matchdatatype string
%token <punctuation> NOT "!"
%token <punctuation> NOTEQ "!="
%token <punctuation> MOD "%"
%token <punctuation> MODEQ "%="
%token <punctuation> AND "&"
%token <punctuation> ANDAND "&&"
%token <punctuation> ANDEQ "&="
%token <punctuation> MULT "*"
%token <punctuation> MULTEQ "*="
%token <punctuation> PLUS "+"
%token <punctuation> PLUSPLUS "++"
%token <punctuation> PLUSEQ "+="
%token <punctuation> COMMA ","
%token <punctuation> MINUS "-"
%token <punctuation> MINUSMINUS "--"
%token <punctuation> MINUSEQ "-="
%token <punctuation> DOT "."
%token <punctuation> DIV "/"
%token <punctuation> DIVEQ "/="
%token <punctuation> COLON ":"
%token <punctuation> SEMICOLON ";"
%token <punctuation> LT "<"
%token <punctuation> LSHIFT "<<"
%token <punctuation> LSHIFTEQ "<<="
%token <punctuation> LTEQ "<="
%token <punctuation> EQ "="
%token <punctuation> EQEQ "=="
%token <punctuation> GT ">"
%token <punctuation> GTEQ ">="
%token <punctuation> RSHIFT ">>"
%token <punctuation> RSHIFTEQ ">>="
%token <punctuation> URSHIFT ">>>"
%token <punctuation> URSHIFTEQ ">>>="
%token <punctuation> QUESTION "?"
%token <punctuation> XOR "^"
%token <punctuation> XOREQ "^="
%token <punctuation> OR "|"
%token <punctuation> OREQ "|="
%token <punctuation> OROR "||"
%token <punctuation> COMP "~"
;; -----------------
;; 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
%type <unicode> syntax "\\\\u[0-9a-f][0-9a-f][0-9a-f][0-9a-f]"
%token <unicode> unicodecharacter
;; -----------------
;; Keyword terminals
;; -----------------
;; Generate a keyword analyzer
%type <keyword> ;;syntax "\\(\\sw\\|\\s_\\)+" matchdatatype keyword
%keyword ABSTRACT "abstract"
%put ABSTRACT summary
"Class|Method declaration modifier: abstract {class|<type>} <name> ..."
%keyword BOOLEAN "boolean"
%put BOOLEAN summary
"Primitive logical quantity type (true or false)"
%keyword BREAK "break"
%put BREAK summary
"break [<label>] ;"
%keyword BYTE "byte"
%put BYTE summary
"Integral primitive type (-128 to 127)"
%keyword CASE "case"
%put CASE summary
"switch(<expr>) {case <const-expr>: <stmts> ... }"
%keyword CATCH "catch"
%put CATCH summary
"try {<stmts>} catch(<parm>) {<stmts>} ... "
%keyword CHAR "char"
%put CHAR summary
"Integral primitive type ('\u0000' to '\uffff') (0 to 65535)"
%keyword CLASS "class"
%put CLASS summary
"Class declaration: class <name>"
%keyword CONST "const"
%put CONST summary
"Unused reserved word"
%keyword CONTINUE "continue"
%put CONTINUE summary
"continue [<label>] ;"
%keyword DEFAULT "default"
%put DEFAULT summary
"switch(<expr>) { ... default: <stmts>}"
%keyword DO "do"
%put DO summary
"do <stmt> while (<expr>);"
%keyword DOUBLE "double"
%put DOUBLE summary
"Primitive floating-point type (double-precision 64-bit IEEE 754)"
%keyword ELSE "else"
%put ELSE summary
"if (<expr>) <stmt> else <stmt>"
%keyword EXTENDS "extends"
%put EXTENDS summary
"SuperClass|SuperInterfaces declaration: extends <name> [, ...]"
%keyword FINAL "final"
%put FINAL summary
"Class|Member declaration modifier: final {class|<type>} <name> ..."
%keyword FINALLY "finally"
%put FINALLY summary
"try {<stmts>} ... finally {<stmts>}"
%keyword FLOAT "float"
%put FLOAT summary
"Primitive floating-point type (single-precision 32-bit IEEE 754)"
%keyword FOR "for"
%put FOR summary
"for ([<init-expr>]; [<expr>]; [<update-expr>]) <stmt>"
%keyword GOTO "goto"
%put GOTO summary
"Unused reserved word"
%keyword IF "if"
%put IF summary
"if (<expr>) <stmt> [else <stmt>]"
%keyword IMPLEMENTS "implements"
%put IMPLEMENTS summary
"Class SuperInterfaces declaration: implements <name> [, ...]"
%keyword IMPORT "import"
%put IMPORT summary
"Import package declarations: import <package>"
%keyword INSTANCEOF "instanceof"
%keyword INT "int"
%put INT summary
"Integral primitive type (-2147483648 to 2147483647)"
%keyword INTERFACE "interface"
%put INTERFACE summary
"Interface declaration: interface <name>"
%keyword LONG "long"
%put LONG summary
"Integral primitive type (-9223372036854775808 to 9223372036854775807)"
%keyword NATIVE "native"
%put NATIVE summary
"Method declaration modifier: native <type> <name> ..."
%keyword NEW "new"
%keyword PACKAGE "package"
%put PACKAGE summary
"Package declaration: package <name>"
%keyword PRIVATE "private"
%put PRIVATE summary
"Access level modifier: private {class|interface|<type>} <name> ..."
%keyword PROTECTED "protected"
%put PROTECTED summary
"Access level modifier: protected {class|interface|<type>} <name> ..."
%keyword PUBLIC "public"
%put PUBLIC summary
"Access level modifier: public {class|interface|<type>} <name> ..."
%keyword RETURN "return"
%put RETURN summary
"return [<expr>] ;"
%keyword SHORT "short"
%put SHORT summary
"Integral primitive type (-32768 to 32767)"
%keyword STATIC "static"
%put STATIC summary
"Declaration modifier: static {class|interface|<type>} <name> ..."
%keyword STRICTFP "strictfp"
%put STRICTFP summary
"Declaration modifier: strictfp {class|interface|<type>} <name> ..."
%keyword SUPER "super"
%keyword SWITCH "switch"
%put SWITCH summary
"switch(<expr>) {[case <const-expr>: <stmts> ...] [default: <stmts>]}"
%keyword SYNCHRONIZED "synchronized"
%put SYNCHRONIZED summary
"synchronized (<expr>) ... | Method decl. modifier: synchronized <type> <name> ..."
%keyword THIS "this"
%keyword THROW "throw"
%put THROW summary
"throw <expr> ;"
%keyword THROWS "throws"
%put THROWS summary
"Method|Constructor declaration: throws <classType>, ..."
%keyword TRANSIENT "transient"
%put TRANSIENT summary
"Field declaration modifier: transient <type> <name> ..."
%keyword TRY "try"
%put TRY summary
"try {<stmts>} [catch(<parm>) {<stmts>} ...] [finally {<stmts>}]"
%keyword VOID "void"
%put VOID summary
"Method return type: void <name> ..."
%keyword VOLATILE "volatile"
%put VOLATILE summary
"Field declaration modifier: volatile <type> <name> ..."
%keyword WHILE "while"
%put WHILE summary
"while (<expr>) <stmt> | do <stmt> while (<expr>);"
;; --------------------------
;; Official javadoc line tags
;; --------------------------
;; Javadoc tags are identified by a 'javadoc' keyword property. The
;; value of this property must be itself a property list where the
;; following properties are recognized:
;;
;; - `seq' (mandatory) is the tag sequence number used to check if tags
;; are correctly ordered in a javadoc comment block.
;;
;; - `usage' (mandatory) is the list of token categories for which this
;; documentation tag is allowed.
;;
;; - `opt' (optional) if non-nil indicates this is an optional tag.
;; By default tags are mandatory.
;;
;; - `with-name' (optional) if non-nil indicates that this tag is
;; followed by an identifier like in "@param <var-name> description"
;; or "@exception <class-name> description".
;;
;; - `with-ref' (optional) if non-nil indicates that the tag is
;; followed by a reference like in "@see <reference>".
%keyword _AUTHOR "@author"
%put _AUTHOR javadoc (seq 1 usage (type))
%keyword _VERSION "@version"
%put _VERSION javadoc (seq 2 usage (type))
%keyword _PARAM "@param"
%put _PARAM javadoc (seq 3 usage (function) with-name t)
%keyword _RETURN "@return"
%put _RETURN javadoc (seq 4 usage (function))
%keyword _EXCEPTION "@exception"
%put _EXCEPTION javadoc (seq 5 usage (function) with-name t)
%keyword _THROWS "@throws"
%put _THROWS javadoc (seq 6 usage (function) with-name t)
%keyword _SEE "@see"
%put _SEE javadoc (seq 7 usage (type function variable) opt t with-ref t)
%keyword _SINCE "@since"
%put _SINCE javadoc (seq 8 usage (type function variable) opt t)
%keyword _SERIAL "@serial"
%put _SERIAL javadoc (seq 9 usage (variable) opt t)
%keyword _SERIALDATA "@serialData"
%put _SERIALDATA javadoc (seq 10 usage (function) opt t)
%keyword _SERIALFIELD "@serialField"
%put _SERIALFIELD javadoc (seq 11 usage (variable) opt t)
%keyword _DEPRECATED "@deprecated"
%put _DEPRECATED javadoc (seq 12 usage (type function variable) opt t)
%%
;; ------------
;; LALR Grammar
;; ------------
;; This grammar is not designed to fully parse correct Java syntax. It
;; is optimized to work in an interactive environment to extract tokens
;; (tags) needed by Semantic. In some cases a syntax not allowed by
;; the Java Language Specification will be accepted by this grammar.
compilation_unit
: package_declaration
| import_declaration
| type_declaration
;
;;; Package statement token
;; ("NAME" package DETAIL "DOCSTRING")
package_declaration
: PACKAGE qualified_name SEMICOLON
(PACKAGE-TAG $2 nil)
;
;;; Include file token
;; ("FILE" include SYSTEM "DOCSTRING")
import_declaration
: IMPORT qualified_name SEMICOLON
(INCLUDE-TAG $2 nil)
| IMPORT qualified_name DOT MULT SEMICOLON
(INCLUDE-TAG (concat $2 $3 $4) nil)
;
type_declaration
: SEMICOLON
()
| class_declaration
| interface_declaration
;
;;; Type Declaration token
;; ("NAME" type "TYPE" ( PART-LIST ) ( PARENTS ) EXTRA-SPEC "DOCSTRING")
class_declaration
: modifiers_opt CLASS qualified_name superc_opt interfaces_opt class_body
(TYPE-TAG $3 $2 $6 (if (or $4 $5) (cons $4 $5)) :typemodifiers $1)
;
superc_opt
: ;;EMPTY
| EXTENDS qualified_name
(identity $2)
;
interfaces_opt
: ;;EMPTY
| IMPLEMENTS qualified_name_list
(nreverse $2)
;
class_body
: BRACE_BLOCK
(EXPANDFULL $1 class_member_declaration)
;
class_member_declaration
: LBRACE
()
| RBRACE
()
| block
()
| static_initializer
()
| constructor_declaration
| interface_declaration
| class_declaration
| method_declaration
| field_declaration
;
;;; Type Declaration token
;; ("NAME" type "TYPE" ( PART-LIST ) ( PARENTS ) EXTRA-SPEC "DOCSTRING")
interface_declaration
: modifiers_opt INTERFACE IDENTIFIER extends_interfaces_opt interface_body
(TYPE-TAG $3 $2 $5 (if $4 (cons nil $4)) :typemodifiers $1)
;
extends_interfaces_opt
: ;;EMPTY
| EXTENDS qualified_name_list
(identity $2)
;
interface_body
: BRACE_BLOCK
(EXPANDFULL $1 interface_member_declaration)
;
interface_member_declaration
: LBRACE
()
| RBRACE
()
| interface_declaration
| class_declaration
| method_declaration
| field_declaration
;
static_initializer
: STATIC block
;
;;; Function token
;; ("NAME" function "TYPE" ( ARG-LIST ) EXTRA-SPEC "DOCSTRING")
constructor_declaration
: modifiers_opt constructor_declarator throwsc_opt constructor_body
(FUNCTION-TAG (car $2) nil (cdr $2)
:typemodifiers $1
:throws $3
:constructor-flag t)
;
constructor_declarator
: IDENTIFIER formal_parameter_list
(cons $1 $2)
;
constructor_body
: block
;
;;; Function token
;; ("NAME" function "TYPE" ( ARG-LIST ) EXTRA-SPEC "DOCSTRING")
method_declaration
: modifiers_opt VOID method_declarator throwsc_opt method_body
(FUNCTION-TAG (car $3) $2 (cdr $3) :typemodifiers $1 :throws $4)
| modifiers_opt type method_declarator throwsc_opt method_body
(FUNCTION-TAG (car $3) $2 (cdr $3) :typemodifiers $1 :throws $4)
;
method_declarator
: IDENTIFIER formal_parameter_list dims_opt
(cons (concat $1 $3) $2)
;
throwsc_opt
: ;;EMPTY
| THROWS qualified_name_list
(nreverse $2)
;
qualified_name_list
: qualified_name_list COMMA qualified_name
(cons $3 $1)
| qualified_name
(list $1)
;
method_body
: SEMICOLON
| block
;
;; Just eat {...} block!
block
: BRACE_BLOCK
;
formal_parameter_list
: PAREN_BLOCK
(EXPANDFULL $1 formal_parameters)
;
formal_parameters
: LPAREN
()
| RPAREN
()
| formal_parameter COMMA
| formal_parameter RPAREN
;
;;; Variable token
;; ("NAME" variable "TYPE" DEFAULT-VALUE EXTRA-SPEC "DOCSTRING")
formal_parameter
: formal_parameter_modifier_opt type variable_declarator_id
(VARIABLE-TAG $3 $2 nil :typemodifiers $1)
;
formal_parameter_modifier_opt
: ;;EMPTY
| FINAL
(list $1)
;
;;; Variable token
;; ("NAME" variable "TYPE" DEFAULT-VALUE EXTRA-SPEC "DOCSTRING")
field_declaration
: modifiers_opt type variable_declarators SEMICOLON
(VARIABLE-TAG $3 $2 nil :typemodifiers $1)
;
variable_declarators
: variable_declarators COMMA variable_declarator
(progn
;; Set the end of the compound declaration to the end of the
;; COMMA delimiter.
(setcdr (cdr (car $1)) (cdr $region2))
(cons $3 $1))
| variable_declarator
(list $1)
;
variable_declarator
: variable_declarator_id EQ variable_initializer
(cons $1 $region)
| variable_declarator_id
(cons $1 $region)
;
variable_declarator_id
: IDENTIFIER dims_opt
(concat $1 $2)
;
variable_initializer
: expression
;
;; Just eat expression!
expression
: expression term
| term
;
term
: literal
| operator
| primitive_type
| IDENTIFIER
| BRACK_BLOCK
| PAREN_BLOCK
| BRACE_BLOCK
| NEW
| CLASS
| THIS
| SUPER
;
literal
;; : NULL_LITERAL
;; | BOOLEAN_LITERAL
: STRING_LITERAL
| NUMBER_LITERAL
;
operator
: NOT
| PLUS
| PLUSPLUS
| MINUS
| MINUSMINUS
| NOTEQ
| MOD
| MODEQ
| AND
| ANDAND
| ANDEQ
| MULT
| MULTEQ
| PLUSEQ
| MINUSEQ
| DOT
| DIV
| DIVEQ
| COLON
| LT
| LSHIFT
| LSHIFTEQ
| LTEQ
| EQ
| EQEQ
| GT
| GTEQ
| RSHIFT
| RSHIFTEQ
| URSHIFT
| URSHIFTEQ
| QUESTION
| XOR
| XOREQ
| OR
| OREQ
| OROR
| COMP
| INSTANCEOF
;
primitive_type
: BOOLEAN
| CHAR
| LONG
| INT
| SHORT
| BYTE
| DOUBLE
| FLOAT
;
modifiers_opt
: ;;EMPTY
| modifiers
(nreverse $1)
;
modifiers
: modifiers modifier
(cons $2 $1)
| modifier
(list $1)
;
modifier
: STRICTFP
| VOLATILE
| TRANSIENT
| SYNCHRONIZED
| NATIVE
| FINAL
| ABSTRACT
| STATIC
| PRIVATE
| PROTECTED
| PUBLIC
;
type
: qualified_name dims_opt
(concat $1 $2)
| primitive_type dims_opt
(concat $1 $2)
;
qualified_name
: qualified_name DOT IDENTIFIER
(concat $1 $2 $3)
| IDENTIFIER
;
dims_opt
: ;;EMPTY
(identity "")
| dims
;
dims
: dims BRACK_BLOCK
(concat $1 "[]")
| BRACK_BLOCK
(identity "[]")
;
%%
;; Define the lexer for this grammar
(define-lex wisent-java-tags-lexer
"Lexical analyzer that handles Java buffers.
It ignores whitespaces, newlines and comments."
semantic-lex-ignore-whitespace
semantic-lex-ignore-newline
semantic-lex-ignore-comments
;;;; Auto-generated analyzers.
wisent-java-tags-wy--<number>-regexp-analyzer
wisent-java-tags-wy--<string>-sexp-analyzer
;; Must detect keywords before other symbols
wisent-java-tags-wy--<keyword>-keyword-analyzer
wisent-java-tags-wy--<symbol>-regexp-analyzer
wisent-java-tags-wy--<punctuation>-string-analyzer
wisent-java-tags-wy--<block>-block-analyzer
;; In theory, unicode chars should be turned into normal chars
;; and then combined into regular ascii keywords and text. This
;; analyzer just keeps these things from making the lexer go boom.
wisent-java-tags-wy--<unicode>-regexp-analyzer
;;;;
semantic-lex-default-action)
;;; java-tags.wy ends here

524
etc/grammars/js.wy Normal file
View file

@ -0,0 +1,524 @@
;;; javascript-jv.wy -- LALR grammar for Javascript
;; Copyright (C) 2005-2011 Free Software Foundation, Inc.
;; Copyright (C) 1998-2011 Ecma International.
;; Author: Joakim Verona
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; The grammar itself is transcribed from the ECMAScript Language
;; Specification published at
;;
;; http://www.ecma-international.org/publications/standards/Ecma-262.htm
;;
;; and redistributed under the following license:
;; Redistribution and use in source and binary forms, with or without
;; modification, are permitted provided that the following conditions
;; are met:
;; 1. Redistributions of source code must retain the above copyright
;; notice, this list of conditions and the following disclaimer.
;; 2. Redistributions in binary form must reproduce the above
;; copyright notice, this list of conditions and the following
;; disclaimer in the documentation and/or other materials provided
;; with the distribution.
;; 3. Neither the name of the authors nor Ecma International may be
;; used to endorse or promote products derived from this software
;; without specific prior written permission. THIS SOFTWARE IS
;; PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS OR
;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
;; ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR
;; ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
;; OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
;; USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
;; DAMAGE.
%package wisent-javascript-jv-wy
;; JAVE I prefere ecmascript-mode
%languagemode ecmascript-mode javascript-mode
;; The default goal
%start Program
;; Other Goals
%start FormalParameterList
;; with the terminals stuff, I used the javacript.y names,
;; but the wisent-java-tags.wy types
;; when possible
;; ------------------
;; Operator terminals
;; ------------------
;;define-lex-string-type-analyzer gets called with the "syntax" comment
%type <punctuation> ;;syntax "\\(\\s.\\|\\s$\\|\\s'\\)+" matchdatatype string
%token <punctuation> ASSIGN_SYMBOL "="
%token <punctuation> BITWISE_AND "&"
%token <punctuation> BITWISE_AND_EQUALS "&="
%token <punctuation> BITWISE_EXCLUSIVE_OR "^"
%token <punctuation> BITWISE_EXCLUSIVE_OR_EQUALS "^="
%token <punctuation> BITWISE_OR "|"
%token <punctuation> BITWISE_OR_EQUALS "|="
%token <punctuation> BITWISE_SHIFT_LEFT "<<"
%token <punctuation> BITWISE_SHIFT_LEFT_EQUALS "<<="
%token <punctuation> BITWISE_SHIFT_RIGHT ">>"
%token <punctuation> BITWISE_SHIFT_RIGHT_EQUALS ">>="
%token <punctuation> BITWISE_SHIFT_RIGHT_ZERO_FILL ">>>"
%token <punctuation> BITWISE_SHIFT_RIGHT_ZERO_FILL_EQUALS ">>>="
%token <punctuation> NOT_EQUAL "!="
%token <punctuation> DIV_EQUALS "/="
%token <punctuation> EQUALS "=="
%token <punctuation> GREATER_THAN ">"
%token <punctuation> GT_EQUAL ">="
%token <punctuation> LOGICAL_AND "&&"
%token <punctuation> LOGICAL_OR "||"
%token <punctuation> LOGICAL_NOT "!!"
%token <punctuation> LS_EQUAL "<="
%token <punctuation> MINUS "-"
%token <punctuation> MINUS_EQUALS "-="
%token <punctuation> MOD "%"
%token <punctuation> MOD_EQUALS "%="
%token <punctuation> MULTIPLY "*"
%token <punctuation> MULTIPLY_EQUALS "*="
%token <punctuation> PLUS "+"
%token <punctuation> PLUS_EQUALS "+="
%token <punctuation> INCREMENT "++"
%token <punctuation> DECREMENT "--"
%token <punctuation> DIV "/"
%token <punctuation> COLON ":"
%token <punctuation> COMMA ","
%token <punctuation> DOT "."
%token <punctuation> LESS_THAN "<"
%token <punctuation> LINE_TERMINATOR "\n"
%token <punctuation> SEMICOLON ";"
%token <punctuation> ONES_COMPLIMENT "~"
;; -----------------------------
;; Block & Parenthesis terminals
;; -----------------------------
%type <block> ;;syntax "\\s(\\|\\s)" matchdatatype block
%token <block> PAREN_BLOCK "(OPEN_PARENTHESIS CLOSE_PARENTHESIS)"
%token <block> BRACE_BLOCK "(START_BLOCK END_BLOCK)"
%token <block> BRACK_BLOCK "(OPEN_SQ_BRACKETS CLOSE_SQ_BRACKETS)"
%token <open-paren> OPEN_PARENTHESIS "("
%token <close-paren> CLOSE_PARENTHESIS ")"
%token <open-paren> START_BLOCK "{"
%token <close-paren> END_BLOCK "}"
%token <open-paren> OPEN_SQ_BRACKETS "["
%token <close-paren> CLOSE_SQ_BRACKETS "]"
;; -----------------
;; Keyword terminals
;; -----------------
;; Generate a keyword analyzer
%type <keyword> ;;syntax "\\(\\sw\\|\\s_\\)+" matchdatatype keyword
%keyword IF "if"
%put IF summary
"if (<expr>) <stmt> [else <stmt>] (jv)"
%keyword BREAK "break"
%put BREAK summary
"break [<label>] ;"
%keyword CONTINUE "continue"
%put CONTINUE summary
"continue [<label>] ;"
%keyword ELSE "else"
%put ELSE summary
"if (<expr>) <stmt> else <stmt>"
%keyword FOR "for"
%put FOR summary
"for ([<init-expr>]; [<expr>]; [<update-expr>]) <stmt>"
%keyword FUNCTION "function"
%put FUNCTION summary
"function declaration blah blah"
%keyword THIS "this"
%put THIS summary
"this"
%keyword RETURN "return"
%put RETURN summary
"return [<expr>] ;"
%keyword WHILE "while"
%put WHILE summary
"while (<expr>) <stmt> | do <stmt> while (<expr>);"
%keyword VOID_SYMBOL "void"
%put VOID_SYMBOL summary
"Method return type: void <name> ..."
%keyword NEW "new"
%put NEW summary
"new <objecttype> - Creates a new object."
%keyword DELETE "delete"
%put DELETE summary
"delete(<objectreference>) - Deletes the object."
%keyword VAR "var"
%put VAR summary
"var <variablename> [= value];"
%keyword WITH "with"
%put WITH summary
"with "
%keyword TYPEOF "typeof"
%put TYPEOF summary
"typeof "
%keyword IN "in"
%put IN summary
"in something"
;; -----------------
;; Literal terminals
;; -----------------
;;the .y file uses VARIABLE as IDENTIFIER, which seems a bit evil
;; it think the normal .wy convention is better than this
%type <symbol> ;;syntax "\\(\\sw\\|\\s_\\)+"
%token <symbol> VARIABLE
%type <string> ;;syntax "\\s\"" matchdatatype sexp
%token <string> STRING
%type <number> ;;syntax semantic-lex-number-expression
%token <number> NUMBER
%token FALSE
%token TRUE
%token QUERY
%token NULL_TOKEN
;;%token UNDEFINED_TOKEN
;;%token INFINITY
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; associativity and stuff
%left PLUS MINUS
%left MULTIPLY DIV MOD
%nonassoc FALSE
%nonassoc HIGHER_THAN_FALSE
%nonassoc ELSE
%nonassoc LOWER_THAN_CLOSE_PARENTHESIS
%nonassoc CLOSE_PARENTHESIS
%%
Program : SourceElement
;
SourceElement : Statement
| FunctionDeclaration
;
Statement : Block
| VariableStatement
| EmptyStatement
| ExpressionStatement
| IfStatement
| IterationExpression
| ContinueStatement
| BreakStatement
| ReturnStatement
| WithStatement
;
FunctionDeclaration : FUNCTION VARIABLE FormalParameterListBlock Block
(FUNCTION-TAG $2 nil $3)
;
FormalParameterListBlock : PAREN_BLOCK
(EXPANDFULL $1 FormalParameterList)
;
FormalParameterList: OPEN_PARENTHESIS
()
| VARIABLE
(VARIABLE-TAG $1 nil nil)
| CLOSE_PARENTHESIS
()
| COMMA
()
;
StatementList : Statement
| StatementList Statement
;
Block : BRACE_BLOCK
;; If you want to parse the body of the function
;; ( EXPANDFULL $1 BlockExpand )
;
BlockExpand: START_BLOCK StatementList END_BLOCK
| START_BLOCK END_BLOCK
;
VariableStatement : VAR VariableDeclarationList SEMICOLON
(VARIABLE-TAG $2 nil nil)
;
VariableDeclarationList : VariableDeclaration
(list $1)
| VariableDeclarationList COMMA VariableDeclaration
(append $1 (list $3))
;
VariableDeclaration : VARIABLE
(append (list $1 nil) $region)
| VARIABLE Initializer
(append (cons $1 $2) $region)
;
Initializer : ASSIGN_SYMBOL AssignmentExpression
(list $2)
;
EmptyStatement : SEMICOLON
;
ExpressionStatement : Expression SEMICOLON
;
IfStatement : IF OPEN_PARENTHESIS Expression CLOSE_PARENTHESIS Statement %prec HIGHER_THAN_FALSE
| IF OPEN_PARENTHESIS Expression CLOSE_PARENTHESIS Statement ELSE Statement
| IF OPEN_PARENTHESIS FALSE CLOSE_PARENTHESIS Statement
| IF OPEN_PARENTHESIS LeftHandSideExpression AssignmentOperator AssignmentExpression CLOSE_PARENTHESIS Statement
;
IterationExpression : WHILE OPEN_PARENTHESIS Expression CLOSE_PARENTHESIS Statement %prec HIGHER_THAN_FALSE
| WHILE OPEN_PARENTHESIS FALSE CLOSE_PARENTHESIS Statement
| WHILE OPEN_PARENTHESIS LeftHandSideExpression AssignmentOperator AssignmentExpression CLOSE_PARENTHESIS Statement
| FOR OPEN_PARENTHESIS OptionalExpression SEMICOLON OptionalExpression SEMICOLON OptionalExpression CLOSE_PARENTHESIS Statement
| FOR OPEN_PARENTHESIS VAR VariableDeclarationList SEMICOLON OptionalExpression SEMICOLON OptionalExpression CLOSE_PARENTHESIS Statement
| FOR OPEN_PARENTHESIS LeftHandSideExpression IN Expression CLOSE_PARENTHESIS Statement
| FOR OPEN_PARENTHESIS VAR VARIABLE OptionalInitializer IN Expression CLOSE_PARENTHESIS Statement
;
ContinueStatement : CONTINUE SEMICOLON
;
;;JAVE break needs labels
BreakStatement : BREAK SEMICOLON
;; | BREAK identifier SEMICOLON
;
ReturnStatement : RETURN Expression SEMICOLON
| RETURN SEMICOLON
;
WithStatement : WITH OPEN_PARENTHESIS Expression CLOSE_PARENTHESIS Statement
;
OptionalInitializer : Initializer
|
;
PrimaryExpression : THIS
| VARIABLE
| NUMBER
| STRING
| NULL_TOKEN
| TRUE
| FALSE
| OPEN_PARENTHESIS Expression CLOSE_PARENTHESIS
;
MemberExpression : PrimaryExpression
| MemberExpression OPEN_SQ_BRACKETS Expression CLOSE_SQ_BRACKETS
| MemberExpression DOT VARIABLE
| NEW MemberExpression Arguments
;
NewExpression : MemberExpression
| NEW NewExpression
;
CallExpression : MemberExpression Arguments
| CallExpression Arguments
| CallExpression OPEN_SQ_BRACKETS Expression CLOSE_SQ_BRACKETS
| CallExpression DOT VARIABLE
;
Arguments : OPEN_PARENTHESIS CLOSE_PARENTHESIS
| OPEN_PARENTHESIS ArgumentList CLOSE_PARENTHESIS
;
ArgumentList : AssignmentExpression
| ArgumentList COMMA AssignmentExpression
;
LeftHandSideExpression : NewExpression
| CallExpression
;
PostfixExpression : LeftHandSideExpression
| LeftHandSideExpression INCREMENT
| LeftHandSideExpression DECREMENT
;
UnaryExpression : PostfixExpression
| DELETE UnaryExpression
| VOID_SYMBOL UnaryExpression
| TYPEOF UnaryExpression
| INCREMENT UnaryExpression
| DECREMENT UnaryExpression
| PLUS UnaryExpression
| MINUS UnaryExpression
| ONES_COMPLIMENT UnaryExpression
| LOGICAL_NOT UnaryExpression
;
MultiplicativeExpression : UnaryExpression
| MultiplicativeExpression MULTIPLY UnaryExpression
| MultiplicativeExpression DIV UnaryExpression
| MultiplicativeExpression MOD UnaryExpression
;
AdditiveExpression : MultiplicativeExpression
| AdditiveExpression PLUS MultiplicativeExpression
| AdditiveExpression MINUS MultiplicativeExpression
;
ShiftExpression : AdditiveExpression
| ShiftExpression BITWISE_SHIFT_LEFT AdditiveExpression
| ShiftExpression BITWISE_SHIFT_RIGHT AdditiveExpression
| ShiftExpression BITWISE_SHIFT_RIGHT_ZERO_FILL AdditiveExpression
;
RelationalExpression : ShiftExpression
| RelationalExpression LESS_THAN ShiftExpression
| RelationalExpression GREATER_THAN ShiftExpression
| RelationalExpression LS_EQUAL ShiftExpression
| RelationalExpression GT_EQUAL ShiftExpression
;
EqualityExpression : RelationalExpression
| EqualityExpression EQUALS RelationalExpression
| EqualityExpression NOT_EQUAL RelationalExpression
;
BitwiseANDExpression : EqualityExpression
| BitwiseANDExpression BITWISE_AND EqualityExpression
;
BitwiseXORExpression : BitwiseANDExpression
| BitwiseXORExpression BITWISE_EXCLUSIVE_OR BitwiseANDExpression
;
BitwiseORExpression : BitwiseXORExpression
| BitwiseORExpression BITWISE_OR BitwiseXORExpression
;
LogicalANDExpression : BitwiseORExpression
| LogicalANDExpression LOGICAL_AND BitwiseORExpression
;
LogicalORExpression : LogicalANDExpression
| LogicalORExpression LOGICAL_OR LogicalANDExpression
;
ConditionalExpression : LogicalORExpression
| LogicalORExpression QUERY AssignmentExpression COLON AssignmentExpression
;
AssignmentExpression : ConditionalExpression
| LeftHandSideExpression AssignmentOperator AssignmentExpression %prec LOWER_THAN_CLOSE_PARENTHESIS
;
AssignmentOperator : ASSIGN_SYMBOL
| MULTIPLY_EQUALS
| DIV_EQUALS
| MOD_EQUALS
| PLUS_EQUALS
| MINUS_EQUALS
| BITWISE_SHIFT_LEFT_EQUALS
| BITWISE_SHIFT_RIGHT_EQUALS
| BITWISE_SHIFT_RIGHT_ZERO_FILL_EQUALS
| BITWISE_AND_EQUALS
| BITWISE_EXCLUSIVE_OR_EQUALS
| BITWISE_OR_EQUALS
;
Expression : AssignmentExpression
| Expression COMMA AssignmentExpression
;
OptionalExpression : Expression
|
;
%%
;;here something like:
;;(define-lex wisent-java-tags-lexer
;; should go
(define-lex javascript-lexer-jv
"javascript thingy"
;;std stuff
semantic-lex-ignore-whitespace
semantic-lex-ignore-newline
semantic-lex-ignore-comments
;;stuff generated from the wy file(one for each "type" declaration)
wisent-javascript-jv-wy--<number>-regexp-analyzer
wisent-javascript-jv-wy--<string>-sexp-analyzer
wisent-javascript-jv-wy--<keyword>-keyword-analyzer
wisent-javascript-jv-wy--<symbol>-regexp-analyzer
wisent-javascript-jv-wy--<punctuation>-string-analyzer
wisent-javascript-jv-wy--<block>-block-analyzer
;;;;more std stuff
semantic-lex-default-action
)

168
etc/grammars/make.by Normal file
View file

@ -0,0 +1,168 @@
;;; make.by -- BY notation for Makefiles.
;; Copyright (C) 1999-2011 Free Software Foundation, Inc.
;;
;; Author: Eric M. Ludlam <zappo@gnu.org>
;; David Ponce <david@dponce.com>
;; Klaus Berndl <klaus.berndl@sdm.de>
;;
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
%package semantic-make-by
%languagemode makefile-mode
%start Makefile
;; This was always a test case.
%quotemode backquote
%token IF "if"
%token IFDEF "ifdef"
%token IFNDEF "ifndef"
%token IFEQ "ifeq"
%token IFNEQ "ifneq"
%token ELSE "else"
%token ENDIF "endif"
%token INCLUDE "include"
%put { IF ELSE ENDIF } summary "Conditional: if (expression) ... else ... endif"
%put IFDEF summary "Conditional: ifdef (expression) ... else ... endif"
%put IFNDEF summary "Conditional: ifndef (expression) ... else ... endif"
%put IFEQ summary "Conditional: ifeq (expression) ... else ... endif"
%put IFNEQ summary "Conditional: ifneq (expression) ... else ... endif"
%put INCLUDE summary "Macro: include filename1 filename2 ..."
%token <punctuation> COLON "\\`[:]\\'"
%token <punctuation> PLUS "\\`[+]\\'"
%token <punctuation> EQUAL "\\`[=]\\'"
%token <punctuation> DOLLAR "\\`[$]\\'"
%token <punctuation> BACKSLASH "\\`[\\]\\'"
%%
Makefile : bol newline (nil)
| bol variable
( ,@$2 )
| bol rule
( ,@$2 )
| bol conditional
( ,@$2 )
| bol include
( ,@$2 )
| whitespace ( nil )
| newline ( nil )
;
variable: symbol opt-whitespace equals opt-whitespace element-list
(VARIABLE-TAG ,$1 nil ,$5)
;
rule: targets opt-whitespace colons opt-whitespace element-list commands
(FUNCTION-TAG ,$1 nil ,$5)
;
targets: target opt-whitespace targets
( (car ,$1) (car ,@$3) )
| target
( (car ,$1) )
;
target: sub-target target
( (concat (car ,$1) (car ,@$3) ) )
| sub-target
( (car ,$1) )
;
sub-target: symbol
| string
| varref
;
conditional: IF some-whitespace symbol newline
( nil )
| IFDEF some-whitespace symbol newline
( nil )
| IFNDEF some-whitespace symbol newline
( nil )
| IFEQ some-whitespace expression newline
( nil )
| IFNEQ some-whitespace expression newline
( nil )
| ELSE newline
( nil )
| ENDIF newline
( nil )
;
expression : semantic-list
;
include: INCLUDE some-whitespace element-list
(INCLUDE-TAG ,$3 nil)
;
equals: COLON EQUAL ()
| PLUS EQUAL ()
| EQUAL ()
;
colons: COLON COLON ()
| COLON ()
;
element-list: elements newline
( ,@$1 )
;
elements: element some-whitespace elements
( ,@$1 ,@$3 )
| element
( ,@$1 )
| ;;EMPTY
;
element: sub-element element
( (concat (car ,$1) (car ,$2)) )
| ;;EMPTY
;
sub-element: symbol
| string
| punctuation
| semantic-list
( (buffer-substring-no-properties
(identity start) (identity end)) )
;
varref: DOLLAR semantic-list
( (buffer-substring-no-properties (identity start) (identity end)) )
;
commands: bol shell-command newline commands
( ,$1 ,@$2 )
| ;;EMPTY
( )
;
opt-whitespace : some-whitespace ( nil )
| ;;EMPTY
;
some-whitespace : whitespace some-whitespace (nil)
| whitespace (nil)
;
;;; make.by ends here

1132
etc/grammars/python.wy Normal file

File diff suppressed because it is too large Load diff

84
etc/grammars/scheme.by Normal file
View file

@ -0,0 +1,84 @@
;;; scheme.by -- Scheme BNF language specification
;; Copyright (C) 2001-2011 Free Software Foundation, Inc.
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
%package semantic-scm-by
%languagemode scheme-mode
%start scheme
%token DEFINE "define"
%token DEFINE-MODULE "define-module"
%token LOAD "load"
%put DEFINE summary "Function: (define symbol expression)"
%put DEFINE-MODULE summary "Function: (define-module (name arg1 ...)) "
%put LOAD summary "Function: (load \"filename\")"
%token <open-paren> OPENPAREN "("
%token <close-paren> CLOSEPAREN ")"
%%
scheme : semantic-list
(EXPAND $1 scheme-list)
;
scheme-list : OPENPAREN scheme-in-list CLOSEPAREN
( ,$2 )
;
scheme-in-list: DEFINE symbol expression
(VARIABLE-TAG $2 nil $3 )
| DEFINE name-args opt-doc sequence
(FUNCTION-TAG (car ,$2) nil (cdr ,$2) )
| DEFINE-MODULE name-args
(PACKAGE-TAG (nth (length $2) $2 ) nil)
| LOAD string
(INCLUDE-TAG (file-name-nondirectory (read $2)) (read $2) )
| symbol
(CODE-TAG $1 nil)
;
name-args: semantic-list
(EXPAND $1 name-arg-expand)
;
name-arg-expand : open-paren name-arg-expand
( ,$2 )
| symbol name-arg-expand
( ,(cons $1 ,$2) )
| ;; EMPTY
( )
;
opt-doc : string
| ;; EMPTY
;
sequence : expression sequence
| expression
;
expression : symbol
| semantic-list
| string
| number
;
;;; scheme.by ends here

View file

@ -0,0 +1,235 @@
;;; srecode-template.wy --- Semantic Recoder Template parser
;; Copyright (C) 2005-2011 Free Software Foundation, Inc.
;; Author: Eric Ludlam <zappo@gnu.org>
;; Keywords: syntax
;; X-RCS: $Id: srecode-template.wy,v 1.10 2009-01-09 23:01:54 zappo Exp $
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;; Parser for the Semantic Recoder template language
;;
;; Semantic Recoder templates are based on Google Templates
;; and are at the bottom of the Semantic Recoder API.
%languagemode srecode-mode
%start template_file
;;; KEYWORDS
%type <keyword>
%keyword SET "set"
%put SET summary "set <name> <value>"
%keyword SHOW "show"
%put SHOW summary "show <name> ; to show a section"
%keyword MACRO "macro"
%put MACRO summary "... macro \"string\" ..."
%keyword CONTEXT "context"
%put CONTEXT summary "context <name>"
%keyword TEMPLATE "template"
%put TEMPLATE summary "template <name>\\n <template definition>"
%keyword SECTIONDICTIONARY "sectiondictionary"
%put SECTIONDICTIONARY summary "sectiondictionary <name>\\n <dictionary entries>"
%keyword PROMPT "prompt"
%keyword DEFAULT "default"
%keyword DEFAULTMACRO "defaultmacro"
%keyword READ "read"
%put { PROMPT DEFAULT DEFAULTMACRO READ } summary "prompt <symbol> \"Describe Symbol: \" [default[macro] <lispsym>|\"valuetext\"] [read <lispsym>]"
%keyword BIND "bind"
%put BIND summary "bind \"<letter>\""
;;; Punctuation Types
%type <punctuation> syntax "\\s.+"
%type <newline>
%token <newline> newline
%token <separator> TEMPLATE_BLOCK "^----"
;;; Bland default types
%type <property> ":\\(\\w\\|\\s_\\)*"
%token <property> property
%type <symbol>
%token <symbol> symbol
%type <string>
%token <string> string
%type <number>
%token <number> number
%%
template_file
: newline ( )
| context
| prompt
| variable
| template
;
context
: CONTEXT symbol newline
(TAG $2 'context)
;
prompt
: PROMPT symbol string opt-default-fcn opt-read-fcn newline
(TAG $2 'prompt :text (read $3) :default $4 :read $5)
;
opt-default-fcn
: DEFAULT symbol
(progn (read $2))
| DEFAULT string
(progn (read $2))
| DEFAULTMACRO string
(progn (cons 'macro (read $2)))
| ()
;
opt-read-fcn
: READ symbol
(progn (read $2))
| ()
;
variable
: SET symbol insertable-string-list newline
(VARIABLE-TAG $2 nil $3)
| SHOW symbol newline
(VARIABLE-TAG $2 nil t)
;
insertable-string-list
: insertable-string
(list $1)
| insertable-string-list insertable-string
(append $1 (list $2))
;
insertable-string
: string
(read $1)
| MACRO string
(cons 'macro (read $2))
;
template
: TEMPLATE templatename opt-dynamic-arguments newline
opt-string
opt-section-dictionaries
TEMPLATE_BLOCK newline
opt-bind
(FUNCTION-TAG $2 nil $3 :documentation $5 :code $7
:dictionaries $6 :binding $9 )
;
templatename
: symbol
| PROMPT
| CONTEXT
| TEMPLATE
| DEFAULT
| MACRO
| DEFAULTMACRO
| READ
| SET
;
opt-dynamic-arguments
: property opt-dynamic-arguments
(cons $1 $2)
| ()
;
opt-string
: string newline
( read $1 )
| ()
;
opt-section-dictionaries
: () ;; EMPTY
| section-dictionary-list
;
section-dictionary-list
: one-section-dictionary
(list $1)
| section-dictionary-list one-section-dictionary
(append $1 (list $2))
;
one-section-dictionary
: SECTIONDICTIONARY string newline
variable-list
(cons (read $2) $4)
;
variable-list
: variable
(EXPANDTAG $1)
| variable-list variable
(append $1 (EXPANDTAG $2))
;
opt-bind
: BIND string newline
( read $2 )
| ()
;
%%
(define-lex-simple-regex-analyzer srecode-template-property-analyzer
"Detect and create a dynamic argument properties."
":\\(\\w\\|\\s_\\)*" 'property 0)
(define-lex-regex-analyzer srecode-template-separator-block
"Detect and create a template quote block."
"^----\n"
(semantic-lex-push-token
(semantic-lex-token
'TEMPLATE_BLOCK
(match-end 0)
(semantic-lex-unterminated-syntax-protection 'TEMPLATE_BLOCK
(goto-char (match-end 0))
(re-search-forward "^----$")
(match-beginning 0))))
(setq semantic-lex-end-point (point)))
(define-lex wisent-srecode-template-lexer
"Lexical analyzer that handles SRecode Template buffers.
It ignores whitespace, newlines and comments."
semantic-lex-newline
semantic-lex-ignore-whitespace
semantic-lex-ignore-newline
semantic-lex-ignore-comments
srecode-template-separator-block
srecode-template-wy--<keyword>-keyword-analyzer
srecode-template-property-analyzer
srecode-template-wy--<symbol>-regexp-analyzer
srecode-template-wy--<number>-regexp-analyzer
srecode-template-wy--<string>-sexp-analyzer
srecode-template-wy--<punctuation>-string-analyzer
semantic-lex-default-action
)
;;; wisent-dot.wy ends here

View file

@ -0,0 +1,542 @@
;;; wisent-grammar.el --- Wisent's input grammar mode
;; Copyright (C) 2002-2011 Free Software Foundation, Inc.
;;
;; Author: David Ponce <david@dponce.com>
;; Maintainer: David Ponce <david@dponce.com>
;; Created: 26 Aug 2002
;; Keywords: syntax
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;; Major mode for editing Wisent's input grammar (.wy) files.
;;; Code:
(require 'semantic)
(require 'semantic/grammar)
(require 'semantic/find)
(require 'semantic/lex)
(require 'semantic/wisent)
(require 'semantic/bovine)
(defsubst wisent-grammar-region-placeholder (symb)
"Given a $N placeholder symbol in SYMB, return a $regionN symbol.
Return nil if $N is not a valid placeholder symbol."
(let ((n (symbol-name symb)))
(if (string-match "^[$]\\([1-9][0-9]*\\)$" n)
(intern (concat "$region" (match-string 1 n))))))
(defun wisent-grammar-EXPAND (symb nonterm)
"Expand call to EXPAND grammar macro.
Return the form to parse from within a nonterminal.
SYMB is a $I placeholder symbol that gives the bounds of the area to
parse.
NONTERM is the nonterminal symbol to start with."
(unless (member nonterm (semantic-grammar-start))
(error "EXPANDFULL macro called with %s, but not used with %%start"
nonterm))
(let (($ri (wisent-grammar-region-placeholder symb)))
(if $ri
`(semantic-bovinate-from-nonterminal
(car ,$ri) (cdr ,$ri) ',nonterm)
(error "Invalid form (EXPAND %s %s)" symb nonterm))))
(defun wisent-grammar-EXPANDFULL (symb nonterm)
"Expand call to EXPANDFULL grammar macro.
Return the form to recursively parse an area.
SYMB is a $I placeholder symbol that gives the bounds of the area.
NONTERM is the nonterminal symbol to start with."
(unless (member nonterm (semantic-grammar-start))
(error "EXPANDFULL macro called with %s, but not used with %%start"
nonterm))
(let (($ri (wisent-grammar-region-placeholder symb)))
(if $ri
`(semantic-parse-region
(car ,$ri) (cdr ,$ri) ',nonterm 1)
(error "Invalid form (EXPANDFULL %s %s)" symb nonterm))))
(defun wisent-grammar-TAG (name class &rest attributes)
"Expand call to TAG grammar macro.
Return the form to create a generic semantic tag.
See the function `semantic-tag' for the meaning of arguments NAME,
CLASS and ATTRIBUTES."
`(wisent-raw-tag
(semantic-tag ,name ,class ,@attributes)))
(defun wisent-grammar-VARIABLE-TAG (name type default-value &rest attributes)
"Expand call to VARIABLE-TAG grammar macro.
Return the form to create a semantic tag of class variable.
See the function `semantic-tag-new-variable' for the meaning of
arguments NAME, TYPE, DEFAULT-VALUE and ATTRIBUTES."
`(wisent-raw-tag
(semantic-tag-new-variable ,name ,type ,default-value ,@attributes)))
(defun wisent-grammar-FUNCTION-TAG (name type arg-list &rest attributes)
"Expand call to FUNCTION-TAG grammar macro.
Return the form to create a semantic tag of class function.
See the function `semantic-tag-new-function' for the meaning of
arguments NAME, TYPE, ARG-LIST and ATTRIBUTES."
`(wisent-raw-tag
(semantic-tag-new-function ,name ,type ,arg-list ,@attributes)))
(defun wisent-grammar-TYPE-TAG (name type members parents &rest attributes)
"Expand call to TYPE-TAG grammar macro.
Return the form to create a semantic tag of class type.
See the function `semantic-tag-new-type' for the meaning of arguments
NAME, TYPE, MEMBERS, PARENTS and ATTRIBUTES."
`(wisent-raw-tag
(semantic-tag-new-type ,name ,type ,members ,parents ,@attributes)))
(defun wisent-grammar-INCLUDE-TAG (name system-flag &rest attributes)
"Expand call to INCLUDE-TAG grammar macro.
Return the form to create a semantic tag of class include.
See the function `semantic-tag-new-include' for the meaning of
arguments NAME, SYSTEM-FLAG and ATTRIBUTES."
`(wisent-raw-tag
(semantic-tag-new-include ,name ,system-flag ,@attributes)))
(defun wisent-grammar-PACKAGE-TAG (name detail &rest attributes)
"Expand call to PACKAGE-TAG grammar macro.
Return the form to create a semantic tag of class package.
See the function `semantic-tag-new-package' for the meaning of
arguments NAME, DETAIL and ATTRIBUTES."
`(wisent-raw-tag
(semantic-tag-new-package ,name ,detail ,@attributes)))
(defun wisent-grammar-CODE-TAG (name detail &rest attributes)
"Expand call to CODE-TAG grammar macro.
Return the form to create a semantic tag of class code.
See the function `semantic-tag-new-code' for the meaning of arguments
NAME, DETAIL and ATTRIBUTES."
`(wisent-raw-tag
(semantic-tag-new-code ,name ,detail ,@attributes)))
(defun wisent-grammar-ALIAS-TAG (name aliasclass definition &rest attributes)
"Expand call to ALIAS-TAG grammar macro.
Return the form to create a semantic tag of class alias.
See the function `semantic-tag-new-alias' for the meaning of arguments
NAME, ALIASCLASS, DEFINITION and ATTRIBUTES."
`(wisent-raw-tag
(semantic-tag-new-alias ,name ,aliasclass ,definition ,@attributes)))
(defun wisent-grammar-EXPANDTAG (raw-tag)
"Expand call to EXPANDTAG grammar macro.
Return the form to produce a list of cooked tags from raw form of
Semantic tag RAW-TAG."
`(wisent-cook-tag ,raw-tag))
(defun wisent-grammar-AST-ADD (ast &rest nodes)
"Expand call to AST-ADD grammar macro.
Return the form to update the abstract syntax tree AST with NODES.
See also the function `semantic-ast-add'."
`(semantic-ast-add ,ast ,@nodes))
(defun wisent-grammar-AST-PUT (ast &rest nodes)
"Expand call to AST-PUT grammar macro.
Return the form to update the abstract syntax tree AST with NODES.
See also the function `semantic-ast-put'."
`(semantic-ast-put ,ast ,@nodes))
(defun wisent-grammar-AST-GET (ast node)
"Expand call to AST-GET grammar macro.
Return the form to get, from the abstract syntax tree AST, the value
of NODE.
See also the function `semantic-ast-get'."
`(semantic-ast-get ,ast ,node))
(defun wisent-grammar-AST-GET1 (ast node)
"Expand call to AST-GET1 grammar macro.
Return the form to get, from the abstract syntax tree AST, the first
value of NODE.
See also the function `semantic-ast-get1'."
`(semantic-ast-get1 ,ast ,node))
(defun wisent-grammar-AST-GET-STRING (ast node)
"Expand call to AST-GET-STRING grammar macro.
Return the form to get, from the abstract syntax tree AST, the value
of NODE as a string.
See also the function `semantic-ast-get-string'."
`(semantic-ast-get-string ,ast ,node))
(defun wisent-grammar-AST-MERGE (ast1 ast2)
"Expand call to AST-MERGE grammar macro.
Return the form to merge the abstract syntax trees AST1 and AST2.
See also the function `semantic-ast-merge'."
`(semantic-ast-merge ,ast1 ,ast2))
(defun wisent-grammar-SKIP-BLOCK (&optional symb)
"Expand call to SKIP-BLOCK grammar macro.
Return the form to skip a parenthesized block.
Optional argument SYMB is a $I placeholder symbol that gives the
bounds of the block to skip. By default, skip the block at `$1'.
See also the function `wisent-skip-block'."
(let ($ri)
(when symb
(unless (setq $ri (wisent-grammar-region-placeholder symb))
(error "Invalid form (SKIP-BLOCK %s)" symb)))
`(wisent-skip-block ,$ri)))
(defun wisent-grammar-SKIP-TOKEN ()
"Expand call to SKIP-TOKEN grammar macro.
Return the form to skip the lookahead token.
See also the function `wisent-skip-token'."
`(wisent-skip-token))
(defun wisent-grammar-assocs ()
"Return associativity and precedence level definitions."
(mapcar
#'(lambda (tag)
(cons (intern (semantic-tag-name tag))
(mapcar #'semantic-grammar-item-value
(semantic-tag-get-attribute tag :value))))
(semantic-find-tags-by-class 'assoc (current-buffer))))
(defun wisent-grammar-terminals ()
"Return the list of terminal symbols.
Keep order of declaration in the WY file without duplicates."
(let (terms)
(mapcar
#'(lambda (tag)
(mapcar #'(lambda (name)
(add-to-list 'terms (intern name)))
(cons (semantic-tag-name tag)
(semantic-tag-get-attribute tag :rest))))
(semantic--find-tags-by-function
#'(lambda (tag)
(memq (semantic-tag-class tag) '(token keyword)))
(current-buffer)))
(nreverse terms)))
;; Cache of macro definitions currently in use.
(defvar wisent--grammar-macros nil)
(defun wisent-grammar-expand-macros (expr)
"Expand expression EXPR into a form without grammar macros.
Return the expanded expression."
(if (or (atom expr) (semantic-grammar-quote-p (car expr)))
expr ;; Just return atom or quoted expression.
(let* ((expr (mapcar 'wisent-grammar-expand-macros expr))
(macro (assq (car expr) wisent--grammar-macros)))
(if macro ;; Expand Semantic built-in.
(apply (cdr macro) (cdr expr))
expr))))
(defun wisent-grammar-nonterminals ()
"Return the list form of nonterminal definitions."
(let ((nttags (semantic-find-tags-by-class
'nonterminal (current-buffer)))
;; Setup the cache of macro definitions.
(wisent--grammar-macros (semantic-grammar-macros))
rltags nterms rules rule elems elem actn sexp prec)
(while nttags
(setq rltags (semantic-tag-components (car nttags))
rules nil)
(while rltags
(setq elems (semantic-tag-get-attribute (car rltags) :value)
prec (semantic-tag-get-attribute (car rltags) :prec)
actn (semantic-tag-get-attribute (car rltags) :expr)
rule nil)
(when elems ;; not an EMPTY rule
(while elems
(setq elem (car elems)
elems (cdr elems))
(setq elem (if (consp elem) ;; mid-rule action
(wisent-grammar-expand-macros (read (car elem)))
(semantic-grammar-item-value elem)) ;; item
rule (cons elem rule)))
(setq rule (nreverse rule)))
(if prec
(setq prec (vector (semantic-grammar-item-value prec))))
(if actn
(setq sexp (wisent-grammar-expand-macros (read actn))))
(setq rule (if actn
(if prec
(list rule prec sexp)
(list rule sexp))
(if prec
(list rule prec)
(list rule))))
(setq rules (cons rule rules)
rltags (cdr rltags)))
(setq nterms (cons (cons (intern (semantic-tag-name (car nttags)))
(nreverse rules))
nterms)
nttags (cdr nttags)))
(nreverse nterms)))
(defun wisent-grammar-grammar ()
"Return Elisp form of the grammar."
(let* ((terminals (wisent-grammar-terminals))
(nonterminals (wisent-grammar-nonterminals))
(assocs (wisent-grammar-assocs)))
(cons terminals (cons assocs nonterminals))))
(defun wisent-grammar-parsetable-builder ()
"Return the value of the parser table."
`(progn
;; Ensure that the grammar [byte-]compiler is available.
(eval-when-compile (require 'semantic/wisent/comp))
(wisent-compile-grammar
',(wisent-grammar-grammar)
',(semantic-grammar-start))))
(defun wisent-grammar-setupcode-builder ()
"Return the parser setup code."
(format
"(semantic-install-function-overrides\n\
'((parse-stream . wisent-parse-stream)))\n\
(setq semantic-parser-name \"LALR\"\n\
semantic--parse-table %s\n\
semantic-debug-parser-source %S\n\
semantic-flex-keywords-obarray %s\n\
semantic-lex-types-obarray %s)\n\
;; Collect unmatched syntax lexical tokens\n\
(semantic-make-local-hook 'wisent-discarding-token-functions)\n\
(add-hook 'wisent-discarding-token-functions\n\
'wisent-collect-unmatched-syntax nil t)"
(semantic-grammar-parsetable)
(buffer-name)
(semantic-grammar-keywordtable)
(semantic-grammar-tokentable)))
(defvar wisent-grammar-menu
'("WY Grammar"
["LALR Compiler Verbose" wisent-toggle-verbose-flag
:style toggle :active (boundp 'wisent-verbose-flag)
:selected (and (boundp 'wisent-verbose-flag)
wisent-verbose-flag)]
)
"WY mode specific grammar menu.
Menu items are appended to the common grammar menu.")
(define-derived-mode wisent-grammar-mode semantic-grammar-mode "WY"
"Major mode for editing Wisent grammars."
(semantic-grammar-setup-menu wisent-grammar-menu)
(semantic-install-function-overrides
'((grammar-parsetable-builder . wisent-grammar-parsetable-builder)
(grammar-setupcode-builder . wisent-grammar-setupcode-builder)
)))
(add-to-list 'auto-mode-alist '("\\.wy$" . wisent-grammar-mode))
(defvar-mode-local wisent-grammar-mode semantic-grammar-macros
'(
(ASSOC . semantic-grammar-ASSOC)
(EXPAND . wisent-grammar-EXPAND)
(EXPANDFULL . wisent-grammar-EXPANDFULL)
(TAG . wisent-grammar-TAG)
(VARIABLE-TAG . wisent-grammar-VARIABLE-TAG)
(FUNCTION-TAG . wisent-grammar-FUNCTION-TAG)
(TYPE-TAG . wisent-grammar-TYPE-TAG)
(INCLUDE-TAG . wisent-grammar-INCLUDE-TAG)
(PACKAGE-TAG . wisent-grammar-PACKAGE-TAG)
(EXPANDTAG . wisent-grammar-EXPANDTAG)
(CODE-TAG . wisent-grammar-CODE-TAG)
(ALIAS-TAG . wisent-grammar-ALIAS-TAG)
(AST-ADD . wisent-grammar-AST-ADD)
(AST-PUT . wisent-grammar-AST-PUT)
(AST-GET . wisent-grammar-AST-GET)
(AST-GET1 . wisent-grammar-AST-GET1)
(AST-GET-STRING . wisent-grammar-AST-GET-STRING)
(AST-MERGE . wisent-grammar-AST-MERGE)
(SKIP-BLOCK . wisent-grammar-SKIP-BLOCK)
(SKIP-TOKEN . wisent-grammar-SKIP-TOKEN)
)
"Semantic grammar macros used in wisent grammars.")
(defvar wisent-make-parsers--emacs-license
";; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.")
(defvar wisent-make-parsers--python-license
";; It is derived in part from the Python grammar, used under the
;; following license:
;;
;; PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
;; --------------------------------------------
;; 1. This LICENSE AGREEMENT is between the Python Software Foundation
;; (\"PSF\"), and the Individual or Organization (\"Licensee\") accessing
;; and otherwise using this software (\"Python\") in source or binary
;; form and its associated documentation.
;;
;; 2. Subject to the terms and conditions of this License Agreement,
;; PSF hereby grants Licensee a nonexclusive, royalty-free, world-wide
;; license to reproduce, analyze, test, perform and/or display
;; publicly, prepare derivative works, distribute, and otherwise use
;; Python alone or in any derivative version, provided, however, that
;; PSF's License Agreement and PSF's notice of copyright, i.e.,
;; \"Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
;; 2009, 2010 Python Software Foundation; All Rights Reserved\" are
;; retained in Python alone or in any derivative version prepared by
;; Licensee.
;;
;; 3. In the event Licensee prepares a derivative work that is based
;; on or incorporates Python or any part thereof, and wants to make
;; the derivative work available to others as provided herein, then
;; Licensee hereby agrees to include in any such work a brief summary
;; of the changes made to Python.
;;
;; 4. PSF is making Python available to Licensee on an \"AS IS\"
;; basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
;; IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND
;; DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
;; FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT
;; INFRINGE ANY THIRD PARTY RIGHTS.
;;
;; 5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
;; FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS A
;; RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON, OR
;; ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
;;
;; 6. This License Agreement will automatically terminate upon a
;; material breach of its terms and conditions.
;;
;; 7. Nothing in this License Agreement shall be deemed to create any
;; relationship of agency, partnership, or joint venture between PSF
;; and Licensee. This License Agreement does not grant permission to
;; use PSF trademarks or trade name in a trademark sense to endorse or
;; promote products or services of Licensee, or any third party.
;;
;; 8. By copying, installing or otherwise using Python, Licensee
;; agrees to be bound by the terms and conditions of this License
;; Agreement.")
(defvar wisent-make-parsers--ecmascript-license
"\n;; It is derived from the grammar in the ECMAScript Language
;; Specification published at
;;
;; http://www.ecma-international.org/publications/standards/Ecma-262.htm
;;
;; and redistributed under the following license:
;;
;; Redistribution and use in source and binary forms, with or without
;; modification, are permitted provided that the following conditions
;; are met:
;;
;; 1. Redistributions of source code must retain the above copyright
;; notice, this list of conditions and the following disclaimer.
;;
;; 2. Redistributions in binary form must reproduce the above
;; copyright notice, this list of conditions and the following
;; disclaimer in the documentation and/or other materials provided
;; with the distribution.
;;
;; 3. Neither the name of the authors nor Ecma International may be
;; used to endorse or promote products derived from this software
;; without specific prior written permission. THIS SOFTWARE IS
;; PROVIDED BY THE ECMA INTERNATIONAL \"AS IS\" AND ANY EXPRESS OR
;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
;; ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR
;; ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
;; OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
;; USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
;; DAMAGE.")
(defvar wisent-make-parsers--parser-file-name
`(("semantic-grammar-wy.el"
"semantic/grammar-wy")
("srecode-template-wy.el"
"srecode/srt-wy")
("wisent-javascript-jv-wy.el"
"semantic/wisent/js-wy"
"Copyright (C) 1998-2011 Ecma International"
,wisent-make-parsers--ecmascript-license)
("wisent-java-tags-wy.el"
"semantic/wisent/javat-wy")
("wisent-python-wy.el"
"semantic/wisent/python-wy"
"Copyright (C) 2001-2010 Python Software Foundation"
,wisent-make-parsers--python-license)))
(defun wisent-make-parsers ()
"Generate Emacs' built-in Wisent-based parser files."
(semantic-mode 1)
;; Loop through each .wy file in current directory, and run
;; `semantic-grammar-batch-build-one-package' to build the grammar.
(dolist (f (directory-files default-directory nil ".wy$"))
(let ((packagename
(condition-case err
(with-current-buffer (find-file-noselect f)
(semantic-grammar-create-package))
(error (message "%s" (error-message-string err)) nil)))
output-data)
(when (setq output-data (assoc packagename wisent-make-parsers--parser-file-name))
(let ((require-name (nth 1 output-data))
(additional-copyright (nth 2 output-data))
(additional-license (nth 3 output-data))
copyright-end)
;; Touch up the generated parsers for Emacs integration.
(with-temp-buffer
(insert-file-contents packagename)
(setq buffer-file-name (expand-file-name packagename))
;; Fix copyright header:
(goto-char (point-min))
(when additional-copyright
(re-search-forward "Copyright (C).*$")
(insert "\n;; " additional-copyright))
(re-search-forward "^;; Author:")
(setq copyright-end (match-beginning 0))
(re-search-forward "^;;; Code:\n")
(delete-region copyright-end (match-end 0))
(goto-char copyright-end)
(insert wisent-make-parsers--emacs-license)
(insert "\n\n;;; Commentary:
;;
;; This file was generated from etc/grammars/"
f ".")
(when additional-license
(insert "\n" additional-license))
(insert "\n\n;;; Code:\n
\(require 'semantic/lex)\n")
(goto-char (point-min))
(delete-region (point-min) (line-end-position))
(insert ";;; " require-name
".el --- Generated parser support file")
(delete-trailing-whitespace)
(re-search-forward ";;\n(require 'semantic-lex)\n")
(delete-region (match-beginning 0) (match-end 0))
;; Fix footer:
(goto-char (point-max))
(re-search-backward "^(provide")
(delete-region (match-beginning 0) (point-max))
(goto-char (point-max))
(insert "(provide '" require-name ")\n\n")
(insert ";;; " require-name ".el ends here\n")
(let ((make-backup-files nil))
(save-buffer))))))))
;;; wisent-grammar.el ends here

View file

@ -20,8 +20,7 @@
;;; Commentary:
;;
;; This file was generated from the grammar file semantic/bovine/c.by
;; in the CEDET repository.
;; This file was generated from etc/grammars/c.by.
;;; Code:

View file

@ -20,8 +20,7 @@
;;; Commentary:
;;
;; This file was generated from the grammar file
;; semantic/bovine/make.by in the CEDET repository.
;; This file was generated from etc/grammars/make.by.
;;; Code:

View file

@ -19,8 +19,7 @@
;;; Commentary:
;;
;; This file was generated from the grammar file
;; semantic/bovine/scm.by in the CEDET repository.
;; This file was generated from etc/grammars/scm.by.
;;; Code:

View file

@ -22,8 +22,7 @@
;;; Commentary:
;;
;; This file is generated from the grammar file semantic-grammar.wy in
;; the upstream CEDET repository.
;; This file was generated from etc/grammars/grammar.wy.
;;; Code:

View file

@ -19,8 +19,7 @@
;;; Commentary:
;;
;; This file was generated from the grammar file
;; semantic/wisent/wisent-java-tags.wy in the CEDET repository.
;; This file was generated from etc/grammars/java-tags.wy.
;;; Code:

View file

@ -19,8 +19,42 @@
;;; Commentary:
;;
;; This file was generated from the grammar file
;; semantic/wisent/wisent-javascript-jv.wy in the CEDET repository.
;; This file was generated from etc/grammars/js.wy.
;;
;; It is derived from the grammar in the ECMAScript Language
;; Specification published at
;;
;; http://www.ecma-international.org/publications/standards/Ecma-262.htm
;;
;; and redistributed under the following license:
;;
;; Redistribution and use in source and binary forms, with or without
;; modification, are permitted provided that the following conditions
;; are met:
;;
;; 1. Redistributions of source code must retain the above copyright
;; notice, this list of conditions and the following disclaimer.
;;
;; 2. Redistributions in binary form must reproduce the above
;; copyright notice, this list of conditions and the following
;; disclaimer in the documentation and/or other materials provided
;; with the distribution.
;;
;; 3. Neither the name of the authors nor Ecma International may be
;; used to endorse or promote products derived from this software
;; without specific prior written permission. THIS SOFTWARE IS
;; PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS OR
;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
;; ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR
;; ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
;; OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
;; USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
;; DAMAGE.
;;; Code:
(require 'semantic/lex)

View file

@ -19,9 +19,59 @@
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This file was generated from etc/grammars/python.wy.
;; It is derived in part from the Python grammar, used under the
;; following license:
;;
;; This file was generated from the grammar file
;; semantic/wisent/wisent-python.wy in the CEDET repository.
;; PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
;; --------------------------------------------
;; 1. This LICENSE AGREEMENT is between the Python Software Foundation
;; ("PSF"), and the Individual or Organization ("Licensee") accessing
;; and otherwise using this software ("Python") in source or binary
;; form and its associated documentation.
;;
;; 2. Subject to the terms and conditions of this License Agreement,
;; PSF hereby grants Licensee a nonexclusive, royalty-free, world-wide
;; license to reproduce, analyze, test, perform and/or display
;; publicly, prepare derivative works, distribute, and otherwise use
;; Python alone or in any derivative version, provided, however, that
;; PSF's License Agreement and PSF's notice of copyright, i.e.,
;; "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
;; 2009, 2010 Python Software Foundation; All Rights Reserved" are
;; retained in Python alone or in any derivative version prepared by
;; Licensee.
;;
;; 3. In the event Licensee prepares a derivative work that is based
;; on or incorporates Python or any part thereof, and wants to make
;; the derivative work available to others as provided herein, then
;; Licensee hereby agrees to include in any such work a brief summary
;; of the changes made to Python.
;;
;; 4. PSF is making Python available to Licensee on an "AS IS"
;; basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
;; IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND
;; DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
;; FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT
;; INFRINGE ANY THIRD PARTY RIGHTS.
;;
;; 5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
;; FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS A
;; RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON, OR
;; ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
;;
;; 6. This License Agreement will automatically terminate upon a
;; material breach of its terms and conditions.
;;
;; 7. Nothing in this License Agreement shall be deemed to create any
;; relationship of agency, partnership, or joint venture between PSF
;; and Licensee. This License Agreement does not grant permission to
;; use PSF trademarks or trade name in a trademark sense to endorse or
;; promote products or services of Licensee, or any third party.
;;
;; 8. By copying, installing or otherwise using Python, Licensee
;; agrees to be bound by the terms and conditions of this License
;; Agreement.
;;; Code:

View file

@ -18,8 +18,8 @@
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Generated from srecode-template.wy in the CEDET repository.
;;
;; This file was generated from etc/grammars/srecode-template.wy.
;;; Code: