Note obsolescence of mouse-sel.el in NEWS.
[emacs.git] / admin / grammars / srecode-template.wy
blobf38d7eaa2a1e99f81cbf731b55833af9d2f7e1dd
1 ;;; srecode-template.wy --- Semantic Recoder Template parser
3 ;; Copyright (C) 2005-2012 Free Software Foundation, Inc.
5 ;; Author: Eric Ludlam <zappo@gnu.org>
6 ;; Keywords: syntax
7 ;; X-RCS: $Id: srecode-template.wy,v 1.10 2009-01-09 23:01:54 zappo Exp $
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
24 ;;; Commentary:
26 ;; Parser for the Semantic Recoder template language
28 ;; Semantic Recoder templates are based on Google Templates
29 ;; and are at the bottom of the Semantic Recoder API.
31 %languagemode  srecode-mode
33 %start template_file
35 ;;; KEYWORDS
36 %type    <keyword>
37 %keyword SET  "set"
38 %put     SET  summary "set <name> <value>"
39 %keyword SHOW "show"
40 %put     SHOW summary "show <name>   ; to show a section"
41 %keyword MACRO "macro"
42 %put     MACRO summary "... macro \"string\" ..."
43 %keyword CONTEXT "context"
44 %put     CONTEXT summary "context <name>"
45 %keyword TEMPLATE  "template"
46 %put     TEMPLATE  summary "template <name>\\n <template definition>"
47 %keyword SECTIONDICTIONARY "sectiondictionary"
48 %put     SECTIONDICTIONARY summary "sectiondictionary <name>\\n <dictionary entries>"
49 %keyword PROMPT "prompt"
50 %keyword DEFAULT "default"
51 %keyword DEFAULTMACRO "defaultmacro"
52 %keyword READ "read"
53 %put     { PROMPT DEFAULT DEFAULTMACRO READ } summary "prompt <symbol> \"Describe Symbol: \" [default[macro] <lispsym>|\"valuetext\"] [read <lispsym>]"
54 %keyword BIND "bind"
55 %put     BIND summary "bind \"<letter>\""
57 ;;; Punctuation Types
58 %type <punctuation> syntax "\\s.+"
59 %type <newline>
60 %token <newline> newline
62 %token <separator> TEMPLATE_BLOCK "^----"
64 ;;; Bland default types
65 %type <property> ":\\(\\w\\|\\s_\\)*"
66 %token <property> property
68 %type  <symbol>
69 %token <symbol> symbol
71 %type  <string>
72 %token <string> string
74 %type  <number>
75 %token <number> number
79 template_file
80   : newline ( )
81   | context
82   | prompt
83   | variable
84   | template
85   ;
87 context
88   : CONTEXT symbol newline
89     (TAG $2 'context)
90   ;
92 prompt
93   : PROMPT symbol string opt-default-fcn opt-read-fcn newline
94     (TAG $2 'prompt :text (read $3) :default $4 :read $5)
95   ;
97 opt-default-fcn
98   : DEFAULT symbol
99     (progn (read $2))
100   | DEFAULT string
101     (progn (read $2))
102   | DEFAULTMACRO string
103     (progn (cons 'macro (read $2)))
104   | ()
105   ;
107 opt-read-fcn
108   : READ symbol
109     (progn (read $2))
110   | ()
111   ;
113 variable
114   : SET symbol insertable-string-list newline
115     (VARIABLE-TAG $2 nil $3)
116   | SHOW symbol newline
117     (VARIABLE-TAG $2 nil t)
118   ;
120 insertable-string-list
121   : insertable-string
122     (list $1)
123   | insertable-string-list insertable-string
124     (append $1 (list $2))
125   ;
127 insertable-string
128   : string
129     (read $1)
130   | MACRO string
131     (cons 'macro (read $2))
132   ;
134 template
135   : TEMPLATE templatename opt-dynamic-arguments newline
136     opt-string
137     opt-section-dictionaries
138     TEMPLATE_BLOCK newline
139     opt-bind
140     (FUNCTION-TAG $2 nil $3 :documentation $5 :code $7
141                   :dictionaries $6 :binding $9 )
142   ;
144 templatename
145   : symbol
146   | PROMPT
147   | CONTEXT
148   | TEMPLATE
149   | DEFAULT
150   | MACRO
151   | DEFAULTMACRO
152   | READ
153   | SET
154   ;
156 opt-dynamic-arguments
157   : property opt-dynamic-arguments
158     (cons $1 $2)
159   | ()
160   ;
162 opt-string
163   : string newline
164     ( read $1 )
165   | ()
166   ;
168 opt-section-dictionaries
169   : () ;; EMPTY
170   | section-dictionary-list
171   ;
173 section-dictionary-list
174   : one-section-dictionary
175     (list $1)
176   | section-dictionary-list one-section-dictionary
177     (append $1 (list $2))
178   ;
180 one-section-dictionary
181   : SECTIONDICTIONARY string newline
182     variable-list
183     (cons (read $2) $4)
184   ;
186 variable-list
187   : variable
188     (EXPANDTAG $1)
189   | variable-list variable
190     (append $1 (EXPANDTAG $2))
191   ;
193 opt-bind
194   : BIND string newline
195     ( read $2 )
196   | ()
197   ;
200 (define-lex-simple-regex-analyzer srecode-template-property-analyzer
201   "Detect and create a dynamic argument properties."
202   ":\\(\\w\\|\\s_\\)*" 'property 0)
204 (define-lex-regex-analyzer srecode-template-separator-block
205   "Detect and create a template quote block."
206   "^----\n"
207   (semantic-lex-push-token
208    (semantic-lex-token
209     'TEMPLATE_BLOCK
210     (match-end 0)
211     (semantic-lex-unterminated-syntax-protection 'TEMPLATE_BLOCK
212       (goto-char (match-end 0))
213       (re-search-forward "^----$")
214       (match-beginning 0))))
215   (setq semantic-lex-end-point (point)))
218 (define-lex wisent-srecode-template-lexer
219   "Lexical analyzer that handles SRecode Template buffers.
220 It ignores whitespace, newlines and comments."
221   semantic-lex-newline
222   semantic-lex-ignore-whitespace
223   semantic-lex-ignore-newline
224   semantic-lex-ignore-comments
225   srecode-template-separator-block
226   srecode-template-wy--<keyword>-keyword-analyzer
227   srecode-template-property-analyzer
228   srecode-template-wy--<symbol>-regexp-analyzer
229   srecode-template-wy--<number>-regexp-analyzer
230   srecode-template-wy--<string>-sexp-analyzer
231   srecode-template-wy--<punctuation>-string-analyzer
232   semantic-lex-default-action
233   )
235 ;;; wisent-dot.wy ends here