@fraczak/k 2.1.6 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Code-derivation-tests/bnat.mjs +10 -0
- package/Code-derivation-tests/built-in.mjs +19 -0
- package/Code-derivation-tests/dot.mjs +15 -0
- package/Code-derivation-tests/index.mjs +20 -0
- package/Code-derivation-tests/loop.mjs +11 -0
- package/Code-derivation-tests/nat.mjs +10 -0
- package/Code-derivation-tests/not-not.mjs +14 -0
- package/Code-derivation-tests/product.mjs +21 -0
- package/Code-derivation-tests/rlz.mjs +14 -0
- package/Code-derivation-tests/vector.mjs +28 -0
- package/INTRO.md +88 -0
- package/README.md +68 -14
- package/TODO.md +54 -0
- package/TYPES.md +32 -0
- package/bug.json +419 -0
- package/chatGPT.md +235 -0
- package/chatGPT.md~ +119 -0
- package/code-resolution.md +121 -0
- package/code-resolution.mjs +51 -0
- package/codes.mjs +59 -4
- package/filters.mjs +59 -0
- package/hash.mjs +39 -0
- package/index.mjs +55 -12
- package/package.json +2 -2
- package/parser.jison +111 -44
- package/parser.mjs +146 -88
- package/patterns.mjs +601 -0
- package/pretty.mjs +27 -0
- package/repl.mjs +6 -3
- package/run.mjs +4 -1
- package/symbol-table.mjs +1 -1
- package/test-filters.mjs +45 -0
- package/test-fingerprint.mjs +38 -0
- package/test.mjs +1 -43
package/parser.jison
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
import s from "./symbol-table.mjs";
|
|
4
4
|
|
|
5
|
+
function getToken(yytext,yy,lstack) {
|
|
6
|
+
const yylloc = yy.lexer.yylloc;
|
|
7
|
+
const loc = lstack[lstack.length - 1]; // { first_line: 5, last_line: 5, first_column: 2, last_column: 3 };
|
|
8
|
+
const start = {line: loc.first_line, column: loc.first_column + 1};
|
|
9
|
+
const end = {line: start.line, column: start.column + yytext.length};
|
|
10
|
+
const result = {start,end,value: String(yytext)};
|
|
11
|
+
// console.log(result);
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
|
|
5
15
|
function fromEscString(escString) {
|
|
6
16
|
const isSingleQuoted = escString.startsWith("'");
|
|
7
17
|
let str = escString.substring(1, escString.length - 1);
|
|
@@ -27,9 +37,9 @@ function fromEscString(escString) {
|
|
|
27
37
|
%lex
|
|
28
38
|
|
|
29
39
|
%%
|
|
30
|
-
[/][*]([*][^/]|[^*])*[*][/]
|
|
31
|
-
("//"|"#"|"%"|"--")[^\n]*
|
|
32
|
-
\s+
|
|
40
|
+
[/][*]([*][^/]|[^*])*[*][/] /* c-comment */
|
|
41
|
+
("//"|"#"|"%"|"--")[^\n]* /* one line comment */
|
|
42
|
+
\s+ /* blanks */
|
|
33
43
|
"<" return 'LA';
|
|
34
44
|
"{" return 'LC';
|
|
35
45
|
"[" return 'LB';
|
|
@@ -39,11 +49,13 @@ function fromEscString(escString) {
|
|
|
39
49
|
"]" return 'RB';
|
|
40
50
|
")" return 'RP';
|
|
41
51
|
"=" return 'EQ';
|
|
52
|
+
"..." return 'DOTS';
|
|
42
53
|
"." return 'DOT';
|
|
43
54
|
"," return 'COMMA';
|
|
44
55
|
";" return 'SC';
|
|
45
56
|
":" return 'COL';
|
|
46
57
|
"$" return 'DOLLAR';
|
|
58
|
+
"?" return 'QMARK';
|
|
47
59
|
"|" return 'PIPE';
|
|
48
60
|
"^" return 'CARET';
|
|
49
61
|
\"([^"\\]|\\(.|\n))*\"|\'([^'\\]|\\(.|\n))*\' return 'STRING';
|
|
@@ -54,41 +66,58 @@ function fromEscString(escString) {
|
|
|
54
66
|
/lex
|
|
55
67
|
|
|
56
68
|
%token NAME STRING INT
|
|
57
|
-
%token LA LC LB LP RA RP RB RC EQ DOT COMMA SC COL DOLLAR PIPE CARET
|
|
69
|
+
%token LA LC LB LP RA RP RB RC EQ DOT COMMA SC COL DOLLAR PIPE CARET QMARK DOTS
|
|
58
70
|
%token EOF
|
|
59
71
|
|
|
60
72
|
%start input_with_eof
|
|
61
73
|
|
|
62
74
|
%%
|
|
63
75
|
|
|
64
|
-
name: NAME { $$ =
|
|
65
|
-
str: STRING { $$ =
|
|
66
|
-
int: INT { $$ =
|
|
76
|
+
name: NAME { $$ = getToken(yytext,yy,_$); };
|
|
77
|
+
str: STRING { $$ = getToken(yytext,yy,_$); $$.value = fromEscString($$.value);};
|
|
78
|
+
int: INT { $$ = getToken(yytext,yy,_$); $$.value = parseInt($$.value); };
|
|
79
|
+
la: LA { $$ = getToken(yytext,yy,_$); };
|
|
80
|
+
lc: LC { $$ = getToken(yytext,yy,_$); };
|
|
81
|
+
lb: LB { $$ = getToken(yytext,yy,_$); };
|
|
82
|
+
lp: LP { $$ = getToken(yytext,yy,_$); };
|
|
83
|
+
ra: RA { $$ = getToken(yytext,yy,_$); };
|
|
84
|
+
rc: RC { $$ = getToken(yytext,yy,_$); };
|
|
85
|
+
rb: RB { $$ = getToken(yytext,yy,_$); };
|
|
86
|
+
rp: RP { $$ = getToken(yytext,yy,_$); };
|
|
87
|
+
eq: EQ { $$ = getToken(yytext,yy,_$); };
|
|
88
|
+
dots: DOTS { $$ = getToken(yytext,yy,_$); };
|
|
89
|
+
dot: DOT { $$ = getToken(yytext,yy,_$); };
|
|
90
|
+
comma: COMMA { $$ = getToken(yytext,yy,_$); };
|
|
91
|
+
sc: SC { $$ = getToken(yytext,yy,_$); };
|
|
92
|
+
col: COL { $$ = getToken(yytext,yy,_$); };
|
|
93
|
+
dollar: DOLLAR { $$ = getToken(yytext,yy,_$); };
|
|
94
|
+
qmark: QMARK { $$ = getToken(yytext,yy,_$); };
|
|
67
95
|
|
|
68
96
|
input_with_eof: defs comp EOF {
|
|
69
97
|
const result = {defs: {rels: s.rels, codes: s.codes}, exp: $2};
|
|
70
98
|
// console.log(JSON.stringify(result, "", 2));
|
|
99
|
+
// process.exit(0);
|
|
71
100
|
return result;
|
|
72
101
|
};
|
|
73
102
|
|
|
74
103
|
defs: { }
|
|
75
|
-
| defs name
|
|
76
|
-
| defs
|
|
104
|
+
| defs name eq comp sc { s.add_rel($2.value,$4); }
|
|
105
|
+
| defs dollar name eq codeDef SC { s.add_code($3.value,$5); }
|
|
77
106
|
;
|
|
78
107
|
|
|
79
108
|
code
|
|
80
|
-
: name { $$ = {code: "ref", ref: $1}; }
|
|
109
|
+
: name { $$ = { code: "ref", ref: $1.value, start: $1.start, end: $1.end}; }
|
|
81
110
|
| codeDef { $$ = $1; }
|
|
82
111
|
;
|
|
83
112
|
|
|
84
113
|
codeDef
|
|
85
|
-
:
|
|
86
|
-
|
|
|
87
|
-
|
|
|
114
|
+
: lc labelled_codes rc { $$ = { code: "product", product: $2, start: $1.start, end: $3.end }; }
|
|
115
|
+
| lb code rb { $$ = { code: "vector", vector: s.as_ref($2), start: $1.start, end: $3.end }; }
|
|
116
|
+
| la labelled_codes ra { $$ = { code: "union", union: $2, start: $1.start, end: $3.end }; }
|
|
88
117
|
;
|
|
89
118
|
|
|
90
119
|
labelled_codes
|
|
91
|
-
: { $$ = {} }
|
|
120
|
+
: { $$ = {}; }
|
|
92
121
|
| non_empty_labelled_codes { $$ = $1.reduce((r, lc) => {
|
|
93
122
|
r[lc.label] = s.as_ref(lc.code);
|
|
94
123
|
return r }
|
|
@@ -97,39 +126,77 @@ labelled_codes
|
|
|
97
126
|
|
|
98
127
|
non_empty_labelled_codes
|
|
99
128
|
: code_label { $$ = [$1]; }
|
|
100
|
-
| non_empty_labelled_codes
|
|
129
|
+
| non_empty_labelled_codes comma code_label
|
|
101
130
|
{ $$ = [].concat($1,$3); }
|
|
102
131
|
;
|
|
103
132
|
|
|
104
133
|
code_label
|
|
105
|
-
: code name { $$ = {label: $2, code: $1}; }
|
|
106
|
-
| code str { $$ = {label: $2, code: $1}; }
|
|
107
|
-
| code int { $$ = {label: $2, code: $1}; }
|
|
108
|
-
| name
|
|
109
|
-
| str
|
|
110
|
-
| int
|
|
134
|
+
: code name { $$ = {label: $2.value, code: $1}; }
|
|
135
|
+
| code str { $$ = {label: $2.value, code: $1}; }
|
|
136
|
+
| code int { $$ = {label: $2.value, code: $1}; }
|
|
137
|
+
| name col code { $$ = {label: $1.value, code: $3}; }
|
|
138
|
+
| str col code { $$ = {label: $1.value, code: $3}; }
|
|
139
|
+
| int col code { $$ = {label: $1.value, code: $3}; }
|
|
140
|
+
;
|
|
141
|
+
|
|
142
|
+
filter
|
|
143
|
+
: name { $$ = { type: "name", name: $1.value, start: $1.start, end: $1.end}; }
|
|
144
|
+
| dollar code { $$ = { type: "code", code: s.as_ref($2), start: $1.start, end: $2.end}; }
|
|
145
|
+
| lp labelled_filters rp { $$ = { open: $2.open, fields: $2.fields, start: $1.start, end: $3.end}; }
|
|
146
|
+
| la labelled_filters ra { $$ = { type: "union", open: $2.open, fields: $2.fields, start: $1.start, end: $3.end}; }
|
|
147
|
+
| lc labelled_filters rc { $$ = { type: "product", open: $2.open, fields: $2.fields, start: $1.start, end: $3.end}; }
|
|
148
|
+
| lb filter rb { $$ = { type: "vector", vector: $2, start: $1.start, end: $3.end }; }
|
|
149
|
+
;
|
|
150
|
+
|
|
151
|
+
labelled_filters
|
|
152
|
+
: { $$ = { fields: {}}; }
|
|
153
|
+
| non_empty_labelled_filters { $$ = $1.reduce((r, lc) => {
|
|
154
|
+
if (lc.dots) {
|
|
155
|
+
r.open = true;
|
|
156
|
+
} else {
|
|
157
|
+
r.fields[lc.label] = lc.filter;
|
|
158
|
+
}
|
|
159
|
+
return r }
|
|
160
|
+
, { fields: {} }); }
|
|
161
|
+
;
|
|
162
|
+
|
|
163
|
+
non_empty_labelled_filters
|
|
164
|
+
: filter_label { $$ = [$1]; }
|
|
165
|
+
| non_empty_labelled_filters comma filter_label
|
|
166
|
+
{ $$ = [].concat($1,$3); }
|
|
167
|
+
;
|
|
168
|
+
|
|
169
|
+
filter_label
|
|
170
|
+
: dots { $$ = {dots: true }; }
|
|
171
|
+
| filter name { $$ = {label: $2.value, filter: $1}; }
|
|
172
|
+
| filter str { $$ = {label: $2.value, filter: $1}; }
|
|
173
|
+
| filter int { $$ = {label: $2.value, filter: $1}; }
|
|
174
|
+
| name col filter { $$ = {label: $1.value, filter: $3}; }
|
|
175
|
+
| str col filter { $$ = {label: $1.value, filter: $3}; }
|
|
176
|
+
| int col filter { $$ = {label: $1.value, filter: $3}; }
|
|
111
177
|
;
|
|
112
178
|
|
|
113
179
|
comp
|
|
114
180
|
: exp { $$ = $1; }
|
|
115
|
-
| comp exp { $$ = s.comp($1, $2); }
|
|
116
|
-
| comp CARET { $$ = {op: 'caret', caret: $1}; }
|
|
181
|
+
| comp exp { $$ = {...s.comp($1, $2), start: $1.start, end:$2.end}; }
|
|
182
|
+
| comp CARET { $$ = {op: 'caret', caret: $1, start: $1.start, end:$2.end}; }
|
|
117
183
|
;
|
|
118
184
|
|
|
119
185
|
exp
|
|
120
|
-
:
|
|
121
|
-
|
|
|
122
|
-
|
|
|
123
|
-
| name { $$ = {op: "ref", ref: $1}; }
|
|
124
|
-
|
|
|
125
|
-
|
|
|
126
|
-
| str { $$ = {op: "str", str: $1}; }
|
|
127
|
-
| int { $$ = {op: "int", int: $1}; }
|
|
128
|
-
|
|
|
129
|
-
|
|
|
130
|
-
|
|
|
131
|
-
|
|
|
132
|
-
|
|
|
186
|
+
: lc labelled rc { $$ = {...$2, start: $1.start, end: $3.end}; }
|
|
187
|
+
| lb list rb { $$ = {op: "vector", vector: $2, start: $1.start, end: $3.end}; }
|
|
188
|
+
| la list ra { $$ = {...s.union($2), start: $1.start, end: $3.end}; }
|
|
189
|
+
| name { $$ = {op: "ref", ref: $1.value, start: $1.start, end: $1.end}; }
|
|
190
|
+
| lp rp { $$ = {...s.identity, start: $1.start, end: $2.end}; }
|
|
191
|
+
| lp comp rp { $$ = {...$2, start: $1.start, end: $3.end }; }
|
|
192
|
+
| str { $$ = {op: "str", str: $1.value, start: $1.start, end: $1.end }; }
|
|
193
|
+
| int { $$ = {op: "int", int: $1.value, start: $1.start, end: $1.end }; }
|
|
194
|
+
| dot int { $$ = {op: "dot", dot: $2.value, start: $1.start, end: $2.end }; }
|
|
195
|
+
| dot str { $$ = {op: "dot", dot: $2.value, start: $1.start, end: $2.end }; }
|
|
196
|
+
| dot name { $$ = {op: "dot", dot: $2.value, start: $1.start, end: $2.end }; }
|
|
197
|
+
| dollar code { $$ = {op: "code", code: s.as_ref($2), start: $1.start, end: $2.end}; }
|
|
198
|
+
| qmark filter { $$ = {op: "filter", filter: $2, start: $1.start, end:$2.end}; }
|
|
199
|
+
| PIPE { $$ = {op: "pipe", start: $1.start, end: $1.end}; }
|
|
133
200
|
;
|
|
134
201
|
|
|
135
202
|
labelled
|
|
@@ -140,17 +207,17 @@ labelled
|
|
|
140
207
|
non_empty_labelled
|
|
141
208
|
: comp_label
|
|
142
209
|
{ $$ = {op: "product", product: [$1]}; }
|
|
143
|
-
| non_empty_labelled
|
|
210
|
+
| non_empty_labelled comma comp_label
|
|
144
211
|
{ $1.product = [].concat($1.product,$3); $$ = $1; }
|
|
145
212
|
;
|
|
146
213
|
|
|
147
214
|
comp_label
|
|
148
|
-
: comp name { $$ = {label: $2, exp: $1}; }
|
|
149
|
-
| comp str { $$ = {label: $2, exp: $1}; }
|
|
150
|
-
| comp int { $$ = {label: $2, exp: $1}; }
|
|
151
|
-
| name
|
|
152
|
-
| str
|
|
153
|
-
| int
|
|
215
|
+
: comp name { $$ = {label: $2.value, exp: $1}; }
|
|
216
|
+
| comp str { $$ = {label: $2.value, exp: $1}; }
|
|
217
|
+
| comp int { $$ = {label: $2.value, exp: $1}; }
|
|
218
|
+
| name col comp { $$ = {label: $1.value, exp: $3}; }
|
|
219
|
+
| str col comp { $$ = {label: $1.value, exp: $3}; }
|
|
220
|
+
| int col comp { $$ = {label: $1.value, exp: $3}; }
|
|
154
221
|
;
|
|
155
222
|
|
|
156
223
|
list
|
|
@@ -160,7 +227,7 @@ list
|
|
|
160
227
|
|
|
161
228
|
non_empty_list
|
|
162
229
|
: comp { $$ = [$1]; }
|
|
163
|
-
| non_empty_list
|
|
230
|
+
| non_empty_list comma comp { $$ = [].concat($1,$3); }
|
|
164
231
|
;
|
|
165
232
|
|
|
166
233
|
%%
|