Moved parser javascript into single block
This commit is contained in:
@@ -3,28 +3,38 @@
|
|||||||
(function () {
|
(function () {
|
||||||
function id(x) { return x[0]; }
|
function id(x) { return x[0]; }
|
||||||
|
|
||||||
const moo = require("moo");
|
const moo = require("moo");
|
||||||
|
|
||||||
const lexer = moo.compile({
|
const lexer = moo.compile({
|
||||||
number: /[0-9]+(?:\.[0-9]+)?/,
|
number: /[0-9]+(?:\.[0-9]+)?/,
|
||||||
string: /'.*?'|".*?"/,
|
string: {
|
||||||
name: {match: /[a-zA-Z]+\w*?/, type: moo.keywords({
|
match: /'.*?'|".*?"/,
|
||||||
'keywords': ['if', 'else', 'd'],
|
value: s => s.slice(1, -1),
|
||||||
})},
|
},
|
||||||
space: {match: /\s+/, lineBreaks: true},
|
name: {
|
||||||
separators: [',', '.'],
|
match: /[a-zA-Z]+\w*?/,
|
||||||
multiplicativeOperator: ['*', '/'],
|
type: moo.keywords({
|
||||||
exponentOperator: ['^'],
|
'keywords': ['if', 'else', 'd'],
|
||||||
additiveOperator: ['+', '-'],
|
}),
|
||||||
unaryOperator: ['-'],
|
},
|
||||||
andOperator: ['&', '&&'],
|
space: {
|
||||||
orOperator: ['|', '||'],
|
match: /\s+/,
|
||||||
equalityOperator: ['=', '==', '===', '!=', '!=='],
|
lineBreaks: true,
|
||||||
relationalOperator: ['>', '<', '>=', '<='],
|
},
|
||||||
brackets: ['(', ')', '{', '}'],
|
separators: [',', '.'],
|
||||||
});
|
multiplicativeOperator: ['*', '/'],
|
||||||
|
exponentOperator: ['^'],
|
||||||
|
additiveOperator: ['+', '-'],
|
||||||
|
unaryOperator: ['-'],
|
||||||
|
andOperator: ['&', '&&'],
|
||||||
|
orOperator: ['|', '||'],
|
||||||
|
stringDelimiters: ['\"', '\''],
|
||||||
|
equalityOperator: ['=', '==', '===', '!=', '!=='],
|
||||||
|
relationalOperator: ['>', '<', '>=', '<='],
|
||||||
|
brackets: ['(', ')', '{', '}'],
|
||||||
|
});
|
||||||
|
|
||||||
function nuller() { return null; }
|
function nuller() { return null; }
|
||||||
|
|
||||||
class OperatorNode {
|
class OperatorNode {
|
||||||
constructor({left, right, operator, fn}) {
|
constructor({left, right, operator, fn}) {
|
||||||
@@ -51,8 +61,8 @@ function id(x) { return x[0]; }
|
|||||||
|
|
||||||
class ConstantNode {
|
class ConstantNode {
|
||||||
constructor(value, type){
|
constructor(value, type){
|
||||||
this.value = value;
|
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
this.value = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var grammar = {
|
var grammar = {
|
||||||
|
|||||||
@@ -1,29 +1,37 @@
|
|||||||
@{%
|
@{%
|
||||||
const moo = require("moo");
|
const moo = require("moo");
|
||||||
|
|
||||||
const lexer = moo.compile({
|
const lexer = moo.compile({
|
||||||
number: /[0-9]+(?:\.[0-9]+)?/,
|
number: /[0-9]+(?:\.[0-9]+)?/,
|
||||||
string: /'.*?'|".*?"/,
|
string: {
|
||||||
name: {match: /[a-zA-Z]+\w*?/, type: moo.keywords({
|
match: /'.*?'|".*?"/,
|
||||||
'keywords': ['if', 'else', 'd'],
|
value: s => s.slice(1, -1),
|
||||||
})},
|
},
|
||||||
space: {match: /\s+/, lineBreaks: true},
|
name: {
|
||||||
separators: [',', '.'],
|
match: /[a-zA-Z]+\w*?/,
|
||||||
multiplicativeOperator: ['*', '/'],
|
type: moo.keywords({
|
||||||
exponentOperator: ['^'],
|
'keywords': ['if', 'else', 'd'],
|
||||||
additiveOperator: ['+', '-'],
|
}),
|
||||||
unaryOperator: ['-'],
|
},
|
||||||
andOperator: ['&', '&&'],
|
space: {
|
||||||
orOperator: ['|', '||'],
|
match: /\s+/,
|
||||||
equalityOperator: ['=', '==', '===', '!=', '!=='],
|
lineBreaks: true,
|
||||||
relationalOperator: ['>', '<', '>=', '<='],
|
},
|
||||||
brackets: ['(', ')', '{', '}'],
|
separators: [',', '.'],
|
||||||
});
|
multiplicativeOperator: ['*', '/'],
|
||||||
%}
|
exponentOperator: ['^'],
|
||||||
|
additiveOperator: ['+', '-'],
|
||||||
|
unaryOperator: ['-'],
|
||||||
|
andOperator: ['&', '&&'],
|
||||||
|
orOperator: ['|', '||'],
|
||||||
|
stringDelimiters: ['\"', '\''],
|
||||||
|
equalityOperator: ['=', '==', '===', '!=', '!=='],
|
||||||
|
relationalOperator: ['>', '<', '>=', '<='],
|
||||||
|
brackets: ['(', ')', '{', '}'],
|
||||||
|
});
|
||||||
|
|
||||||
@{% function nuller() { return null; } %}
|
function nuller() { return null; }
|
||||||
|
|
||||||
@{%
|
|
||||||
class OperatorNode {
|
class OperatorNode {
|
||||||
constructor({left, right, operator, fn}) {
|
constructor({left, right, operator, fn}) {
|
||||||
this.left = left;
|
this.left = left;
|
||||||
@@ -49,8 +57,8 @@
|
|||||||
|
|
||||||
class ConstantNode {
|
class ConstantNode {
|
||||||
constructor(value, type){
|
constructor(value, type){
|
||||||
this.value = value;
|
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
this.value = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
%}
|
%}
|
||||||
|
|||||||
Reference in New Issue
Block a user