1 ;;; srecode-template.wy --- Semantic Recoder Template parser
3 ;; Copyright (C) 2005-2014 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 | 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)
136 insertable-string-list
139 | insertable-string-list insertable-string
140 (append $1 (list $2))
147 (cons 'macro (read $2))
151 : TEMPLATE templatename opt-dynamic-arguments newline
153 section-dictionary-list
154 TEMPLATE_BLOCK newline
156 (FUNCTION-TAG $2 nil $3 :documentation $5 :code $7
157 :dictionaries $6 :binding $9 )
172 opt-dynamic-arguments
173 : property opt-dynamic-arguments
184 section-dictionary-list
187 | section-dictionary-list flat-section-dictionary
188 (append $1 (list $2))
189 | section-dictionary-list section-dictionary
190 (append $1 (list $2))
193 flat-section-dictionary
194 : SECTIONDICTIONARY string newline
195 flat-dictionary-entry-list
199 flat-dictionary-entry-list
202 | flat-dictionary-entry-list flat-dictionary-entry
206 flat-dictionary-entry
212 : SECTION string newline
213 dictionary-entry-list
218 dictionary-entry-list
221 | dictionary-entry-list dictionary-entry
233 : BIND string newline
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."
246 (semantic-lex-push-token
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."
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
274 ;;; srecode-template.wy ends here