-
Notifications
You must be signed in to change notification settings - Fork 5
/
clojure.wy
170 lines (142 loc) · 4.74 KB
/
clojure.wy
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
;;; semantic/wisent/clojure.wy -- LALR grammar for Clojure
;;
;; Copyright (C)
;;
;; Author: K
;; Maintainer:
;; Created:
;; Keywords: syntax
;;
;; This file is not part of GNU Emacs.
;;
;; This program 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 2, or (at
;; your option) any later version.
;;
;; This software 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; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
%package wisent-clojure-wy
%provide clojure-wy
%languagemode clojure-mode
;; The default goal.
%start sexpr
%start list_content_opt
%start argument
%start fn_content_simple_arity
%start sexpr_full
;; -----------------------------
;; Block & Parenthesis terminals
;; -----------------------------
%type <block> ;;syntax "\\s(\\|\\s)" matchdatatype block
%token <block> PAREN_BLOCK "(LPAREN RPAREN)"
%token <block> BRACE_BLOCK "(LBRACE RBRACE)"
%token <block> BRACK_BLOCK "(LBRACK RBRACK)"
%token <open-paren> LPAREN "("
%token <close-paren> RPAREN ")"
%token <open-paren> LBRACE "{"
%token <close-paren> RBRACE "}"
%token <open-paren> LBRACK "["
%token <close-paren> RBRACK "]"
%type <string> ;;syntax "\\s\"" matchdatatype sexp
%token <string> STRING_LITERAL
%type <number> ;;syntax semantic-lex-number-expression
%token <number> NUMBER_LITERAL
;; Token generated by external lexers
%token DEFN
%token DEF
%token DEFPROJECT
%token SYMBOL
%token NS
%token METADATA
;; reader macros
%token META_READER
%token VAR_READER
%token SET_READER
%token FN_READER
%token EVAL_READER
%token COMMENT_READER
%token UNREADABLE_READER
%token DISCARD_READER
%token UNREADABLE_READER
%%
sexpr: PAREN_BLOCK
(EXPANDFULL $1 list_content_opt)
| SYMBOL
;; | NUMBER_LITERAL
;; | STRING_LITERAL
;
list_content_opt: ;; empty
| list_content
;
list_content: DEF metadata_defs_opt SYMBOL list_content_opt
(VARIABLE-TAG $3 nil nil)
| DEFN metadata_defs_opt SYMBOL doc_string_opt metadata_defs_opt fn_content_def
(FUNCTION-TAG $3 nil (car $6) :arity (cadr $6))
| NS metadata_defs_opt SYMBOL
(PACKAGE-TAG $3 nil)
| DEFPROJECT SYMBOL STRING_LITERAL collection_content_full
(TAG "project" 'project :name $2 :version $3 :properties $4)
;
sexpr_full: SYMBOL
(TAG $1 'symbol)
| NUMBER_LITERAL
(list 'number $1)
| STRING_LITERAL
(TAG (car (read-from-string $1)) 'string)
| PAREN_BLOCK
(TAG (symbol-name (gensym "list")) 'list :content (EXPANDFULL $1 sexpr_full))
| BRACE_BLOCK
(TAG (symbol-name (gensym "set")) 'set :content (EXPANDFULL $1 sexpr_full))
| BRACK_BLOCK
(TAG (symbol-name (gensym "vector")) 'vector :content (EXPANDFULL $1 sexpr_full))
;
collection_content_full: sexpr_full
(list $1)
| sexpr_full collection_content_full
(cons $1 $2)
;
doc_string_opt: ;; empty
| STRING_LITERAL
;
metadata_defs_opt: ;; empty
| metadata_defs
;
metadata_defs: metadata_def
| metadata_defs metadata_def
;
metadata_def: BRACE_BLOCK
| METADATA BRACE_BLOCK
| METADATA SYMBOL
(list $2)
;
fn_content_simple_arity: BRACK_BLOCK
(EXPANDFULL $1 argument)
;
fn_content_multi_arity: PAREN_BLOCK
;; for some reasons we get the arguments in the wrong order here
(list (EXPANDFULL $1 fn_content_simple_arity))
| PAREN_BLOCK fn_content_multi_arity
(append
(list (EXPANDFULL $1 fn_content_simple_arity)
(list $2)))
;
fn_content_def: fn_content_simple_arity
(list $1 nil)
| fn_content_multi_arity
(list (car $1) $1)
;
argument: SYMBOL
(VARIABLE-TAG $1 nil nil)
| metadata_def SYMBOL
(VARIABLE-TAG $2 (car $1) nil)
;
%%
;;; semantic/wisent/clojure.wy ends here