yukigo-prolog-parser 0.1.3 → 0.2.2

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.
@@ -1,223 +1,224 @@
1
- @{% import {
2
- NumberPrimitive,
3
- StringPrimitive,
4
- Rule,
5
- Fact,
6
- Query,
7
- ListPrimitive,
8
- ConsExpression,
9
- ArithmeticBinaryOperation,
10
- ArithmeticUnaryOperation,
11
- ComparisonOperation,
12
- Exist,
13
- Not,
14
- Findall,
15
- Sequence,
16
- UnguardedBody,
17
- Equation,
18
- If,
19
- Call,
20
- Forall,
21
- SymbolPrimitive,
22
- AssignOperation,
23
- UnifyOperation,
24
- VariablePattern,
25
- FunctorPattern,
26
- ConsPattern,
27
- ListPattern,
28
- LogicConstraint,
29
- LiteralPattern,
30
- WildcardPattern,
31
- TuplePattern,
32
- Test,
33
- Assert,
34
- Truth
35
- } from "yukigo-ast"
36
-
37
- import { PrologLexer } from "./lexer.js"
38
-
39
- const asSequence = (d) => {
40
- if (d instanceof Sequence) return d;
41
- if (Array.isArray(d)) return d.length === 1 ? d[0] : new Sequence(d);
42
- return new Sequence([d]);
43
- };
44
-
45
- %}
46
- @preprocessor typescript
47
- @lexer PrologLexer
48
-
49
- program -> _ (clause _):* {% (d) => d[1].map(x => x[0]).filter(x => x !== null).flat(Infinity) %}
50
-
51
- clause -> (fact | rule | query | test_rule) {% (d) => d[0][0] %}
52
-
53
- fact -> any_atom arguments:? _ %period {% (d) => new Fact(d[0], d[1] ?? []) %}
54
-
55
- rule -> any_atom equation _ %period {% (d) => new Rule(d[0], [d[1]]) %}
56
-
57
- test_rule -> %testKeyword %lparen _ structural_literal test_args:? _ %rparen equation _ %period {% (d) => new Test(d[3], d[7].body.sequence, d[4] ? [d[4]] : []) %}
58
-
59
- test_args -> _ %comma _ pattern {% (d) => d[3] %}
60
-
61
- equation -> arguments:? _ %colonDash _ body {% (d) => new Equation(d[0] || [], new UnguardedBody(new Sequence(d[4])))%}
62
-
63
- query -> %queryOp _ body _ %period {% (d) => new Query(d[2]) %}
64
-
65
- body -> expression (_ (%comma | %semicolon) _ expression):* {% (d) => [d[0], ...d[1].map(x => x[3])] %}
66
-
67
- expression ->
68
- (conditional | forall | findall | unification | assignment | comparison | not | exist | assertion) {% (d) => d[0][0] %}
69
- | "(" _ body _ ")" {% (d) => new Sequence(d[2]) %}
70
-
71
- conditional -> "(" _ body _ "->" _ body _ %semicolon _ body _ ")" {% (d) =>
72
- new If(
73
- asSequence(d[2]),
74
- asSequence(d[6]),
75
- asSequence(d[10])
76
- )
77
- %}
78
-
79
- forall -> %forallRule "(" _ expression _ %comma _ expression _ ")" {% (d) => new Forall(d[3], d[7]) %}
80
-
81
- findall -> %findallRule "(" _ pattern _ %comma _ expression _ %comma _ pattern _ ")" {% (d) => new Findall(d[3], d[7], d[11]) %}
82
-
83
- not ->
84
- "not" "(" _ expression _ ")" {% (d) => new Not(asSequence(d[3])) %}
85
- | "\\+" _ expression {% (d) => new Not(d[2]) %}
86
-
87
- exist ->
88
- "call" %lparen _ pattern_list _ %rparen {% (d) => {
89
- const [callee, ...rest] = d[3]
90
- return new Call(callee.name, rest)
91
- } %}
92
- | any_atom arguments:? {% (d, l, reject) => {
93
- const val = d[0].value;
94
- if (["not", "\\+", "call", "assertion"].includes(val)) return reject;
95
- return new Exist(d[0], d[1] ?? [])
96
- } %}
97
- | variable {% (d) => new Exist(d[0], []) %}
98
-
99
- assertion -> "assertion" %lparen _ expression _ %rparen {% (d) =>
100
- new Assert(null, new Truth(asSequence(d[3])))
101
- %}
102
-
103
- assignment ->
104
- addition _ "is" _ addition {% (d) =>
105
- new LogicConstraint(new AssignOperation("Assign", d[0], d[4]))
106
- %}
107
-
108
- unification -> addition _ "=" _ addition {% (d) => new LogicConstraint(new UnifyOperation("Unify", d[0], d[4])) %}
109
-
110
- comparison ->
111
- addition _ comparison_op _ addition {% (d) =>
112
- new LogicConstraint(new ComparisonOperation(d[2], d[0], d[4]))
113
- %}
114
-
115
- addition ->
116
- multiplication _ "+" _ addition {% (d) => new ArithmeticBinaryOperation("Plus", d[0], d[4]) %}
117
- | multiplication _ "-" _ addition {% (d) => new ArithmeticBinaryOperation("Minus", d[0], d[4]) %}
118
- | multiplication {% id %}
119
-
120
- multiplication ->
121
- primary _ "*" _ multiplication {% (d) => new ArithmeticBinaryOperation("Multiply", d[0], d[4]) %}
122
- | primary _ "/" _ multiplication {% (d) => new ArithmeticBinaryOperation("Divide", d[0], d[4]) %}
123
- | primary {% id %}
124
-
125
- primary ->
126
- arithmetic_literal {% id %}
127
- | variable {% id %}
128
- | "-" _ primary {% (d) => new ArithmeticUnaryOperation("Negation", d[2]) %}
129
- | strict_atom arguments {% (d, l, reject) => {
130
- const val = d[0].value;
131
- if (["abs", "round", "sqrt", "max", "assertion"].includes(val)) return reject;
132
- return new Exist(d[0], d[1] ?? [])
133
- } %}
134
- | primitiveOperation {% id %}
135
- | cons_expr {% id %}
136
- | list_expr {% id %}
137
- | "(" _ addition _ ")" {% d => d[2] %}
138
-
139
- list_expr -> "[" _ primary_list:? _ "]" {% (d) => new ListPrimitive(d[2] || []) %}
140
-
141
- cons_expr -> "[" _ primary_list _ %consOp _ addition _ "]" {% (d) => {
142
- const heads = d[2];
143
- const tail = d[6];
144
- let current = tail;
145
- for (let i = heads.length - 1; i >= 0; i--) {
146
- current = new ConsExpression(heads[i], current);
147
- }
148
- return current;
149
- } %}
150
-
151
- primitiveOperation ->
152
- "round" __ addition {% d => new ArithmeticUnaryOperation("Round", d[2]) %}
153
- | "abs" __ addition {% d => new ArithmeticUnaryOperation("Absolute", d[2]) %}
154
- | "sqrt" __ addition {% d => new ArithmeticUnaryOperation("Sqrt", d[2]) %}
155
- | "max" "(" _ addition _ "," _ addition _ ")" {% d => new ArithmeticBinaryOperation("Max", d[3], d[7]) %}
156
-
157
- primitiveArguments -> %lparen _ primary_list _ %rparen {% (d) => d[2] %}
158
- primary_list -> addition (_ %comma _ addition):* {% (d) => [d[0], ...d[1].map(x => x[3])] %}
159
-
160
- arguments -> %lparen _ pattern_list _ %rparen {% (d) => d[2] %}
161
-
162
- pattern_list -> pattern (_ %comma _ pattern):* {% (d) => [d[0], ...d[1].map(x => x[3])] %}
163
-
164
- pattern ->
165
- infix_pattern {% id %}
166
- | primary_pattern {% id %}
167
-
168
- primary_pattern ->
169
- variable {% (d) => new VariablePattern(d[0]) %}
170
- | structural_literal {% (d) => new LiteralPattern(d[0]) %}
171
- | %wildcard {% (d) => new WildcardPattern() %}
172
- | any_atom arguments {% (d) => new FunctorPattern(d[0], d[1]) %}
173
- | "(" _ pattern_list _ ")" {% (d) => new TuplePattern(d[2]) %}
174
- | "[" _ pattern_list _ %consOp _ pattern _ "]" {% (d) => {
175
- const heads = d[2];
176
- const tail = d[6];
177
- let current = tail;
178
- for (let i = heads.length - 1; i >= 0; i--) {
179
- current = new ConsPattern(heads[i], current);
180
- }
181
- return current;
182
- } %}
183
- | "[" _ pattern_list:? _ "]" {% (d) => new ListPattern(d[2] ? d[2] : []) %}
184
-
185
- infix_pattern -> primary_pattern _ any_atom _ pattern {% (d) => new FunctorPattern(d[2], [d[0], d[4]]) %}
186
-
187
- variable -> %variable {% (d) => new SymbolPrimitive(d[0].value) %}
188
-
189
- strict_atom -> %atom {% (d) => new SymbolPrimitive(d[0].value) %}
190
- | %primitiveOperator {% (d) => new SymbolPrimitive(d[0].value) %}
191
-
192
- any_atom -> strict_atom {% id %}
193
- | (%op | %comparisonOp) {% (d) => new SymbolPrimitive(d[0][0].value) %}
194
-
195
- arithmetic_literal ->
196
- strict_atom {% id %}
197
- | %number {% (d) => new NumberPrimitive(Number(d[0].value)) %}
198
- | %string {% (d) => new StringPrimitive(d[0].value) %}
199
-
200
- structural_literal ->
201
- any_atom {% id %}
202
- | %number {% (d) => new NumberPrimitive(Number(d[0].value)) %}
203
- | %string {% (d) => new StringPrimitive(d[0].value) %}
204
-
205
- comparison_op ->
206
- "=:=" {% d => "Equal" %}
207
- | "=\\=" {% d => "NotEqual" %}
208
- | "==" {% d => "Same" %}
209
- | "\\==" {% d => "NotSame" %}
210
- | "\\=" {% d => "NotSame" %}
211
- | "@<" {% d => "LessThan" %}
212
- | "@=<" {% d => "LessOrEqualThan" %}
213
- | "@>" {% d => "GreaterThan" %}
214
- | "@>=" {% d => "GreaterOrEqualThan" %}
215
- | "<" {% d => "LessThan" %}
216
- | "=<" {% d => "LessOrEqualThan" %}
217
- | ">" {% d => "GreaterThan" %}
218
- | ">=" {% d => "GreaterOrEqualThan" %}
219
- | "=@=" {% d => "Same" %}
220
- | "\\=@=" {% d => "NotSame" %}
221
-
222
- _ -> %WS:*
223
- __ -> %WS:?
1
+ @{%
2
+ const {
3
+ NumberPrimitive,
4
+ BooleanPrimitive,
5
+ StringPrimitive,
6
+ Rule,
7
+ Fact,
8
+ Query,
9
+ ListPrimitive,
10
+ ConsExpression,
11
+ ArithmeticBinaryOperation,
12
+ ArithmeticUnaryOperation,
13
+ ComparisonOperation,
14
+ Exist,
15
+ Not,
16
+ Findall,
17
+ Sequence,
18
+ UnguardedBody,
19
+ Equation,
20
+ If,
21
+ Call,
22
+ Forall,
23
+ SymbolPrimitive,
24
+ AssignOperation,
25
+ UnifyOperation,
26
+ VariablePattern,
27
+ FunctorPattern,
28
+ ConsPattern,
29
+ ListPattern,
30
+ LogicConstraint,
31
+ LiteralPattern,
32
+ WildcardPattern,
33
+ TuplePattern,
34
+ Test,
35
+ Assert,
36
+ Truth
37
+ } = require("yukigo-ast")
38
+
39
+ const { PrologLexer } = require("./lexer.js")
40
+
41
+ const asSequence = (d) => {
42
+ if (d instanceof Sequence) return d;
43
+ if (Array.isArray(d)) return d.length === 1 ? d[0] : new Sequence(d);
44
+ return new Sequence([d]);
45
+ };
46
+
47
+ %}
48
+ @lexer PrologLexer
49
+
50
+ program -> _ (clause _):* {% (d) => d[1].map(x => x[0]).filter(x => x !== null).flat(Infinity) %}
51
+
52
+ clause -> (fact | rule | query | test_rule) {% (d) => d[0][0] %}
53
+
54
+ fact -> any_atom arguments:? _ %period {% (d) => new Fact(d[0], d[1] ?? []) %}
55
+
56
+ rule -> any_atom equation _ %period {% (d) => new Rule(d[0], [d[1]]) %}
57
+
58
+ test_rule -> %testKeyword %lparen _ structural_literal test_args:? _ %rparen _ (%colonDash | %colon) _ body _ %period {% (d) => new Test(d[3], new Sequence(d[10]), d[4] ? [d[4]] : []) %}
59
+
60
+ test_args -> _ %comma _ pattern {% (d) => d[3] %}
61
+
62
+ equation -> arguments:? _ %colonDash _ body {% (d) => new Equation(d[0] || [], new UnguardedBody(new Sequence(d[4])))%}
63
+
64
+ query -> %queryOp _ body _ %period {% (d) => new Query(d[2]) %}
65
+
66
+ body -> expression (_ (%comma | %semicolon) _ expression):* {% (d) => [d[0], ...d[1].map(x => x[3])] %}
67
+
68
+ expression ->
69
+ (conditional | forall | findall | unification | assignment | comparison | not | exist | assertion) {% (d) => d[0][0] %}
70
+ | "(" _ body _ ")" {% (d) => new Sequence(d[2]) %}
71
+
72
+ conditional -> "(" _ body _ "->" _ body _ %semicolon _ body _ ")" {% (d) =>
73
+ new If(
74
+ asSequence(d[2]),
75
+ asSequence(d[6]),
76
+ asSequence(d[10])
77
+ )
78
+ %}
79
+
80
+ forall -> %forallRule "(" _ expression _ %comma _ expression _ ")" {% (d) => new Forall(d[3], d[7]) %}
81
+
82
+ findall -> %findallRule "(" _ pattern _ %comma _ expression _ %comma _ pattern _ ")" {% (d) => new Findall(d[3], d[7], d[11]) %}
83
+
84
+ not ->
85
+ "not" "(" _ expression _ ")" {% (d) => new Not(asSequence(d[3])) %}
86
+ | "\\+" _ expression {% (d) => new Not(d[2]) %}
87
+
88
+ exist ->
89
+ "call" %lparen _ pattern_list _ %rparen {% (d) => {
90
+ const [callee, ...rest] = d[3]
91
+ return new Call(callee.name, rest)
92
+ } %}
93
+ | any_atom arguments:? {% (d, l, reject) => {
94
+ const val = d[0].value;
95
+ if (["not", "\\+", "call", "assertion"].includes(val)) return reject;
96
+ return new Exist(d[0], d[1] ?? [])
97
+ } %}
98
+ | variable {% (d) => new Exist(d[0], []) %}
99
+
100
+ assertion -> "assertion" %lparen _ expression _ %rparen {% (d) =>
101
+ new Assert(new BooleanPrimitive(false), new Truth(asSequence(d[3])))
102
+ %}
103
+
104
+ assignment ->
105
+ addition _ "is" _ addition {% (d) =>
106
+ new LogicConstraint(new AssignOperation("Assign", d[0], d[4]))
107
+ %}
108
+
109
+ unification -> addition _ "=" _ addition {% (d) => new LogicConstraint(new UnifyOperation("Unify", d[0], d[4])) %}
110
+
111
+ comparison ->
112
+ addition _ comparison_op _ addition {% (d) =>
113
+ new LogicConstraint(new ComparisonOperation(d[2], d[0], d[4]))
114
+ %}
115
+
116
+ addition ->
117
+ multiplication _ "+" _ addition {% (d) => new ArithmeticBinaryOperation("Plus", d[0], d[4]) %}
118
+ | multiplication _ "-" _ addition {% (d) => new ArithmeticBinaryOperation("Minus", d[0], d[4]) %}
119
+ | multiplication {% id %}
120
+
121
+ multiplication ->
122
+ primary _ "*" _ multiplication {% (d) => new ArithmeticBinaryOperation("Multiply", d[0], d[4]) %}
123
+ | primary _ "/" _ multiplication {% (d) => new ArithmeticBinaryOperation("Divide", d[0], d[4]) %}
124
+ | primary {% id %}
125
+
126
+ primary ->
127
+ arithmetic_literal {% id %}
128
+ | variable {% id %}
129
+ | "-" _ primary {% (d) => new ArithmeticUnaryOperation("Negation", d[2]) %}
130
+ | strict_atom arguments {% (d, l, reject) => {
131
+ const val = d[0].value;
132
+ if (["abs", "round", "sqrt", "max", "assertion"].includes(val)) return reject;
133
+ return new Exist(d[0], d[1] ?? [])
134
+ } %}
135
+ | primitiveOperation {% id %}
136
+ | cons_expr {% id %}
137
+ | list_expr {% id %}
138
+ | "(" _ addition _ ")" {% d => d[2] %}
139
+
140
+ list_expr -> "[" _ primary_list:? _ "]" {% (d) => new ListPrimitive(d[2] || []) %}
141
+
142
+ cons_expr -> "[" _ primary_list _ %consOp _ addition _ "]" {% (d) => {
143
+ const heads = d[2];
144
+ const tail = d[6];
145
+ let current = tail;
146
+ for (let i = heads.length - 1; i >= 0; i--) {
147
+ current = new ConsExpression(heads[i], current);
148
+ }
149
+ return current;
150
+ } %}
151
+
152
+ primitiveOperation ->
153
+ "round" __ addition {% d => new ArithmeticUnaryOperation("Round", d[2]) %}
154
+ | "abs" __ addition {% d => new ArithmeticUnaryOperation("Absolute", d[2]) %}
155
+ | "sqrt" __ addition {% d => new ArithmeticUnaryOperation("Sqrt", d[2]) %}
156
+ | "max" "(" _ addition _ "," _ addition _ ")" {% d => new ArithmeticBinaryOperation("Max", d[3], d[7]) %}
157
+
158
+ primitiveArguments -> %lparen _ primary_list _ %rparen {% (d) => d[2] %}
159
+ primary_list -> addition (_ %comma _ addition):* {% (d) => [d[0], ...d[1].map(x => x[3])] %}
160
+
161
+ arguments -> %lparen _ pattern_list _ %rparen {% (d) => d[2] %}
162
+
163
+ pattern_list -> pattern (_ %comma _ pattern):* {% (d) => [d[0], ...d[1].map(x => x[3])] %}
164
+
165
+ pattern ->
166
+ infix_pattern {% id %}
167
+ | primary_pattern {% id %}
168
+
169
+ primary_pattern ->
170
+ variable {% (d) => new VariablePattern(d[0]) %}
171
+ | structural_literal {% (d) => new LiteralPattern(d[0]) %}
172
+ | %wildcard {% (d) => new WildcardPattern() %}
173
+ | any_atom arguments {% (d) => new FunctorPattern(d[0], d[1]) %}
174
+ | "(" _ pattern_list _ ")" {% (d) => new TuplePattern(d[2]) %}
175
+ | "[" _ pattern_list _ %consOp _ pattern _ "]" {% (d) => {
176
+ const heads = d[2];
177
+ const tail = d[6];
178
+ let current = tail;
179
+ for (let i = heads.length - 1; i >= 0; i--) {
180
+ current = new ConsPattern(heads[i], current);
181
+ }
182
+ return current;
183
+ } %}
184
+ | "[" _ pattern_list:? _ "]" {% (d) => new ListPattern(d[2] ? d[2] : []) %}
185
+
186
+ infix_pattern -> primary_pattern _ any_atom _ pattern {% (d) => new FunctorPattern(d[2], [d[0], d[4]]) %}
187
+
188
+ variable -> %variable {% (d) => new SymbolPrimitive(d[0].value) %}
189
+
190
+ strict_atom -> %atom {% (d) => new SymbolPrimitive(d[0].value) %}
191
+ | %primitiveOperator {% (d) => new SymbolPrimitive(d[0].value) %}
192
+
193
+ any_atom -> strict_atom {% id %}
194
+ | (%op | %comparisonOp) {% (d) => new SymbolPrimitive(d[0][0].value) %}
195
+
196
+ arithmetic_literal ->
197
+ strict_atom {% id %}
198
+ | %number {% (d) => new NumberPrimitive(Number(d[0].value)) %}
199
+ | %string {% (d) => new StringPrimitive(d[0].value) %}
200
+
201
+ structural_literal ->
202
+ any_atom {% id %}
203
+ | %number {% (d) => new NumberPrimitive(Number(d[0].value)) %}
204
+ | %string {% (d) => new StringPrimitive(d[0].value) %}
205
+
206
+ comparison_op ->
207
+ "=:=" {% d => "Equal" %}
208
+ | "=\\=" {% d => "NotEqual" %}
209
+ | "==" {% d => "Same" %}
210
+ | "\\==" {% d => "NotSame" %}
211
+ | "\\=" {% d => "NotSame" %}
212
+ | "@<" {% d => "LessThan" %}
213
+ | "@=<" {% d => "LessOrEqualThan" %}
214
+ | "@>" {% d => "GreaterThan" %}
215
+ | "@>=" {% d => "GreaterOrEqualThan" %}
216
+ | "<" {% d => "LessThan" %}
217
+ | "=<" {% d => "LessOrEqualThan" %}
218
+ | ">" {% d => "GreaterThan" %}
219
+ | ">=" {% d => "GreaterOrEqualThan" %}
220
+ | "=@=" {% d => "Same" %}
221
+ | "\\=@=" {% d => "NotSame" %}
222
+
223
+ _ -> %WS:*
224
+ __ -> %WS:?
@@ -1,40 +1,42 @@
1
- import { makeLexer } from "moo-ignore";
2
- import moo from "moo";
3
- export const PrologLexerConfig = {
4
- WS: /[ \t]+/,
5
- wildcard: "_",
6
- notOperator: { match: ["\\+", "not"] },
7
- forallRule: "forall",
8
- findallRule: "findall",
9
- comment: /%.*|\/\*[\s\S]*?\*\//,
10
- number:
11
- /\b(?:[0-9]+(?:\.[0-9]+(?:e[+-]?[0-9]+)?)?|0o[0-7]+|0x[0-9a-fA-F]+|0b[01]+)\b/,
12
- string: /(?:'(?:[^']|'')*'|"(?:[^"]|"")*")/,
13
- backtick: "`",
14
- lparen: "(",
15
- rparen: ")",
16
- lbracket: "{",
17
- rbracket: "}",
18
- lsquare: "[",
19
- rsquare: "]",
20
- comma: ",",
21
- arrow: "->",
22
- period: ".",
23
- semicolon: ";",
24
- colonDash: ":-",
25
- consOp: "|",
26
- queryOp: "?-",
27
- comparisonOp: /@<|@=<|@>=|@>|<|=<|>=|>|=@=|\\=@=|=:=|=\\=|==|\\==|\\=|=/,
28
- op: /\+|-|\*|\/|\/\/|~|\^|\?|\$|''|\.\./,
29
- variable: /[A-Z][a-zA-Z0-9_\u00C0-\u00FF]*/,
30
- atom: {
31
- match: /[a-z!][a-zA-Z0-9_\u00C0-\u00FF]*/,
32
- type: moo.keywords({
33
- primitiveOperator: ["round", "abs", "sqrt", "call", "max", "assertion"],
34
- testKeyword: ["test"],
35
- }),
36
- },
37
- NL: { match: /\r?\n/, lineBreaks: true },
38
- };
39
-
40
- export const PrologLexer = makeLexer(PrologLexerConfig, ["comment", "NL"]);
1
+ // @ts-ignore
2
+ import { makeLexer } from "moo-ignore";
3
+ import moo from "moo";
4
+ export const PrologLexerConfig = {
5
+ WS: /[ \t]+/,
6
+ wildcard: "_",
7
+ notOperator: { match: ["\\+", "not"] },
8
+ forallRule: "forall",
9
+ findallRule: "findall",
10
+ comment: /%.*|\/\*[\s\S]*?\*\//,
11
+ number:
12
+ /\b(?:[0-9]+(?:\.[0-9]+(?:e[+-]?[0-9]+)?)?|0o[0-7]+|0x[0-9a-fA-F]+|0b[01]+)\b/,
13
+ string: /(?:'(?:[^']|'')*'|"(?:[^"]|"")*")/,
14
+ backtick: "`",
15
+ lparen: "(",
16
+ rparen: ")",
17
+ lbracket: "{",
18
+ rbracket: "}",
19
+ lsquare: "[",
20
+ rsquare: "]",
21
+ comma: ",",
22
+ arrow: "->",
23
+ period: ".",
24
+ semicolon: ";",
25
+ colonDash: ":-",
26
+ colon: ":",
27
+ consOp: "|",
28
+ queryOp: "?-",
29
+ comparisonOp: /@<|@=<|@>=|@>|<|=<|>=|>|=@=|\\=@=|=:=|=\\=|==|\\==|\\=|=/,
30
+ op: /\+|-|\*|\/|\/\/|~|\^|\?|\$|''|\.\./,
31
+ variable: /[A-Z][a-zA-Z0-9_\u00C0-\u00FF]*/,
32
+ atom: {
33
+ match: /[a-z!][a-zA-Z0-9_\u00C0-\u00FF]*/,
34
+ type: moo.keywords({
35
+ primitiveOperator: ["round", "abs", "sqrt", "call", "max", "assertion"],
36
+ testKeyword: ["test"],
37
+ }),
38
+ },
39
+ NL: { match: /\r?\n/, lineBreaks: true },
40
+ };
41
+
42
+ export const PrologLexer = makeLexer(PrologLexerConfig, ["comment", "NL"]);