f84a414b46e8abd6810be7ceaa8544252cd5fe39
[bpt/emacs.git] / admin / grammars / srecode-template.wy
1 ;;; srecode-template.wy --- Semantic Recoder Template parser
2
3 ;; Copyright (C) 2005-2012 Free Software Foundation, Inc.
4
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 $
8
9 ;; This file is part of GNU Emacs.
10
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.
15
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.
20
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/>.
23
24 ;;; Commentary:
25 ;;
26 ;; Parser for the Semantic Recoder template language
27 ;;
28 ;; Semantic Recoder templates are based on Google Templates
29 ;; and are at the bottom of the Semantic Recoder API.
30
31 %package srecode-template-wy
32 %provide srecode/srt-wy
33
34 %languagemode srecode-mode
35
36 %start template_file
37
38 ;;; KEYWORDS
39 %type <keyword>
40 %keyword SET "set"
41 %put SET summary "set <name> <value>"
42 %keyword SHOW "show"
43 %put SHOW summary "show <name> ; to show a section"
44 %keyword MACRO "macro"
45 %put MACRO summary "... macro \"string\" ..."
46 %keyword CONTEXT "context"
47 %put CONTEXT summary "context <name>"
48 %keyword TEMPLATE "template"
49 %put TEMPLATE summary "template <name>\\n <template definition>"
50 %keyword SECTIONDICTIONARY "sectiondictionary"
51 %put SECTIONDICTIONARY summary "sectiondictionary <name>\\n <dictionary entries>"
52
53 %keyword SECTION "section"
54 %put SECTION summary
55 "section <name>\\n <dictionary entries>\\n end"
56
57 %keyword END "end"
58 %put END summary
59 "section ... end"
60
61 %keyword PROMPT "prompt"
62 %keyword DEFAULT "default"
63 %keyword DEFAULTMACRO "defaultmacro"
64 %keyword READ "read"
65 %put { PROMPT DEFAULT DEFAULTMACRO READ } summary "prompt <symbol> \"Describe Symbol: \" [default[macro] <lispsym>|\"valuetext\"] [read <lispsym>]"
66 %keyword BIND "bind"
67 %put BIND summary "bind \"<letter>\""
68
69 ;;; Punctuation Types
70 %type <punctuation> syntax "\\s.+"
71 %type <newline>
72 %token <newline> newline
73
74 %token <separator> TEMPLATE_BLOCK "^----"
75
76 ;;; Bland default types
77 %type <property> syntax ":\\(\\w\\|\\s_\\)*"
78 %token <property> property
79
80 %type <symbol>
81 %token <symbol> symbol
82
83 %type <string>
84 %token <string> string
85
86 %type <number>
87 %token <number> number
88
89 %%
90
91 template_file
92 : newline ( )
93 | context
94 | prompt
95 | variable
96 | template
97 ;
98
99 context
100 : CONTEXT symbol newline
101 (TAG $2 'context)
102 ;
103
104 prompt
105 : PROMPT symbol string opt-default-fcn opt-read-fcn newline
106 (TAG $2 'prompt :text (read $3) :default $4 :read $5)
107 ;
108
109 opt-default-fcn
110 : DEFAULT symbol
111 (progn (read $2))
112 | DEFAULT string
113 (progn (read $2))
114 | DEFAULTMACRO string
115 (progn (cons 'macro (read $2)))
116 | ()
117 ;
118
119 opt-read-fcn
120 : READ symbol
121 (progn (read $2))
122 | ()
123 ;
124
125 variable
126 : SET symbol insertable-string-list newline
127 (VARIABLE-TAG $2 nil $3)
128 | SHOW symbol newline
129 (VARIABLE-TAG $2 nil t)
130 ;
131
132 insertable-string-list
133 : insertable-string
134 (list $1)
135 | insertable-string-list insertable-string
136 (append $1 (list $2))
137 ;
138
139 insertable-string
140 : string
141 (read $1)
142 | MACRO string
143 (cons 'macro (read $2))
144 ;
145
146 template
147 : TEMPLATE templatename opt-dynamic-arguments newline
148 opt-string
149 section-dictionary-list
150 TEMPLATE_BLOCK newline
151 opt-bind
152 (FUNCTION-TAG $2 nil $3 :documentation $5 :code $7
153 :dictionaries $6 :binding $9 )
154 ;
155
156 templatename
157 : symbol
158 | PROMPT
159 | CONTEXT
160 | TEMPLATE
161 | DEFAULT
162 | MACRO
163 | DEFAULTMACRO
164 | READ
165 | SET
166 ;
167
168 opt-dynamic-arguments
169 : property opt-dynamic-arguments
170 (cons $1 $2)
171 | ()
172 ;
173
174 opt-string
175 : string newline
176 ( read $1 )
177 | ()
178 ;
179
180 section-dictionary-list
181 : ;; empty
182 ()
183 | section-dictionary-list flat-section-dictionary
184 (append $1 (list $2))
185 | section-dictionary-list section-dictionary
186 (append $1 (list $2))
187 ;
188
189 flat-section-dictionary
190 : SECTIONDICTIONARY string newline
191 flat-dictionary-entry-list
192 (cons (read $2) $4)
193 ;
194
195 flat-dictionary-entry-list
196 : ;; empty
197 ()
198 | flat-dictionary-entry-list flat-dictionary-entry
199 (append $1 $2)
200 ;
201
202 flat-dictionary-entry
203 : variable
204 (EXPANDTAG $1)
205 ;
206
207 section-dictionary
208 : SECTION string newline
209 dictionary-entry-list
210 END newline
211 (cons (read $2) $4)
212 ;
213
214 dictionary-entry-list
215 : ;; empty
216 ()
217 | dictionary-entry-list dictionary-entry
218 (append $1 $2)
219 ;
220
221 dictionary-entry
222 : variable
223 (EXPANDTAG $1)
224 | section-dictionary
225 (list $1)
226 ;
227
228 opt-bind
229 : BIND string newline
230 ( read $2 )
231 | ()
232 ;
233
234 %%
235 (define-lex-simple-regex-analyzer srecode-template-property-analyzer
236 "Detect and create a dynamic argument properties."
237 ":\\(\\w\\|\\s_\\)*" 'property 0)
238
239 (define-lex-regex-analyzer srecode-template-separator-block
240 "Detect and create a template quote block."
241 "^----\n"
242 (semantic-lex-push-token
243 (semantic-lex-token
244 'TEMPLATE_BLOCK
245 (match-end 0)
246 (semantic-lex-unterminated-syntax-protection 'TEMPLATE_BLOCK
247 (goto-char (match-end 0))
248 (re-search-forward "^----$")
249 (match-beginning 0))))
250 (setq semantic-lex-end-point (point)))
251
252
253 (define-lex wisent-srecode-template-lexer
254 "Lexical analyzer that handles SRecode Template buffers.
255 It ignores whitespace, newlines and comments."
256 semantic-lex-newline
257 semantic-lex-ignore-whitespace
258 semantic-lex-ignore-newline
259 semantic-lex-ignore-comments
260 srecode-template-separator-block
261 srecode-template-wy--<keyword>-keyword-analyzer
262 srecode-template-property-analyzer
263 srecode-template-wy--<symbol>-regexp-analyzer
264 srecode-template-wy--<number>-regexp-analyzer
265 srecode-template-wy--<string>-sexp-analyzer
266 srecode-template-wy--<punctuation>-string-analyzer
267 semantic-lex-default-action
268 )
269
270 ;;; srecode-template.wy ends here