srt-wy.el 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. ;;; srecode/srt-wy.el --- Generated parser support file
  2. ;; Copyright (C) 2005, 2007-2012 Free Software Foundation, Inc.
  3. ;; This file is part of GNU Emacs.
  4. ;; GNU Emacs is free software: you can redistribute it and/or modify
  5. ;; it under the terms of the GNU General Public License as published by
  6. ;; the Free Software Foundation, either version 3 of the License, or
  7. ;; (at your option) any later version.
  8. ;; GNU Emacs is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;; You should have received a copy of the GNU General Public License
  13. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  14. ;;; Commentary:
  15. ;;
  16. ;; This file was generated from admin/grammars/srecode-template.wy.
  17. ;;; Code:
  18. (require 'semantic/lex)
  19. ;;; Prologue
  20. ;;
  21. ;;; Declarations
  22. ;;
  23. (defconst srecode-template-wy--keyword-table
  24. (semantic-lex-make-keyword-table
  25. '(("set" . SET)
  26. ("show" . SHOW)
  27. ("macro" . MACRO)
  28. ("context" . CONTEXT)
  29. ("template" . TEMPLATE)
  30. ("sectiondictionary" . SECTIONDICTIONARY)
  31. ("prompt" . PROMPT)
  32. ("default" . DEFAULT)
  33. ("defaultmacro" . DEFAULTMACRO)
  34. ("read" . READ)
  35. ("bind" . BIND))
  36. '(("bind" summary "bind \"<letter>\"")
  37. ("read" summary "prompt <symbol> \"Describe Symbol: \" [default[macro] <lispsym>|\"valuetext\"] [read <lispsym>]")
  38. ("defaultmacro" summary "prompt <symbol> \"Describe Symbol: \" [default[macro] <lispsym>|\"valuetext\"] [read <lispsym>]")
  39. ("default" summary "prompt <symbol> \"Describe Symbol: \" [default[macro] <lispsym>|\"valuetext\"] [read <lispsym>]")
  40. ("prompt" summary "prompt <symbol> \"Describe Symbol: \" [default[macro] <lispsym>|\"valuetext\"] [read <lispsym>]")
  41. ("sectiondictionary" summary "sectiondictionary <name>\\n <dictionary entries>")
  42. ("template" summary "template <name>\\n <template definition>")
  43. ("context" summary "context <name>")
  44. ("macro" summary "... macro \"string\" ...")
  45. ("show" summary "show <name> ; to show a section")
  46. ("set" summary "set <name> <value>")))
  47. "Table of language keywords.")
  48. (defconst srecode-template-wy--token-table
  49. (semantic-lex-make-type-table
  50. '(("number"
  51. (number))
  52. ("string"
  53. (string))
  54. ("symbol"
  55. (symbol))
  56. ("property"
  57. (property))
  58. ("separator"
  59. (TEMPLATE_BLOCK . "^----"))
  60. ("newline"
  61. (newline)))
  62. '(("number" :declared t)
  63. ("string" :declared t)
  64. ("symbol" :declared t)
  65. ("property" :declared t)
  66. ("newline" :declared t)
  67. ("punctuation" syntax "\\s.+")
  68. ("punctuation" :declared t)
  69. ("keyword" :declared t)))
  70. "Table of lexical tokens.")
  71. (defconst srecode-template-wy--parse-table
  72. (progn
  73. (eval-when-compile
  74. (require 'semantic/wisent/comp))
  75. (wisent-compile-grammar
  76. '((SET SHOW MACRO CONTEXT TEMPLATE SECTIONDICTIONARY PROMPT DEFAULT DEFAULTMACRO READ BIND newline TEMPLATE_BLOCK property symbol string number)
  77. nil
  78. (template_file
  79. ((newline)
  80. nil)
  81. ((context))
  82. ((prompt))
  83. ((variable))
  84. ((template)))
  85. (context
  86. ((CONTEXT symbol newline)
  87. (wisent-raw-tag
  88. (semantic-tag $2 'context))))
  89. (prompt
  90. ((PROMPT symbol string opt-default-fcn opt-read-fcn newline)
  91. (wisent-raw-tag
  92. (semantic-tag $2 'prompt :text
  93. (read $3)
  94. :default $4 :read $5))))
  95. (opt-default-fcn
  96. ((DEFAULT symbol)
  97. (progn
  98. (read $2)))
  99. ((DEFAULT string)
  100. (progn
  101. (read $2)))
  102. ((DEFAULTMACRO string)
  103. (progn
  104. (cons 'macro
  105. (read $2))))
  106. (nil nil))
  107. (opt-read-fcn
  108. ((READ symbol)
  109. (progn
  110. (read $2)))
  111. (nil nil))
  112. (variable
  113. ((SET symbol insertable-string-list newline)
  114. (wisent-raw-tag
  115. (semantic-tag-new-variable $2 nil $3)))
  116. ((SHOW symbol newline)
  117. (wisent-raw-tag
  118. (semantic-tag-new-variable $2 nil t))))
  119. (insertable-string-list
  120. ((insertable-string)
  121. (list $1))
  122. ((insertable-string-list insertable-string)
  123. (append $1
  124. (list $2))))
  125. (insertable-string
  126. ((string)
  127. (read $1))
  128. ((MACRO string)
  129. (cons 'macro
  130. (read $2))))
  131. (template
  132. ((TEMPLATE templatename opt-dynamic-arguments newline opt-string opt-section-dictionaries TEMPLATE_BLOCK newline opt-bind)
  133. (wisent-raw-tag
  134. (semantic-tag-new-function $2 nil $3 :documentation $5 :code $7 :dictionaries $6 :binding $9))))
  135. (templatename
  136. ((symbol))
  137. ((PROMPT))
  138. ((CONTEXT))
  139. ((TEMPLATE))
  140. ((DEFAULT))
  141. ((MACRO))
  142. ((DEFAULTMACRO))
  143. ((READ))
  144. ((SET)))
  145. (opt-dynamic-arguments
  146. ((property opt-dynamic-arguments)
  147. (cons $1 $2))
  148. (nil nil))
  149. (opt-string
  150. ((string newline)
  151. (read $1))
  152. (nil nil))
  153. (opt-section-dictionaries
  154. (nil nil)
  155. ((section-dictionary-list)))
  156. (section-dictionary-list
  157. ((one-section-dictionary)
  158. (list $1))
  159. ((section-dictionary-list one-section-dictionary)
  160. (append $1
  161. (list $2))))
  162. (one-section-dictionary
  163. ((SECTIONDICTIONARY string newline variable-list)
  164. (cons
  165. (read $2)
  166. $4)))
  167. (variable-list
  168. ((variable)
  169. (wisent-cook-tag $1))
  170. ((variable-list variable)
  171. (append $1
  172. (wisent-cook-tag $2))))
  173. (opt-bind
  174. ((BIND string newline)
  175. (read $2))
  176. (nil nil)))
  177. '(template_file)))
  178. "Parser table.")
  179. (defun srecode-template-wy--install-parser ()
  180. "Setup the Semantic Parser."
  181. (semantic-install-function-overrides
  182. '((parse-stream . wisent-parse-stream)))
  183. (setq semantic-parser-name "LALR"
  184. semantic--parse-table srecode-template-wy--parse-table
  185. semantic-debug-parser-source "srecode-template.wy"
  186. semantic-flex-keywords-obarray srecode-template-wy--keyword-table
  187. semantic-lex-types-obarray srecode-template-wy--token-table)
  188. ;; Collect unmatched syntax lexical tokens
  189. (semantic-make-local-hook 'wisent-discarding-token-functions)
  190. (add-hook 'wisent-discarding-token-functions
  191. 'wisent-collect-unmatched-syntax nil t))
  192. ;;; Analyzers
  193. (define-lex-string-type-analyzer srecode-template-wy--<punctuation>-string-analyzer
  194. "string analyzer for <punctuation> tokens."
  195. "\\s.+"
  196. nil
  197. 'punctuation)
  198. (define-lex-regex-type-analyzer srecode-template-wy--<symbol>-regexp-analyzer
  199. "regexp analyzer for <symbol> tokens."
  200. "\\(\\sw\\|\\s_\\)+"
  201. nil
  202. 'symbol)
  203. (define-lex-regex-type-analyzer srecode-template-wy--<number>-regexp-analyzer
  204. "regexp analyzer for <number> tokens."
  205. semantic-lex-number-expression
  206. nil
  207. 'number)
  208. (define-lex-sexp-type-analyzer srecode-template-wy--<string>-sexp-analyzer
  209. "sexp analyzer for <string> tokens."
  210. "\\s\""
  211. 'string)
  212. (define-lex-keyword-type-analyzer srecode-template-wy--<keyword>-keyword-analyzer
  213. "keyword analyzer for <keyword> tokens."
  214. "\\(\\sw\\|\\s_\\)+")
  215. ;;; Epilogue
  216. ;;
  217. (define-lex-simple-regex-analyzer srecode-template-property-analyzer
  218. "Detect and create a dynamic argument properties."
  219. ":\\(\\w\\|\\s_\\)*" 'property 0)
  220. (define-lex-regex-analyzer srecode-template-separator-block
  221. "Detect and create a template quote block."
  222. "^----\n"
  223. (semantic-lex-push-token
  224. (semantic-lex-token
  225. 'TEMPLATE_BLOCK
  226. (match-end 0)
  227. (semantic-lex-unterminated-syntax-protection 'TEMPLATE_BLOCK
  228. (goto-char (match-end 0))
  229. (re-search-forward "^----$")
  230. (match-beginning 0))))
  231. (setq semantic-lex-end-point (point)))
  232. (define-lex wisent-srecode-template-lexer
  233. "Lexical analyzer that handles SRecode Template buffers.
  234. It ignores whitespace, newlines and comments."
  235. semantic-lex-newline
  236. semantic-lex-ignore-whitespace
  237. semantic-lex-ignore-newline
  238. semantic-lex-ignore-comments
  239. srecode-template-separator-block
  240. srecode-template-wy--<keyword>-keyword-analyzer
  241. srecode-template-property-analyzer
  242. srecode-template-wy--<symbol>-regexp-analyzer
  243. srecode-template-wy--<number>-regexp-analyzer
  244. srecode-template-wy--<string>-sexp-analyzer
  245. srecode-template-wy--<punctuation>-string-analyzer
  246. semantic-lex-default-action
  247. )
  248. (provide 'srecode/srt-wy)
  249. ;;; srecode/srt-wy.el ends here