occam-grammars 1.0.785 → 1.1.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/example.js +4520 -250
- package/index.html +3 -0
- package/lib/example/view/customGrammarBNF.js +2 -29
- package/lib/example/view/furtle.js +148 -0
- package/lib/example.js +5 -1
- package/lib/furtle/bnf.js +14 -0
- package/lib/furtle/entries.js +39 -0
- package/lib/furtle/lexer.js +148 -0
- package/lib/{basic → furtle}/parser.js +13 -13
- package/lib/index.js +9 -9
- package/lib/json/bnf.js +2 -2
- package/package.json +2 -1
- package/src/example/view/customGrammarBNF.js +5 -22
- package/src/example/view/furtle.js +137 -0
- package/src/example.js +2 -0
- package/src/furtle/bnf.js +193 -0
- package/src/furtle/entries.js +30 -0
- package/src/{basic → furtle}/lexer.js +12 -14
- package/src/furtle/parser.js +15 -0
- package/src/index.js +2 -2
- package/src/json/bnf.js +2 -2
- package/lib/basic/bnf.js +0 -15
- package/lib/basic/entries.js +0 -15
- package/lib/basic/lexer.js +0 -150
- package/src/basic/bnf.js +0 -7
- package/src/basic/entries.js +0 -7
- package/src/basic/parser.js +0 -15
package/lib/json/bnf.js
CHANGED
|
@@ -8,7 +8,7 @@ Object.defineProperty(exports, "default", {
|
|
|
8
8
|
return _default;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
var bnf = '\n\n\n document ::= json error* \n \n | error+ \n \n ;\n \n \n \n json ::= array \n \n | object \n \n | [string-literal] \n \n | [boolean] \n \n | [number] \n \n | [null] \n \n ;\n \n \n \n array
|
|
11
|
+
var bnf = '\n\n\n document ::= json error* \n \n | error+ \n \n ;\n \n \n \n json ::= array \n \n | object \n \n | [string-literal] \n \n | [boolean] \n \n | [number] \n \n | [null] \n \n ;\n \n \n \n array.. ::= "[" ( element ( "," element )* )? nonsense? "]" ;\n \n \n \n object.. ::= "{" ( property ( "," property )* )? nonsense? "}" ;\n \n \n \n property ::= [string-literal] ":" json ;\n \n \n\n element ::= json ;\n \n \n\n nonsense. ::= ( ":" | "," | [string-literal] | [number] | [boolean] | [null] | [unassigned] )+ ;\n \n\n\n error. ::= . ;\n \n\n';
|
|
12
12
|
var _default = bnf;
|
|
13
13
|
|
|
14
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
14
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9qc29uL2JuZi5qcyJdLCJzb3VyY2VzQ29udGVudCI6WyJcInVzZSBzdHJpY3RcIjtcblxuY29uc3QgYm5mID0gYFxuXG5cbiAgICBkb2N1bWVudCAgICAgOjo9ICBqc29uIGVycm9yKiBcbiAgICBcbiAgICAgICAgICAgICAgICAgICB8ICBlcnJvcisgXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcbiAgICAgICAgICAgICAgICAgICA7XG4gIFxuICBcbiAgXG4gICAganNvbiAgICAgICAgIDo6PSAgYXJyYXkgXG4gICAgXG4gICAgICAgICAgICAgICAgICAgfCAgb2JqZWN0IFxuICAgIFxuICAgICAgICAgICAgICAgICAgIHwgIFtzdHJpbmctbGl0ZXJhbF0gXG4gICAgXG4gICAgICAgICAgICAgICAgICAgfCAgW2Jvb2xlYW5dIFxuICAgIFxuICAgICAgICAgICAgICAgICAgIHwgIFtudW1iZXJdIFxuICAgIFxuICAgICAgICAgICAgICAgICAgIHwgIFtudWxsXSBcbiAgICBcbiAgICAgICAgICAgICAgICAgICA7XG4gIFxuICBcbiAgXG4gICAgYXJyYXkuLiAgICAgIDo6PSAgXCJbXCIgKCBlbGVtZW50ICggXCIsXCIgZWxlbWVudCApKiApPyBub25zZW5zZT8gXCJdXCIgO1xuICBcbiAgXG4gICAgIFxuICAgIG9iamVjdC4uICAgICA6Oj0gIFwie1wiICggcHJvcGVydHkgKCBcIixcIiBwcm9wZXJ0eSApKiApPyBub25zZW5zZT8gXCJ9XCIgO1xuICBcbiAgXG4gICAgXG4gICAgcHJvcGVydHkgICAgIDo6PSAgW3N0cmluZy1saXRlcmFsXSBcIjpcIiBqc29uIDtcbiAgXG4gICAgXG5cbiAgICBlbGVtZW50ICAgICAgOjo9ICBqc29uIDtcbiAgXG4gICAgXG5cbiAgICBub25zZW5zZS4gICAgOjo9ICAoIFwiOlwiIHwgXCIsXCIgfCBbc3RyaW5nLWxpdGVyYWxdIHwgW251bWJlcl0gfCBbYm9vbGVhbl0gfCBbbnVsbF0gfCBbdW5hc3NpZ25lZF0gKSsgO1xuICAgIFxuXG5cbiAgICBlcnJvci4gICAgICAgOjo9ICAuIDtcbiAgICBcblxuYDtcblxuZXhwb3J0IGRlZmF1bHQgYm5mO1xuIl0sIm5hbWVzIjpbImJuZiJdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7K0JBc0RBOzs7ZUFBQTs7O0FBcERBLElBQU1BLE1BQU87SUFvRGIsV0FBZUEifQ==
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "occam-grammars",
|
|
3
3
|
"author": "James Smith",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.1.1",
|
|
5
5
|
"license": "MIT, Anti-996",
|
|
6
6
|
"homepage": "https://github.com/djalbat/occam-grammars",
|
|
7
7
|
"description": "Occam's grammars.",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"express": "^4.17.1",
|
|
24
24
|
"juxtapose": "^4.0.108",
|
|
25
25
|
"lively-cli": "^2.0.65",
|
|
26
|
+
"occam-grammar-utilities": "^8.0.239",
|
|
26
27
|
"watchful-cli": "^1.7.56"
|
|
27
28
|
},
|
|
28
29
|
"scripts": {
|
|
@@ -5,23 +5,6 @@ import { CustomGrammarBNFLexer, CustomGrammarBNFParser } from "../../index"; //
|
|
|
5
5
|
import View from "../view";
|
|
6
6
|
|
|
7
7
|
export default class CustomGrammarBNFView extends View {
|
|
8
|
-
getParseTree(tokens) {
|
|
9
|
-
let parseTree = null;
|
|
10
|
-
|
|
11
|
-
const { Parser } = this.constructor,
|
|
12
|
-
parser = Parser.fromNothing(),
|
|
13
|
-
ruleName = this.getRuleName(),
|
|
14
|
-
ruleMap = parser.getRuleMap(),
|
|
15
|
-
rule = ruleMap[ruleName],
|
|
16
|
-
node = parser.parse(tokens, rule);
|
|
17
|
-
|
|
18
|
-
if (node !== null) {
|
|
19
|
-
parseTree = node.asParseTree(tokens);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return parseTree;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
8
|
static Lexer = CustomGrammarBNFLexer;
|
|
26
9
|
|
|
27
10
|
static Parser = CustomGrammarBNFParser;
|
|
@@ -30,16 +13,16 @@ export default class CustomGrammarBNFView extends View {
|
|
|
30
13
|
|
|
31
14
|
static initialContent = `
|
|
32
15
|
|
|
33
|
-
|
|
16
|
+
term ::= operation ( <NO_WHITESPACE>"(" term ")" )? ;
|
|
34
17
|
|
|
35
18
|
|
|
36
|
-
|
|
19
|
+
operation ::= "insert"<NO_WHITESPACE>"(" term "," term ")"
|
|
37
20
|
|
|
38
|
-
|
|
21
|
+
| "delete"<NO_WHITESPACE>"(" term "," term ")"
|
|
39
22
|
|
|
40
|
-
|
|
23
|
+
| "empty"<NO_WHITESPACE>"("<NO_WHITESPACE>")"
|
|
41
24
|
|
|
42
|
-
|
|
25
|
+
;
|
|
43
26
|
`;
|
|
44
27
|
|
|
45
28
|
static defaultProperties = {
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { lexerUtilities } from "occam-lexers";
|
|
4
|
+
import { parserUtilities } from "occam-parsers";
|
|
5
|
+
import { eliminateLeftRecursion } from "occam-grammar-utilities";
|
|
6
|
+
import { FurtleLexer, FurtleParser } from "../../index"; ///
|
|
7
|
+
|
|
8
|
+
import View from "../view";
|
|
9
|
+
|
|
10
|
+
const { rulesFromEntries, lexerFromRules } = lexerUtilities,
|
|
11
|
+
{ rulesFromBNF, parserFromRulesAndStartRuleName } = parserUtilities;
|
|
12
|
+
|
|
13
|
+
export default class FurtleView extends View {
|
|
14
|
+
getTokens() {
|
|
15
|
+
const lexicalEntries = this.getLexicalEntries(),
|
|
16
|
+
entries = lexicalEntries, ///
|
|
17
|
+
rules = rulesFromEntries(entries),
|
|
18
|
+
furtleLexer = lexerFromRules(FurtleLexer, rules),
|
|
19
|
+
lexer = furtleLexer, ///
|
|
20
|
+
content = this.getContent(),
|
|
21
|
+
tokens = lexer.tokenise(content);
|
|
22
|
+
|
|
23
|
+
return tokens;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
getParseTree(tokens) {
|
|
27
|
+
let parseTree = null;
|
|
28
|
+
|
|
29
|
+
const bnf = this.getBNF();
|
|
30
|
+
|
|
31
|
+
let rules;
|
|
32
|
+
|
|
33
|
+
rules = rulesFromBNF(bnf);
|
|
34
|
+
|
|
35
|
+
rules = eliminateLeftRecursion(rules); ///
|
|
36
|
+
|
|
37
|
+
const ruleName = this.getRuleName(),
|
|
38
|
+
startRuleName = ruleName, ///
|
|
39
|
+
furtleParser = parserFromRulesAndStartRuleName(FurtleParser, rules, startRuleName),
|
|
40
|
+
parser = furtleParser, ///
|
|
41
|
+
node = parser.parse(tokens);
|
|
42
|
+
|
|
43
|
+
if (node !== null) {
|
|
44
|
+
parseTree = node.asParseTree(tokens);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return parseTree;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
static Lexer = FurtleLexer;
|
|
51
|
+
|
|
52
|
+
static Parser = FurtleParser;
|
|
53
|
+
|
|
54
|
+
static readOnly = false;
|
|
55
|
+
|
|
56
|
+
static initialContent = `Node* termNode, statementNode; Boolean* bound = false;
|
|
57
|
+
|
|
58
|
+
String variableName = variableNameFromTermNode(termNode);
|
|
59
|
+
|
|
60
|
+
If (variableName == null) {
|
|
61
|
+
Break;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
Nodes statementNodes = nodesQuery(statementNode, //statement);
|
|
65
|
+
|
|
66
|
+
ForEach(statementNodes, (Node statementNode) {
|
|
67
|
+
String boundVariableName = boundVariableNameFromStatementNode(statementNode);
|
|
68
|
+
|
|
69
|
+
If (boundVariableName == variableName) {
|
|
70
|
+
bound = true;
|
|
71
|
+
|
|
72
|
+
Break;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
String variableNameFromTermNode(Node termNode) {
|
|
78
|
+
String variableName = null;
|
|
79
|
+
|
|
80
|
+
Node variableNameTerminalNode = nodeQuery(termNode, /term/variable/@name);
|
|
81
|
+
|
|
82
|
+
If (variableNameTerminalNode != null) {
|
|
83
|
+
String content;
|
|
84
|
+
|
|
85
|
+
{ content } = variableNameTerminalNode;
|
|
86
|
+
|
|
87
|
+
variableName = content;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
Return variableName;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
String boundVariableNameFromStatementNode(Node statementNode) {
|
|
94
|
+
String boundVariableName = null;
|
|
95
|
+
|
|
96
|
+
Nodes childNodes;
|
|
97
|
+
|
|
98
|
+
{ childNodes } = statementNode;
|
|
99
|
+
|
|
100
|
+
Node firstChildNode;
|
|
101
|
+
|
|
102
|
+
[ firstChildNode ] = childNodes;
|
|
103
|
+
|
|
104
|
+
Boolean firstChildNodeTerminalNode = isTerminalNode(firstChildNode);
|
|
105
|
+
|
|
106
|
+
If (firstChildNodeTerminalNode) {
|
|
107
|
+
Node terminalNode = firstChildNode;
|
|
108
|
+
|
|
109
|
+
String content;
|
|
110
|
+
|
|
111
|
+
{ content } = firstChildNode;
|
|
112
|
+
|
|
113
|
+
If ((content == "∀") || (content == "∃")) {
|
|
114
|
+
Node secondChildNode;
|
|
115
|
+
|
|
116
|
+
[ _, secondChildNode ] = childNodes;
|
|
117
|
+
|
|
118
|
+
Node argumentNode = secondChildNode;
|
|
119
|
+
|
|
120
|
+
Node boundVariableNameTerminalNode = nodeQuery(argumentNode, /argument/term/variable/@name);
|
|
121
|
+
|
|
122
|
+
If (boundVariableNameTerminalNode != null) {
|
|
123
|
+
{ content } = boundVariableNameTerminalNode;
|
|
124
|
+
|
|
125
|
+
boundVariableName = content;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
Return boundVariableName;
|
|
131
|
+
}
|
|
132
|
+
`;
|
|
133
|
+
|
|
134
|
+
static defaultProperties = {
|
|
135
|
+
className: "furtle"
|
|
136
|
+
};
|
|
137
|
+
}
|
package/src/example.js
CHANGED
|
@@ -8,6 +8,7 @@ import { Body } from "easy";
|
|
|
8
8
|
|
|
9
9
|
import TeXView from "./example/view/tex";
|
|
10
10
|
import JSONView from "./example/view/json";
|
|
11
|
+
import FurtleView from "./example/view/furtle";
|
|
11
12
|
import PlainTextView from "./example/view/plainText";
|
|
12
13
|
import CustomGrammarBNFView from "./example/view/customGrammarBNF";
|
|
13
14
|
import CustomGrammarPatternView from "./example/view/customGrammarPattern";
|
|
@@ -22,6 +23,7 @@ const body = new Body(),
|
|
|
22
23
|
switch (example) {
|
|
23
24
|
case "tex" : View = TeXView; break;
|
|
24
25
|
case "json" : View = JSONView; break;
|
|
26
|
+
case "furtle" : View = FurtleView; break;
|
|
25
27
|
case "plain-text" : View = PlainTextView; break;
|
|
26
28
|
case "custom-grammar-bnf" : View = CustomGrammarBNFView; break;
|
|
27
29
|
case "custom-grammar-pattern" : View = CustomGrammarPatternView; break;
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const bnf = `document ::= ( instruction | error )+ ;
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
instruction ::= functionDeclaration
|
|
8
|
+
|
|
9
|
+
| pointersDeclaration
|
|
10
|
+
|
|
11
|
+
| variablesDeclaration
|
|
12
|
+
|
|
13
|
+
| variableAssignment
|
|
14
|
+
|
|
15
|
+
| objectAssignment
|
|
16
|
+
|
|
17
|
+
| arrayAssignment
|
|
18
|
+
|
|
19
|
+
| conditionalBlock
|
|
20
|
+
|
|
21
|
+
| forEachLoop
|
|
22
|
+
|
|
23
|
+
| break
|
|
24
|
+
|
|
25
|
+
;
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
functionDeclaration ::= [type] function ;
|
|
30
|
+
|
|
31
|
+
pointersDeclaration ::= [type]<NO_WHITESPACE>"*" [name] assignment? ( "," [name] assignment? )* ";" ;
|
|
32
|
+
|
|
33
|
+
variablesDeclaration ::= [type] [name] assignment? ( "," [name] assignment? )* ";" ;
|
|
34
|
+
|
|
35
|
+
variableAssignment ::= [name] assignment ";" ;
|
|
36
|
+
|
|
37
|
+
objectAssignment ::= "{"
|
|
38
|
+
|
|
39
|
+
[name] ( "," [name] )*
|
|
40
|
+
|
|
41
|
+
"}" "=" [name] ";" ;
|
|
42
|
+
|
|
43
|
+
arrayAssignment ::= "["
|
|
44
|
+
|
|
45
|
+
(
|
|
46
|
+
|
|
47
|
+
( "_" ( "," "_" )* ( "," [name] )+ )
|
|
48
|
+
|
|
49
|
+
|
|
|
50
|
+
|
|
51
|
+
( [name] ( "," [name] )* )
|
|
52
|
+
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
"]" "=" [name] ";" ;
|
|
56
|
+
|
|
57
|
+
conditionalBlock ::= "If" "(" condition ")" block ( "Else" block )? ;
|
|
58
|
+
|
|
59
|
+
forEachLoop ::= "ForEach"<NO_WHITESPACE>"(" [name] "," anonymousFunction ")" ";" ;
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
assignment ::= "=" ( functionCall | isTerminalNode | nodesQuery | nodeQuery | value ) ;
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
block ::= "{" ( variablesDeclaration |
|
|
68
|
+
|
|
69
|
+
variableAssignment |
|
|
70
|
+
|
|
71
|
+
objectAssignment |
|
|
72
|
+
|
|
73
|
+
arrayAssignment |
|
|
74
|
+
|
|
75
|
+
conditionalBlock |
|
|
76
|
+
|
|
77
|
+
forEachLoop |
|
|
78
|
+
|
|
79
|
+
break )* "}" ;
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
functionCall ::= [name]<NO_WHITESPACE>"(" ( [name] ( "," [name] )* )? ")" ;
|
|
85
|
+
|
|
86
|
+
function ::= [name]<NO_WHITESPACE>"(" ( argument ( "," argument )* )? ")" body ;
|
|
87
|
+
|
|
88
|
+
anonymousFunction ::= "(" ( argument ( "," argument )* )? ")" body ;
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
isTerminalNode ::= "isTerminalNode"<NO_WHITESPACE>"(" [name] ")" ;
|
|
93
|
+
|
|
94
|
+
nodesQuery ::= "nodesQuery"<NO_WHITESPACE>"(" [name] "," expression ")" ;
|
|
95
|
+
|
|
96
|
+
nodeQuery ::= "nodeQuery"<NO_WHITESPACE>"(" [name] "," expression ")" ;
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
condition ::= "(" condition ")"
|
|
102
|
+
|
|
103
|
+
| condition ( "||" | "&&" ) condition
|
|
104
|
+
|
|
105
|
+
| value ( ( "!=" | "==" ) value )?
|
|
106
|
+
|
|
107
|
+
;
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
body ::= "{" ( variablesDeclaration |
|
|
112
|
+
|
|
113
|
+
variableAssignment |
|
|
114
|
+
|
|
115
|
+
objectAssignment |
|
|
116
|
+
|
|
117
|
+
arrayAssignment |
|
|
118
|
+
|
|
119
|
+
conditionalBlock |
|
|
120
|
+
|
|
121
|
+
forEachLoop |
|
|
122
|
+
|
|
123
|
+
break )* return? "}" ;
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
return ::= "Return" value ";" ;
|
|
128
|
+
|
|
129
|
+
break ::= "Break" ";" ;
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
value ::= [name] | [number] | [primitive] | [string-literal] ;
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
argument ::= [type] [name] ;
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
expression ::= path spread? subExpression? ;
|
|
142
|
+
|
|
143
|
+
path ::= "/" infiniteDescent? selectors ;
|
|
144
|
+
|
|
145
|
+
subExpression ::= path spread? subExpression?;
|
|
146
|
+
|
|
147
|
+
infiniteDescent ::= "/" ;
|
|
148
|
+
|
|
149
|
+
selectors ::= selector ( "|" selector )* ;
|
|
150
|
+
|
|
151
|
+
spread ::= unique
|
|
152
|
+
|
|
153
|
+
| "["
|
|
154
|
+
|
|
155
|
+
(
|
|
156
|
+
|
|
157
|
+
( startIndex "..." endIndex )
|
|
158
|
+
|
|
159
|
+
|
|
|
160
|
+
|
|
161
|
+
( startIndex "..." )
|
|
162
|
+
|
|
163
|
+
|
|
|
164
|
+
|
|
165
|
+
( "..." endIndex )
|
|
166
|
+
|
|
167
|
+
|
|
|
168
|
+
|
|
169
|
+
index
|
|
170
|
+
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
"]" ;
|
|
174
|
+
|
|
175
|
+
selector ::= ruleName | tokenType ;
|
|
176
|
+
|
|
177
|
+
ruleName ::= [name] | "*" ;
|
|
178
|
+
|
|
179
|
+
tokenType ::= "@"<NO_WHITESPACE>( [name] | "*" ) ;
|
|
180
|
+
|
|
181
|
+
startIndex ::= [number] ;
|
|
182
|
+
|
|
183
|
+
endIndex ::= [number] ;
|
|
184
|
+
|
|
185
|
+
index ::= [number] ;
|
|
186
|
+
|
|
187
|
+
unique ::= "!" ;
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
error. ::= . ;`;
|
|
192
|
+
|
|
193
|
+
export default bnf;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const entries = [
|
|
4
|
+
{
|
|
5
|
+
"type": "^(?:Boolean|String|Number|Nodes|Node|Void)"
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
"keyword": "^(?:If|Else|Return|ForEach|Break)"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"primitive": "^(?:null|true|false)"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"instruction": "^(?:nodeQuery|nodesQuery|isTerminalNode)"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"special": "^(?:!=|==|=|;|,|_|&&|\\|\\||@|!|\\*|\\||\\/|\\(|\\)|\\[|\\]|\\{|\\}|\\.\\.\\.)"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"name": "^[a-zA-Z\-]+"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"number": "^[0-9]+"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"unassigned": "^."
|
|
27
|
+
}
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
export default entries;
|
|
@@ -2,44 +2,42 @@
|
|
|
2
2
|
|
|
3
3
|
import { CommonLexer,
|
|
4
4
|
WhitespaceToken,
|
|
5
|
-
RegularExpressionToken,
|
|
6
5
|
EndOfLineNonSignificantToken,
|
|
7
|
-
SinglyQuotedStringLiteralToken,
|
|
8
6
|
DoublyQuotedStringLiteralToken,
|
|
9
|
-
PythonStyleSingleLineCommentToken,
|
|
10
7
|
EndOfLineCommentNonSignificantToken,
|
|
8
|
+
PythonStyleSingleLineCommentToken,
|
|
11
9
|
PythonStyleEndOfMultiLineCommentToken,
|
|
12
10
|
PythonStyleStartOfMultiLineCommentToken,
|
|
13
11
|
PythonStyleMiddleOfMultiLineCommentToken } from "occam-lexers";
|
|
14
12
|
|
|
15
13
|
import entries from "./entries";
|
|
16
14
|
|
|
17
|
-
export default class
|
|
15
|
+
export default class FurtleLexer extends CommonLexer {
|
|
18
16
|
static entries = entries;
|
|
19
17
|
|
|
20
18
|
static EndOfLineToken = EndOfLineNonSignificantToken; ///
|
|
21
19
|
|
|
22
20
|
static WhitespaceToken = WhitespaceToken;
|
|
23
21
|
|
|
24
|
-
static
|
|
22
|
+
static RegularExpressionToken = null;
|
|
25
23
|
|
|
26
|
-
static
|
|
24
|
+
static EndOfLineCommentToken = EndOfLineCommentNonSignificantToken;
|
|
27
25
|
|
|
28
|
-
static SingleLineCommentToken = PythonStyleSingleLineCommentToken;
|
|
26
|
+
static SingleLineCommentToken = PythonStyleSingleLineCommentToken;
|
|
29
27
|
|
|
30
|
-
static EndOfMultiLineCommentToken = PythonStyleEndOfMultiLineCommentToken;
|
|
28
|
+
static EndOfMultiLineCommentToken = PythonStyleEndOfMultiLineCommentToken; ///
|
|
31
29
|
|
|
32
|
-
static StartOfMultiLineCommentToken = PythonStyleStartOfMultiLineCommentToken;
|
|
30
|
+
static StartOfMultiLineCommentToken = PythonStyleStartOfMultiLineCommentToken; ///
|
|
33
31
|
|
|
34
|
-
static MiddleOfMultiLineCommentToken = PythonStyleMiddleOfMultiLineCommentToken;
|
|
32
|
+
static MiddleOfMultiLineCommentToken = PythonStyleMiddleOfMultiLineCommentToken; ///
|
|
35
33
|
|
|
36
|
-
static SinglyQuotedStringLiteralToken =
|
|
34
|
+
static SinglyQuotedStringLiteralToken = null;
|
|
37
35
|
|
|
38
36
|
static DoublyQuotedStringLiteralToken = DoublyQuotedStringLiteralToken;
|
|
39
37
|
|
|
40
|
-
static fromNothing() { return CommonLexer.fromNothing(
|
|
38
|
+
static fromNothing() { return CommonLexer.fromNothing(FurtleLexer); }
|
|
41
39
|
|
|
42
|
-
static fromRules(rules) { return CommonLexer.fromRules(
|
|
40
|
+
static fromRules(rules) { return CommonLexer.fromRules(FurtleLexer, rules); }
|
|
43
41
|
|
|
44
|
-
static fromEntries(entries) { return CommonLexer.fromEntries(
|
|
42
|
+
static fromEntries(entries) { return CommonLexer.fromEntries(FurtleLexer, entries); }
|
|
45
43
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { CommonParser } from "occam-parsers";
|
|
4
|
+
|
|
5
|
+
import bnf from "./bnf";
|
|
6
|
+
|
|
7
|
+
export default class FurtleParser extends CommonParser {
|
|
8
|
+
static bnf = bnf;
|
|
9
|
+
|
|
10
|
+
static fromNothing() { return CommonParser.fromNothing(FurtleParser); }
|
|
11
|
+
|
|
12
|
+
static fromBNF(bnf) { return CommonParser.fromBNF(FurtleParser, bnf); }
|
|
13
|
+
|
|
14
|
+
static fromRules(rules) { return CommonParser.fromRules(FurtleParser, rules); }
|
|
15
|
+
}
|
package/src/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
export { default as TeXLexer } from "./teX/lexer";
|
|
4
4
|
export { default as JSONLexer } from "./json/lexer";
|
|
5
|
-
export { default as
|
|
5
|
+
export { default as FurtleLexer } from "./furtle/lexer";
|
|
6
6
|
export { default as NominalLexer } from "./nominal/lexer";
|
|
7
7
|
export { default as PlainTextLexer } from "./plainText/lexer";
|
|
8
8
|
export { default as CustomGrammarBNFLexer } from "./customGrammarBNF/lexer";
|
|
@@ -10,7 +10,7 @@ export { default as CustomGrammarPatternLexer } from "./customGrammarPattern/lex
|
|
|
10
10
|
|
|
11
11
|
export { default as TeXParser } from "./teX/parser";
|
|
12
12
|
export { default as JSONParser } from "./json/parser";
|
|
13
|
-
export { default as
|
|
13
|
+
export { default as FurtleParser } from "./furtle/parser";
|
|
14
14
|
export { default as NominalParser } from "./nominal/parser";
|
|
15
15
|
export { default as PlainTextParser } from "./plainText/parser";
|
|
16
16
|
export { default as CustomGrammarBNFParser } from "./customGrammarBNF/parser";
|
package/src/json/bnf.js
CHANGED
|
@@ -27,11 +27,11 @@ const bnf = `
|
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
|
|
30
|
-
array
|
|
30
|
+
array.. ::= "[" ( element ( "," element )* )? nonsense? "]" ;
|
|
31
31
|
|
|
32
32
|
|
|
33
33
|
|
|
34
|
-
object
|
|
34
|
+
object.. ::= "{" ( property ( "," property )* )? nonsense? "}" ;
|
|
35
35
|
|
|
36
36
|
|
|
37
37
|
|
package/lib/basic/bnf.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "default", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return _default;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
var _occamparsers = require("occam-parsers");
|
|
12
|
-
var bnf = _occamparsers.BasicParser.bnf;
|
|
13
|
-
var _default = bnf;
|
|
14
|
-
|
|
15
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXNpYy9ibmYuanMiXSwic291cmNlc0NvbnRlbnQiOlsiXCJ1c2Ugc3RyaWN0XCI7XG5cbmltcG9ydCB7IEJhc2ljUGFyc2VyIH0gZnJvbSBcIm9jY2FtLXBhcnNlcnNcIjtcblxuY29uc3QgeyBibmYgfSA9IEJhc2ljUGFyc2VyO1xuXG5leHBvcnQgZGVmYXVsdCBibmY7XG4iXSwibmFtZXMiOlsiYm5mIiwiQmFzaWNQYXJzZXIiXSwibWFwcGluZ3MiOiJBQUFBOzs7OytCQU1BOzs7ZUFBQTs7OzRCQUo0QjtBQUU1QixJQUFNLEFBQUVBLE1BQVFDLHlCQUFXLENBQW5CRDtJQUVSLFdBQWVBIn0=
|
package/lib/basic/entries.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "default", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return _default;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
var _occamlexers = require("occam-lexers");
|
|
12
|
-
var entries = _occamlexers.BasicLexer.entries;
|
|
13
|
-
var _default = entries;
|
|
14
|
-
|
|
15
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXNpYy9lbnRyaWVzLmpzIl0sInNvdXJjZXNDb250ZW50IjpbIlwidXNlIHN0cmljdFwiO1xyXG5cclxuaW1wb3J0IHsgQmFzaWNMZXhlciB9IGZyb20gXCJvY2NhbS1sZXhlcnNcIjtcclxuXHJcbmNvbnN0IHsgZW50cmllcyB9ID0gQmFzaWNMZXhlcjtcclxuXHJcbmV4cG9ydCBkZWZhdWx0IGVudHJpZXM7XHJcbiJdLCJuYW1lcyI6WyJlbnRyaWVzIiwiQmFzaWNMZXhlciJdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7K0JBTUE7OztlQUFBOzs7MkJBSjJCO0FBRTNCLElBQU0sQUFBRUEsVUFBWUMsdUJBQVUsQ0FBdEJEO0lBRVIsV0FBZUEifQ==
|