summaryrefslogtreecommitdiff
path: root/admin/grammars/srecode-template.wy
blob: 4ff2d7e4e4177bebddc5628014c8088ce7682566 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
;;; srecode-template.wy --- Semantic Recoder Template parser

;; Copyright (C) 2005-2011 Free Software Foundation, Inc.

;; Author: Eric Ludlam <zappo@gnu.org>
;; Keywords: syntax
;; X-RCS: $Id: srecode-template.wy,v 1.10 2009-01-09 23:01:54 zappo Exp $

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:
;;
;; Parser for the Semantic Recoder template language
;;
;; Semantic Recoder templates are based on Google Templates
;; and are at the bottom of the Semantic Recoder API.

%languagemode  srecode-mode

%start template_file

;;; KEYWORDS
%type    <keyword>
%keyword SET  "set"
%put     SET  summary "set <name> <value>"
%keyword SHOW "show"
%put     SHOW summary "show <name>   ; to show a section"
%keyword MACRO "macro"
%put     MACRO summary "... macro \"string\" ..."
%keyword CONTEXT "context"
%put     CONTEXT summary "context <name>"
%keyword TEMPLATE  "template"
%put     TEMPLATE  summary "template <name>\\n <template definition>"
%keyword SECTIONDICTIONARY "sectiondictionary"
%put     SECTIONDICTIONARY summary "sectiondictionary <name>\\n <dictionary entries>"
%keyword PROMPT "prompt"
%keyword DEFAULT "default"
%keyword DEFAULTMACRO "defaultmacro"
%keyword READ "read"
%put     { PROMPT DEFAULT DEFAULTMACRO READ } summary "prompt <symbol> \"Describe Symbol: \" [default[macro] <lispsym>|\"valuetext\"] [read <lispsym>]"
%keyword BIND "bind"
%put     BIND summary "bind \"<letter>\""

;;; Punctuation Types
%type <punctuation> syntax "\\s.+"
%type <newline>
%token <newline> newline

%token <separator> TEMPLATE_BLOCK "^----"

;;; Bland default types
%type <property> ":\\(\\w\\|\\s_\\)*"
%token <property> property

%type  <symbol>
%token <symbol> symbol

%type  <string>
%token <string> string

%type  <number>
%token <number> number

%%

template_file
  : newline ( )
  | context
  | prompt
  | variable
  | template
  ;

context
  : CONTEXT symbol newline
    (TAG $2 'context)
  ;

prompt
  : PROMPT symbol string opt-default-fcn opt-read-fcn newline
    (TAG $2 'prompt :text (read $3) :default $4 :read $5)
  ;

opt-default-fcn
  : DEFAULT symbol
    (progn (read $2))
  | DEFAULT string
    (progn (read $2))
  | DEFAULTMACRO string
    (progn (cons 'macro (read $2)))
  | ()
  ;

opt-read-fcn
  : READ symbol
    (progn (read $2))
  | ()
  ;

variable
  : SET symbol insertable-string-list newline
    (VARIABLE-TAG $2 nil $3)
  | SHOW symbol newline
    (VARIABLE-TAG $2 nil t)
  ;

insertable-string-list
  : insertable-string
    (list $1)
  | insertable-string-list insertable-string
    (append $1 (list $2))
  ;

insertable-string
  : string
    (read $1)
  | MACRO string
    (cons 'macro (read $2))
  ;

template
  : TEMPLATE templatename opt-dynamic-arguments newline
    opt-string
    opt-section-dictionaries
    TEMPLATE_BLOCK newline
    opt-bind
    (FUNCTION-TAG $2 nil $3 :documentation $5 :code $7
		  :dictionaries $6 :binding $9 )
  ;

templatename
  : symbol
  | PROMPT
  | CONTEXT
  | TEMPLATE
  | DEFAULT
  | MACRO
  | DEFAULTMACRO
  | READ
  | SET
  ;

opt-dynamic-arguments
  : property opt-dynamic-arguments
    (cons $1 $2)
  | ()
  ;

opt-string
  : string newline
    ( read $1 )
  | ()
  ;

opt-section-dictionaries
  : () ;; EMPTY
  | section-dictionary-list
  ;

section-dictionary-list
  : one-section-dictionary
    (list $1)
  | section-dictionary-list one-section-dictionary
    (append $1 (list $2))
  ;

one-section-dictionary
  : SECTIONDICTIONARY string newline
    variable-list
    (cons (read $2) $4)
  ;

variable-list
  : variable
    (EXPANDTAG $1)
  | variable-list variable
    (append $1 (EXPANDTAG $2))
  ;

opt-bind
  : BIND string newline
    ( read $2 )
  | ()
  ;

%%
(define-lex-simple-regex-analyzer srecode-template-property-analyzer
  "Detect and create a dynamic argument properties."
  ":\\(\\w\\|\\s_\\)*" 'property 0)

(define-lex-regex-analyzer srecode-template-separator-block
  "Detect and create a template quote block."
  "^----\n"
  (semantic-lex-push-token
   (semantic-lex-token
    'TEMPLATE_BLOCK
    (match-end 0)
    (semantic-lex-unterminated-syntax-protection 'TEMPLATE_BLOCK
      (goto-char (match-end 0))
      (re-search-forward "^----$")
      (match-beginning 0))))
  (setq semantic-lex-end-point (point)))


(define-lex wisent-srecode-template-lexer
  "Lexical analyzer that handles SRecode Template buffers.
It ignores whitespace, newlines and comments."
  semantic-lex-newline
  semantic-lex-ignore-whitespace
  semantic-lex-ignore-newline
  semantic-lex-ignore-comments
  srecode-template-separator-block
  srecode-template-wy--<keyword>-keyword-analyzer
  srecode-template-property-analyzer
  srecode-template-wy--<symbol>-regexp-analyzer
  srecode-template-wy--<number>-regexp-analyzer
  srecode-template-wy--<string>-sexp-analyzer
  srecode-template-wy--<punctuation>-string-analyzer
  semantic-lex-default-action
  )

;;; wisent-dot.wy ends here