Update copyright year to 2014 by running admin/update-copyright.
[emacs.git] / admin / grammars / srecode-template.wy
blobd4dd2ad907a48f5840d8bed7d0650a65f5023e98
1 ;;; srecode-template.wy --- Semantic Recoder Template parser
3 ;; Copyright (C) 2005-2014 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 %package srecode-template-wy
32 %provide srecode/srt-wy
34 %languagemode  srecode-mode
36 %start template_file
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>"
53 %keyword SECTION  "section"
54 %put     SECTION  summary
55          "section <name>\\n <dictionary entries>\\n end"
57 %keyword END      "end"
58 %put     END      summary
59          "section ... end"
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>\""
69 ;;; Punctuation Types
70 %type <punctuation> syntax "\\s.+"
71 %type <newline>
72 %token <newline> newline
74 %token <separator> TEMPLATE_BLOCK "^----"
76 ;;; Bland default types
77 %type <property> syntax ":\\(\\w\\|\\s_\\)*"
78 %token <property> property
80 %type  <symbol>
81 %token <symbol> symbol
83 %type  <string>
84 %token <string> string
86 %type  <number>
87 %token <number> number
91 template_file
92   : newline ( )
93   | context
94   | prompt
95   | variable
96   | template
97   ;
99 context
100   : CONTEXT symbol newline
101     (TAG $2 'context)
102   ;
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   ;
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   ;
119 opt-read-fcn
120   : READ symbol
121     (progn (read $2))
122   | ()
123   ;
125 variable
126   : SET symbol insertable-string-list newline
127     (VARIABLE-TAG $2 nil $3)
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))
132   | SHOW symbol newline
133     (VARIABLE-TAG $2 nil t)
134   ;
136 insertable-string-list
137   : insertable-string
138     (list $1)
139   | insertable-string-list insertable-string
140     (append $1 (list $2))
141   ;
143 insertable-string
144   : string
145     (read $1)
146   | MACRO string
147     (cons 'macro (read $2))
148   ;
150 template
151   : TEMPLATE templatename opt-dynamic-arguments newline
152     opt-string
153     section-dictionary-list
154     TEMPLATE_BLOCK newline
155     opt-bind
156     (FUNCTION-TAG $2 nil $3 :documentation $5 :code $7
157                   :dictionaries $6 :binding $9 )
158   ;
160 templatename
161   : symbol
162   | PROMPT
163   | CONTEXT
164   | TEMPLATE
165   | DEFAULT
166   | MACRO
167   | DEFAULTMACRO
168   | READ
169   | SET
170   ;
172 opt-dynamic-arguments
173   : property opt-dynamic-arguments
174     (cons $1 $2)
175   | ()
176   ;
178 opt-string
179   : string newline
180     ( read $1 )
181   | ()
182   ;
184 section-dictionary-list
185   : ;; empty
186     ()
187   | section-dictionary-list flat-section-dictionary
188     (append $1 (list $2))
189   | section-dictionary-list section-dictionary
190     (append $1 (list $2))
191   ;
193 flat-section-dictionary
194   : SECTIONDICTIONARY string newline
195     flat-dictionary-entry-list
196     (cons (read $2) $4)
197   ;
199 flat-dictionary-entry-list
200   : ;; empty
201     ()
202   | flat-dictionary-entry-list flat-dictionary-entry
203     (append $1 $2)
204   ;
206 flat-dictionary-entry
207   : variable
208     (EXPANDTAG $1)
209   ;
211 section-dictionary
212   : SECTION string newline
213     dictionary-entry-list
214     END newline
215     (cons (read $2) $4)
216   ;
218 dictionary-entry-list
219   : ;; empty
220     ()
221   | dictionary-entry-list dictionary-entry
222     (append $1 $2)
223   ;
225 dictionary-entry
226   : variable
227     (EXPANDTAG $1)
228   | section-dictionary
229     (list $1)
230   ;
232 opt-bind
233   : BIND string newline
234     ( read $2 )
235   | ()
236   ;
239 (define-lex-simple-regex-analyzer srecode-template-property-analyzer
240   "Detect and create a dynamic argument properties."
241   ":\\(\\w\\|\\s_\\)*" 'property 0)
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)))
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
267   srecode-template-wy--<number>-regexp-analyzer
268   srecode-template-wy--<symbol>-regexp-analyzer
269   srecode-template-wy--<string>-sexp-analyzer
270   srecode-template-wy--<punctuation>-string-analyzer
271   semantic-lex-default-action
272   )
274 ;;; srecode-template.wy ends here