1 ;;; srecode-template.wy --- Semantic Recoder Template parser
3 ;; Copyright (C) 2005-2013 Free Software Foundation, Inc.
5 ;; Author: Eric Ludlam <zappo@gnu.org>
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/>.
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
41 %put SET summary "set <name> <value>"
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"
55 "section <name>\\n <dictionary entries>\\n end"
61 %keyword PROMPT "prompt"
62 %keyword DEFAULT "default"
63 %keyword DEFAULTMACRO "defaultmacro"
65 %put { PROMPT DEFAULT DEFAULTMACRO READ } summary "prompt <symbol> \"Describe Symbol: \" [default[macro] <lispsym>|\"valuetext\"] [read <lispsym>]"
67 %put BIND summary "bind \"<letter>\""
70 %type <punctuation> syntax "\\s.+"
72 %token <newline> newline
74 %token <separator> TEMPLATE_BLOCK "^----"
76 ;;; Bland default types
77 %type <property> syntax ":\\(\\w\\|\\s_\\)*"
78 %token <property> property
81 %token <symbol> symbol
84 %token <string> string
87 %token <number> number
100 : CONTEXT symbol newline
105 : PROMPT symbol string opt-default-fcn opt-read-fcn newline
106 (TAG $2 'prompt :text (read $3) :default $4 :read $5)
114 | DEFAULTMACRO string
115 (progn (cons 'macro (read $2)))
126 : SET symbol insertable-string-list newline
127 (VARIABLE-TAG $2 nil $3)
128 | SHOW symbol newline
129 (VARIABLE-TAG $2 nil t)
132 insertable-string-list
135 | insertable-string-list insertable-string
136 (append $1 (list $2))
143 (cons 'macro (read $2))
147 : TEMPLATE templatename opt-dynamic-arguments newline
149 section-dictionary-list
150 TEMPLATE_BLOCK newline
152 (FUNCTION-TAG $2 nil $3 :documentation $5 :code $7
153 :dictionaries $6 :binding $9 )
168 opt-dynamic-arguments
169 : property opt-dynamic-arguments
180 section-dictionary-list
183 | section-dictionary-list flat-section-dictionary
184 (append $1 (list $2))
185 | section-dictionary-list section-dictionary
186 (append $1 (list $2))
189 flat-section-dictionary
190 : SECTIONDICTIONARY string newline
191 flat-dictionary-entry-list
195 flat-dictionary-entry-list
198 | flat-dictionary-entry-list flat-dictionary-entry
202 flat-dictionary-entry
208 : SECTION string newline
209 dictionary-entry-list
214 dictionary-entry-list
217 | dictionary-entry-list dictionary-entry
229 : BIND string newline
235 (define-lex-simple-regex-analyzer srecode-template-property-analyzer
236 "Detect and create a dynamic argument properties."
237 ":\\(\\w\\|\\s_\\)*" 'property 0)
239 (define-lex-regex-analyzer srecode-template-separator-block
240 "Detect and create a template quote block."
242 (semantic-lex-push-token
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)))
253 (define-lex wisent-srecode-template-lexer
254 "Lexical analyzer that handles SRecode Template buffers.
255 It ignores whitespace, newlines and comments."
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
270 ;;; srecode-template.wy ends here