grammar-wy.el 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. ;;; semantic/grammar-wy.el --- Generated parser support file
  2. ;; Copyright (C) 2002-2004, 2009-2012 Free Software Foundation, Inc.
  3. ;; Author: David Ponce <david@dponce.com>
  4. ;; Keywords: syntax
  5. ;; This file is part of GNU Emacs.
  6. ;; GNU Emacs is free software: you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation, either version 3 of the License, or
  9. ;; (at your option) any later version.
  10. ;; GNU Emacs is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Commentary:
  17. ;;
  18. ;; This file was generated from admin/grammars/grammar.wy.
  19. ;;; Code:
  20. (require 'semantic/lex)
  21. (defvar semantic-grammar-lex-c-char-re)
  22. ;; Current parsed nonterminal name.
  23. (defvar semantic-grammar-wy--nterm nil)
  24. ;; Index of rule in a nonterminal clause.
  25. (defvar semantic-grammar-wy--rindx nil)
  26. ;;; Declarations
  27. ;;
  28. (defconst semantic-grammar-wy--keyword-table
  29. (semantic-lex-make-keyword-table
  30. '(("%default-prec" . DEFAULT-PREC)
  31. ("%no-default-prec" . NO-DEFAULT-PREC)
  32. ("%keyword" . KEYWORD)
  33. ("%languagemode" . LANGUAGEMODE)
  34. ("%left" . LEFT)
  35. ("%nonassoc" . NONASSOC)
  36. ("%package" . PACKAGE)
  37. ("%prec" . PREC)
  38. ("%put" . PUT)
  39. ("%quotemode" . QUOTEMODE)
  40. ("%right" . RIGHT)
  41. ("%scopestart" . SCOPESTART)
  42. ("%start" . START)
  43. ("%token" . TOKEN)
  44. ("%type" . TYPE)
  45. ("%use-macros" . USE-MACROS))
  46. 'nil)
  47. "Table of language keywords.")
  48. (defconst semantic-grammar-wy--token-table
  49. (semantic-lex-make-type-table
  50. '(("punctuation"
  51. (GT . ">")
  52. (LT . "<")
  53. (OR . "|")
  54. (SEMI . ";")
  55. (COLON . ":"))
  56. ("close-paren"
  57. (RBRACE . "}")
  58. (RPAREN . ")"))
  59. ("open-paren"
  60. (LBRACE . "{")
  61. (LPAREN . "("))
  62. ("block"
  63. (BRACE_BLOCK . "(LBRACE RBRACE)")
  64. (PAREN_BLOCK . "(LPAREN RPAREN)"))
  65. ("code"
  66. (EPILOGUE . "%%...EOF")
  67. (PROLOGUE . "%{...%}"))
  68. ("sexp"
  69. (SEXP))
  70. ("qlist"
  71. (PREFIXED_LIST))
  72. ("char"
  73. (CHARACTER))
  74. ("symbol"
  75. (PERCENT_PERCENT . "\\`%%\\'")
  76. (SYMBOL))
  77. ("string"
  78. (STRING)))
  79. '(("punctuation" :declared t)
  80. ("block" :declared t)
  81. ("sexp" matchdatatype sexp)
  82. ("sexp" syntax "\\=")
  83. ("sexp" :declared t)
  84. ("qlist" matchdatatype sexp)
  85. ("qlist" syntax "\\s'\\s-*(")
  86. ("qlist" :declared t)
  87. ("char" syntax semantic-grammar-lex-c-char-re)
  88. ("char" :declared t)
  89. ("symbol" syntax ":?\\(\\sw\\|\\s_\\)+")
  90. ("symbol" :declared t)
  91. ("string" :declared t)
  92. ("keyword" :declared t)))
  93. "Table of lexical tokens.")
  94. (defconst semantic-grammar-wy--parse-table
  95. (progn
  96. (eval-when-compile
  97. (require 'semantic/wisent/comp))
  98. (wisent-compile-grammar
  99. '((DEFAULT-PREC NO-DEFAULT-PREC KEYWORD LANGUAGEMODE LEFT NONASSOC PACKAGE PREC PUT QUOTEMODE RIGHT SCOPESTART START TOKEN TYPE USE-MACROS STRING SYMBOL PERCENT_PERCENT CHARACTER PREFIXED_LIST SEXP PROLOGUE EPILOGUE PAREN_BLOCK BRACE_BLOCK LPAREN RPAREN LBRACE RBRACE COLON SEMI OR LT GT)
  100. nil
  101. (grammar
  102. ((prologue))
  103. ((epilogue))
  104. ((declaration))
  105. ((nonterminal))
  106. ((PERCENT_PERCENT)))
  107. (prologue
  108. ((PROLOGUE)
  109. (wisent-raw-tag
  110. (semantic-tag-new-code "prologue" nil))))
  111. (epilogue
  112. ((EPILOGUE)
  113. (wisent-raw-tag
  114. (semantic-tag-new-code "epilogue" nil))))
  115. (declaration
  116. ((decl)
  117. (eval $1)))
  118. (decl
  119. ((default_prec_decl))
  120. ((no_default_prec_decl))
  121. ((languagemode_decl))
  122. ((package_decl))
  123. ((precedence_decl))
  124. ((put_decl))
  125. ((quotemode_decl))
  126. ((scopestart_decl))
  127. ((start_decl))
  128. ((keyword_decl))
  129. ((token_decl))
  130. ((type_decl))
  131. ((use_macros_decl)))
  132. (default_prec_decl
  133. ((DEFAULT-PREC)
  134. `(wisent-raw-tag
  135. (semantic-tag "default-prec" 'assoc :value
  136. '("t")))))
  137. (no_default_prec_decl
  138. ((NO-DEFAULT-PREC)
  139. `(wisent-raw-tag
  140. (semantic-tag "default-prec" 'assoc :value
  141. '("nil")))))
  142. (languagemode_decl
  143. ((LANGUAGEMODE symbols)
  144. `(wisent-raw-tag
  145. (semantic-tag ',(car $2)
  146. 'languagemode :rest ',(cdr $2)))))
  147. (package_decl
  148. ((PACKAGE SYMBOL)
  149. `(wisent-raw-tag
  150. (semantic-tag-new-package ',$2 nil))))
  151. (precedence_decl
  152. ((associativity token_type_opt items)
  153. `(wisent-raw-tag
  154. (semantic-tag ',$1 'assoc :type ',$2 :value ',$3))))
  155. (associativity
  156. ((LEFT)
  157. (progn "left"))
  158. ((RIGHT)
  159. (progn "right"))
  160. ((NONASSOC)
  161. (progn "nonassoc")))
  162. (put_decl
  163. ((PUT put_name put_value)
  164. `(wisent-raw-tag
  165. (semantic-tag ',$2 'put :value ',(list $3))))
  166. ((PUT put_name put_value_list)
  167. `(wisent-raw-tag
  168. (semantic-tag ',$2 'put :value ',$3)))
  169. ((PUT put_name_list put_value)
  170. `(wisent-raw-tag
  171. (semantic-tag ',(car $2)
  172. 'put :rest ',(cdr $2)
  173. :value ',(list $3))))
  174. ((PUT put_name_list put_value_list)
  175. `(wisent-raw-tag
  176. (semantic-tag ',(car $2)
  177. 'put :rest ',(cdr $2)
  178. :value ',$3))))
  179. (put_name_list
  180. ((BRACE_BLOCK)
  181. (mapcar 'semantic-tag-name
  182. (semantic-parse-region
  183. (car $region1)
  184. (cdr $region1)
  185. 'put_names 1))))
  186. (put_names
  187. ((LBRACE)
  188. nil)
  189. ((RBRACE)
  190. nil)
  191. ((put_name)
  192. (wisent-raw-tag
  193. (semantic-tag $1 'put-name))))
  194. (put_name
  195. ((SYMBOL))
  196. ((token_type)))
  197. (put_value_list
  198. ((BRACE_BLOCK)
  199. (mapcar 'semantic-tag-code-detail
  200. (semantic-parse-region
  201. (car $region1)
  202. (cdr $region1)
  203. 'put_values 1))))
  204. (put_values
  205. ((LBRACE)
  206. nil)
  207. ((RBRACE)
  208. nil)
  209. ((put_value)
  210. (wisent-raw-tag
  211. (semantic-tag-new-code "put-value" $1))))
  212. (put_value
  213. ((SYMBOL any_value)
  214. (cons $1 $2)))
  215. (scopestart_decl
  216. ((SCOPESTART SYMBOL)
  217. `(wisent-raw-tag
  218. (semantic-tag ',$2 'scopestart))))
  219. (quotemode_decl
  220. ((QUOTEMODE SYMBOL)
  221. `(wisent-raw-tag
  222. (semantic-tag ',$2 'quotemode))))
  223. (start_decl
  224. ((START symbols)
  225. `(wisent-raw-tag
  226. (semantic-tag ',(car $2)
  227. 'start :rest ',(cdr $2)))))
  228. (keyword_decl
  229. ((KEYWORD SYMBOL string_value)
  230. `(wisent-raw-tag
  231. (semantic-tag ',$2 'keyword :value ',$3))))
  232. (token_decl
  233. ((TOKEN token_type_opt SYMBOL string_value)
  234. `(wisent-raw-tag
  235. (semantic-tag ',$3 ',(if $2 'token 'keyword)
  236. :type ',$2 :value ',$4)))
  237. ((TOKEN token_type_opt symbols)
  238. `(wisent-raw-tag
  239. (semantic-tag ',(car $3)
  240. 'token :type ',$2 :rest ',(cdr $3)))))
  241. (token_type_opt
  242. (nil)
  243. ((token_type)))
  244. (token_type
  245. ((LT SYMBOL GT)
  246. (progn $2)))
  247. (type_decl
  248. ((TYPE token_type plist_opt)
  249. `(wisent-raw-tag
  250. (semantic-tag ',$2 'type :value ',$3))))
  251. (plist_opt
  252. (nil)
  253. ((plist)))
  254. (plist
  255. ((plist put_value)
  256. (append
  257. (list $2)
  258. $1))
  259. ((put_value)
  260. (list $1)))
  261. (use_name_list
  262. ((BRACE_BLOCK)
  263. (mapcar 'semantic-tag-name
  264. (semantic-parse-region
  265. (car $region1)
  266. (cdr $region1)
  267. 'use_names 1))))
  268. (use_names
  269. ((LBRACE)
  270. nil)
  271. ((RBRACE)
  272. nil)
  273. ((SYMBOL)
  274. (wisent-raw-tag
  275. (semantic-tag $1 'use-name))))
  276. (use_macros_decl
  277. ((USE-MACROS SYMBOL use_name_list)
  278. `(wisent-raw-tag
  279. (semantic-tag "macro" 'macro :type ',$2 :value ',$3))))
  280. (string_value
  281. ((STRING)
  282. (read $1)))
  283. (any_value
  284. ((SYMBOL))
  285. ((STRING))
  286. ((PAREN_BLOCK))
  287. ((PREFIXED_LIST))
  288. ((SEXP)))
  289. (symbols
  290. ((lifo_symbols)
  291. (nreverse $1)))
  292. (lifo_symbols
  293. ((lifo_symbols SYMBOL)
  294. (cons $2 $1))
  295. ((SYMBOL)
  296. (list $1)))
  297. (nonterminal
  298. ((SYMBOL
  299. (setq semantic-grammar-wy--nterm $1 semantic-grammar-wy--rindx 0)
  300. COLON rules SEMI)
  301. (wisent-raw-tag
  302. (semantic-tag $1 'nonterminal :children $4))))
  303. (rules
  304. ((lifo_rules)
  305. (apply 'nconc
  306. (nreverse $1))))
  307. (lifo_rules
  308. ((lifo_rules OR rule)
  309. (cons $3 $1))
  310. ((rule)
  311. (list $1)))
  312. (rule
  313. ((rhs)
  314. (let*
  315. ((nterm semantic-grammar-wy--nterm)
  316. (rindx semantic-grammar-wy--rindx)
  317. (rhs $1)
  318. comps prec action elt)
  319. (setq semantic-grammar-wy--rindx
  320. (1+ semantic-grammar-wy--rindx))
  321. (while rhs
  322. (setq elt
  323. (car rhs)
  324. rhs
  325. (cdr rhs))
  326. (cond
  327. ((vectorp elt)
  328. (if prec
  329. (error "Duplicate %%prec in `%s:%d' rule" nterm rindx))
  330. (setq prec
  331. (aref elt 0)))
  332. ((consp elt)
  333. (if
  334. (or action comps)
  335. (setq comps
  336. (cons elt comps)
  337. semantic-grammar-wy--rindx
  338. (1+ semantic-grammar-wy--rindx))
  339. (setq action
  340. (car elt))))
  341. (t
  342. (setq comps
  343. (cons elt comps)))))
  344. (wisent-cook-tag
  345. (wisent-raw-tag
  346. (semantic-tag
  347. (format "%s:%d" nterm rindx)
  348. 'rule :type
  349. (if comps "group" "empty")
  350. :value comps :prec prec :expr action))))))
  351. (rhs
  352. (nil)
  353. ((rhs item)
  354. (cons $2 $1))
  355. ((rhs action)
  356. (cons
  357. (list $2)
  358. $1))
  359. ((rhs PREC item)
  360. (cons
  361. (vector $3)
  362. $1)))
  363. (action
  364. ((PAREN_BLOCK))
  365. ((PREFIXED_LIST))
  366. ((BRACE_BLOCK)
  367. (format "(progn\n%s)"
  368. (let
  369. ((s $1))
  370. (if
  371. (string-match "^{[ \n ]*" s)
  372. (setq s
  373. (substring s
  374. (match-end 0))))
  375. (if
  376. (string-match "[ \n ]*}$" s)
  377. (setq s
  378. (substring s 0
  379. (match-beginning 0))))
  380. s))))
  381. (items
  382. ((lifo_items)
  383. (nreverse $1)))
  384. (lifo_items
  385. ((lifo_items item)
  386. (cons $2 $1))
  387. ((item)
  388. (list $1)))
  389. (item
  390. ((SYMBOL))
  391. ((CHARACTER))))
  392. '(grammar prologue epilogue declaration nonterminal rule put_names put_values use_names)))
  393. "Parser table.")
  394. (defun semantic-grammar-wy--install-parser ()
  395. "Setup the Semantic Parser."
  396. (semantic-install-function-overrides
  397. '((parse-stream . wisent-parse-stream)))
  398. (setq semantic-parser-name "LALR"
  399. semantic--parse-table semantic-grammar-wy--parse-table
  400. semantic-debug-parser-source "semantic-grammar.wy"
  401. semantic-flex-keywords-obarray semantic-grammar-wy--keyword-table
  402. semantic-lex-types-obarray semantic-grammar-wy--token-table)
  403. ;; Collect unmatched syntax lexical tokens
  404. (semantic-make-local-hook 'wisent-discarding-token-functions)
  405. (add-hook 'wisent-discarding-token-functions
  406. 'wisent-collect-unmatched-syntax nil t))
  407. ;;; Analyzers
  408. (define-lex-sexp-type-analyzer semantic-grammar-wy--<sexp>-sexp-analyzer
  409. "sexp analyzer for <sexp> tokens."
  410. "\\="
  411. 'SEXP)
  412. (define-lex-sexp-type-analyzer semantic-grammar-wy--<qlist>-sexp-analyzer
  413. "sexp analyzer for <qlist> tokens."
  414. "\\s'\\s-*("
  415. 'PREFIXED_LIST)
  416. (define-lex-keyword-type-analyzer semantic-grammar-wy--<keyword>-keyword-analyzer
  417. "keyword analyzer for <keyword> tokens."
  418. "\\(\\sw\\|\\s_\\)+")
  419. (define-lex-block-type-analyzer semantic-grammar-wy--<block>-block-analyzer
  420. "block analyzer for <block> tokens."
  421. "\\s(\\|\\s)"
  422. '((("(" LPAREN PAREN_BLOCK)
  423. ("{" LBRACE BRACE_BLOCK))
  424. (")" RPAREN)
  425. ("}" RBRACE))
  426. )
  427. (define-lex-regex-type-analyzer semantic-grammar-wy--<char>-regexp-analyzer
  428. "regexp analyzer for <char> tokens."
  429. semantic-grammar-lex-c-char-re
  430. nil
  431. 'CHARACTER)
  432. (define-lex-sexp-type-analyzer semantic-grammar-wy--<string>-sexp-analyzer
  433. "sexp analyzer for <string> tokens."
  434. "\\s\""
  435. 'STRING)
  436. (define-lex-regex-type-analyzer semantic-grammar-wy--<symbol>-regexp-analyzer
  437. "regexp analyzer for <symbol> tokens."
  438. ":?\\(\\sw\\|\\s_\\)+"
  439. '((PERCENT_PERCENT . "\\`%%\\'"))
  440. 'SYMBOL)
  441. (define-lex-string-type-analyzer semantic-grammar-wy--<punctuation>-string-analyzer
  442. "string analyzer for <punctuation> tokens."
  443. "\\(\\s.\\|\\s$\\|\\s'\\)+"
  444. '((GT . ">")
  445. (LT . "<")
  446. (OR . "|")
  447. (SEMI . ";")
  448. (COLON . ":"))
  449. 'punctuation)
  450. (provide 'semantic/grammar-wy)
  451. ;;; semantic/grammar-wy.el ends here