Commit | Line | Data |
---|---|---|
78adbf9c CY |
1 | ;;; srecode-template.wy --- Semantic Recoder Template parser |
2 | ||
ab422c4d | 3 | ;; Copyright (C) 2005-2013 Free Software Foundation, Inc. |
78adbf9c CY |
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 | ||
62a81506 CY |
31 | %package srecode-template-wy |
32 | %provide srecode/srt-wy | |
33 | ||
78adbf9c CY |
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>" | |
62a81506 CY |
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 | ||
78adbf9c CY |
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 | |
62a81506 | 77 | %type <property> syntax ":\\(\\w\\|\\s_\\)*" |
78adbf9c CY |
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) | |
890f7890 DE |
128 | | SET symbol number newline |
129 | ;; This so a common error w/ priority works. | |
130 | ;; Note that "number" still has a string value in the lexer. | |
131 | (VARIABLE-TAG $2 nil (list $3)) | |
78adbf9c CY |
132 | | SHOW symbol newline |
133 | (VARIABLE-TAG $2 nil t) | |
134 | ; | |
135 | ||
136 | insertable-string-list | |
137 | : insertable-string | |
138 | (list $1) | |
139 | | insertable-string-list insertable-string | |
140 | (append $1 (list $2)) | |
141 | ; | |
142 | ||
143 | insertable-string | |
144 | : string | |
145 | (read $1) | |
146 | | MACRO string | |
147 | (cons 'macro (read $2)) | |
148 | ; | |
149 | ||
150 | template | |
151 | : TEMPLATE templatename opt-dynamic-arguments newline | |
152 | opt-string | |
62a81506 | 153 | section-dictionary-list |
78adbf9c CY |
154 | TEMPLATE_BLOCK newline |
155 | opt-bind | |
156 | (FUNCTION-TAG $2 nil $3 :documentation $5 :code $7 | |
157 | :dictionaries $6 :binding $9 ) | |
158 | ; | |
159 | ||
160 | templatename | |
161 | : symbol | |
162 | | PROMPT | |
163 | | CONTEXT | |
164 | | TEMPLATE | |
165 | | DEFAULT | |
166 | | MACRO | |
167 | | DEFAULTMACRO | |
168 | | READ | |
169 | | SET | |
170 | ; | |
171 | ||
172 | opt-dynamic-arguments | |
173 | : property opt-dynamic-arguments | |
174 | (cons $1 $2) | |
175 | | () | |
176 | ; | |
177 | ||
178 | opt-string | |
179 | : string newline | |
180 | ( read $1 ) | |
181 | | () | |
182 | ; | |
183 | ||
78adbf9c | 184 | section-dictionary-list |
62a81506 CY |
185 | : ;; empty |
186 | () | |
187 | | section-dictionary-list flat-section-dictionary | |
188 | (append $1 (list $2)) | |
189 | | section-dictionary-list section-dictionary | |
78adbf9c CY |
190 | (append $1 (list $2)) |
191 | ; | |
192 | ||
62a81506 | 193 | flat-section-dictionary |
78adbf9c | 194 | : SECTIONDICTIONARY string newline |
62a81506 CY |
195 | flat-dictionary-entry-list |
196 | (cons (read $2) $4) | |
197 | ; | |
198 | ||
199 | flat-dictionary-entry-list | |
200 | : ;; empty | |
201 | () | |
202 | | flat-dictionary-entry-list flat-dictionary-entry | |
203 | (append $1 $2) | |
204 | ; | |
205 | ||
206 | flat-dictionary-entry | |
207 | : variable | |
208 | (EXPANDTAG $1) | |
209 | ; | |
210 | ||
211 | section-dictionary | |
212 | : SECTION string newline | |
213 | dictionary-entry-list | |
214 | END newline | |
78adbf9c CY |
215 | (cons (read $2) $4) |
216 | ; | |
217 | ||
62a81506 | 218 | dictionary-entry-list |
735135f9 | 219 | : ;; empty |
62a81506 CY |
220 | () |
221 | | dictionary-entry-list dictionary-entry | |
222 | (append $1 $2) | |
223 | ; | |
224 | ||
225 | dictionary-entry | |
78adbf9c CY |
226 | : variable |
227 | (EXPANDTAG $1) | |
62a81506 CY |
228 | | section-dictionary |
229 | (list $1) | |
78adbf9c CY |
230 | ; |
231 | ||
232 | opt-bind | |
233 | : BIND string newline | |
234 | ( read $2 ) | |
235 | | () | |
236 | ; | |
237 | ||
238 | %% | |
239 | (define-lex-simple-regex-analyzer srecode-template-property-analyzer | |
240 | "Detect and create a dynamic argument properties." | |
241 | ":\\(\\w\\|\\s_\\)*" 'property 0) | |
242 | ||
243 | (define-lex-regex-analyzer srecode-template-separator-block | |
244 | "Detect and create a template quote block." | |
245 | "^----\n" | |
246 | (semantic-lex-push-token | |
247 | (semantic-lex-token | |
248 | 'TEMPLATE_BLOCK | |
249 | (match-end 0) | |
250 | (semantic-lex-unterminated-syntax-protection 'TEMPLATE_BLOCK | |
251 | (goto-char (match-end 0)) | |
252 | (re-search-forward "^----$") | |
253 | (match-beginning 0)))) | |
254 | (setq semantic-lex-end-point (point))) | |
255 | ||
256 | ||
257 | (define-lex wisent-srecode-template-lexer | |
258 | "Lexical analyzer that handles SRecode Template buffers. | |
259 | It ignores whitespace, newlines and comments." | |
260 | semantic-lex-newline | |
261 | semantic-lex-ignore-whitespace | |
262 | semantic-lex-ignore-newline | |
263 | semantic-lex-ignore-comments | |
264 | srecode-template-separator-block | |
265 | srecode-template-wy--<keyword>-keyword-analyzer | |
266 | srecode-template-property-analyzer | |
78adbf9c | 267 | srecode-template-wy--<number>-regexp-analyzer |
890f7890 | 268 | srecode-template-wy--<symbol>-regexp-analyzer |
78adbf9c CY |
269 | srecode-template-wy--<string>-sexp-analyzer |
270 | srecode-template-wy--<punctuation>-string-analyzer | |
271 | semantic-lex-default-action | |
272 | ) | |
273 | ||
62a81506 | 274 | ;;; srecode-template.wy ends here |