yapp 2.2.184 → 3.0.4
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 +102 -444
- package/lib/example/view.js +3 -8
- package/lib/index.js +1 -9
- package/lib/lexer/javascript.js +6 -18
- package/lib/lexer/json.js +7 -20
- package/lib/lexer/plainText.js +7 -20
- package/lib/lexer/xml.js +6 -18
- package/lib/parser/javascript.js +10 -19
- package/lib/parser/json.js +10 -19
- package/lib/parser/plainText.js +10 -19
- package/lib/parser/xml.js +10 -19
- package/lib/plugin/javascript.js +3 -5
- package/lib/plugin/json.js +3 -5
- package/lib/plugin/plainText.js +3 -5
- package/lib/plugin/xml.js +3 -5
- package/lib/plugin.js +3 -2
- package/package.json +2 -2
- package/src/example/view.js +7 -14
- package/src/index.js +0 -2
- package/src/lexer/javascript.js +5 -8
- package/src/lexer/json.js +5 -8
- package/src/lexer/plainText.js +5 -9
- package/src/lexer/xml.js +4 -7
- package/src/parser/javascript.js +139 -142
- package/src/parser/json.js +16 -14
- package/src/parser/plainText.js +10 -8
- package/src/parser/xml.js +24 -22
- package/src/plugin/javascript.js +1 -1
- package/src/plugin/json.js +1 -1
- package/src/plugin/plainText.js +1 -1
- package/src/plugin/xml.js +1 -1
- package/src/plugin.js +5 -1
- package/lib/lexer/yapp.js +0 -93
- package/lib/parser/yapp.js +0 -132
- package/src/lexer/yapp.js +0 -5
- package/src/parser/yapp.js +0 -29
package/src/example/view.js
CHANGED
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
import withStyle from "easy-with-style"; ///
|
|
4
4
|
|
|
5
5
|
import { Element } from "easy";
|
|
6
|
-
import {
|
|
7
|
-
import { BNFParser } from "occam-parsers";
|
|
8
|
-
import { eliminateLeftRecursion, rewriteNodes } from "occam-grammar-utilities";
|
|
6
|
+
import { rewriteNodes, parserUtilities } from "occam-grammar-utilities";
|
|
9
7
|
import { RowDiv, RowsDiv, ColumnDiv, ColumnsDiv, VerticalSplitterDiv, HorizontalSplitterDiv } from "easy-layout";
|
|
10
8
|
|
|
11
9
|
import Yapp from "./yapp";
|
|
@@ -19,8 +17,7 @@ import MiddleSizeableDiv from "./div/sizeable/middle";
|
|
|
19
17
|
import ParseTreeTextarea from "./textarea/parseTree";
|
|
20
18
|
import LexicalEntriesTextarea from "./textarea/lexicalEntries";
|
|
21
19
|
|
|
22
|
-
const
|
|
23
|
-
bnfParser = BNFParser.fromNothing();
|
|
20
|
+
const { rulesFromBNF } = parserUtilities;
|
|
24
21
|
|
|
25
22
|
class View extends Element {
|
|
26
23
|
contentChangeHandler(event, element) {
|
|
@@ -29,17 +26,12 @@ class View extends Element {
|
|
|
29
26
|
|
|
30
27
|
keyUpHandler(event, element) {
|
|
31
28
|
try {
|
|
32
|
-
const lexicalEntries = this.getLexicalEntries(),
|
|
33
|
-
entries = lexicalEntries, ///
|
|
34
|
-
bnf = this.getBNF(),
|
|
35
|
-
tokens = bnfLexer.tokensFromBNF(bnf);
|
|
36
|
-
|
|
37
|
-
let rules = bnfParser.rulesFromTokens(tokens);
|
|
38
|
-
|
|
39
|
-
rules = eliminateLeftRecursion(rules);
|
|
40
|
-
|
|
41
29
|
const { Plugin } = this.constructor,
|
|
42
30
|
{ Lexer, Parser } = Plugin,
|
|
31
|
+
lexicalEntries = this.getLexicalEntries(),
|
|
32
|
+
bnf = this.getBNF(),
|
|
33
|
+
entries = lexicalEntries, ///
|
|
34
|
+
rules = rulesFromBNF(bnf),
|
|
43
35
|
lexer = Lexer.fromEntries(entries),
|
|
44
36
|
parser = Parser.fromRules(rules),
|
|
45
37
|
yappLexer = lexer, ///
|
|
@@ -64,6 +56,7 @@ class View extends Element {
|
|
|
64
56
|
yappHeight = topSizeableDivHeight; ///
|
|
65
57
|
|
|
66
58
|
this.setYappWidth(yappWidth);
|
|
59
|
+
|
|
67
60
|
this.setYappHeight(yappHeight);
|
|
68
61
|
|
|
69
62
|
this.resizeYapp();
|
package/src/index.js
CHANGED
|
@@ -4,8 +4,6 @@ import Yapp from "./yapp";
|
|
|
4
4
|
|
|
5
5
|
export default Yapp;
|
|
6
6
|
|
|
7
|
-
export { default as YappLexer } from "./lexer/yapp";
|
|
8
|
-
export { default as YappParser } from "./parser/yapp";
|
|
9
7
|
export { default as syntaxStyle } from "./style/syntax";
|
|
10
8
|
export { default as colourScheme } from "./scheme/colour";
|
|
11
9
|
export { default as firaCodeStyle } from "./style/firaCode";
|
package/src/lexer/javascript.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { CommonLexer,
|
|
4
|
+
WhitespaceToken,
|
|
4
5
|
EndOfLineNonSignificantToken,
|
|
5
6
|
CStyleSingleLineCommentToken,
|
|
6
7
|
SinglyQuotedStringLiteralToken,
|
|
@@ -10,8 +11,6 @@ import { WhitespaceToken,
|
|
|
10
11
|
CStyleMiddleOfMultiLineCommentToken,
|
|
11
12
|
EndOfLineCommentNonSignificantToken } from "occam-lexers";
|
|
12
13
|
|
|
13
|
-
import YappLexer from "../lexer/yapp";
|
|
14
|
-
|
|
15
14
|
const entries = [
|
|
16
15
|
{
|
|
17
16
|
"delimiter": "^(?:`|\\$\\{|<\\/|\\/>)"
|
|
@@ -36,7 +35,7 @@ const entries = [
|
|
|
36
35
|
}
|
|
37
36
|
];
|
|
38
37
|
|
|
39
|
-
export default class JavaScriptLexer extends
|
|
38
|
+
export default class JavaScriptLexer extends CommonLexer {
|
|
40
39
|
static entries = entries;
|
|
41
40
|
|
|
42
41
|
static EndOfLineToken = EndOfLineNonSignificantToken; ///
|
|
@@ -59,9 +58,7 @@ export default class JavaScriptLexer extends YappLexer {
|
|
|
59
58
|
|
|
60
59
|
static DoublyQuotedStringLiteralToken = DoublyQuotedStringLiteralToken;
|
|
61
60
|
|
|
62
|
-
static fromNothing() { return
|
|
63
|
-
|
|
64
|
-
static fromRules(rules) { return YappLexer.fromRules(JavaScriptLexer, rules); }
|
|
61
|
+
static fromNothing() { return CommonLexer.fromNothing(JavaScriptLexer); }
|
|
65
62
|
|
|
66
|
-
static fromEntries(entries) { return
|
|
63
|
+
static fromEntries(entries) { return CommonLexer.fromEntries(JavaScriptLexer, entries); }
|
|
67
64
|
}
|
package/src/lexer/json.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import { WhitespaceToken, EndOfLineNonSignificantToken, DoublyQuotedStringLiteralToken, EndOfLineCommentNonSignificantToken } from "occam-lexers";
|
|
3
|
+
import { CommonLexer, WhitespaceToken, EndOfLineNonSignificantToken, DoublyQuotedStringLiteralToken } from "occam-lexers";
|
|
5
4
|
|
|
6
5
|
const entries = [
|
|
7
6
|
{
|
|
@@ -18,14 +17,14 @@ const entries = [
|
|
|
18
17
|
}
|
|
19
18
|
];
|
|
20
19
|
|
|
21
|
-
export default class JSONLexer extends
|
|
20
|
+
export default class JSONLexer extends CommonLexer {
|
|
22
21
|
static entries = entries;
|
|
23
22
|
|
|
24
23
|
static EndOfLineToken = EndOfLineNonSignificantToken; ///
|
|
25
24
|
|
|
26
25
|
static WhitespaceToken = WhitespaceToken;
|
|
27
26
|
|
|
28
|
-
static EndOfLineCommentToken =
|
|
27
|
+
static EndOfLineCommentToken = null;
|
|
29
28
|
|
|
30
29
|
static SingleLineCommentToken = null;
|
|
31
30
|
|
|
@@ -41,9 +40,7 @@ export default class JSONLexer extends YappLexer {
|
|
|
41
40
|
|
|
42
41
|
static DoublyQuotedStringLiteralToken = DoublyQuotedStringLiteralToken;
|
|
43
42
|
|
|
44
|
-
static fromNothing() { return
|
|
43
|
+
static fromNothing() { return CommonLexer.fromNothing(JSONLexer); }
|
|
45
44
|
|
|
46
|
-
static
|
|
47
|
-
|
|
48
|
-
static fromEntries(entries) { return YappLexer.fromEntries(JSONLexer, entries); }
|
|
45
|
+
static fromEntries(entries) { return CommonLexer.fromEntries(JSONLexer, entries); }
|
|
49
46
|
}
|
package/src/lexer/plainText.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import { WhitespaceToken, EndOfLineNonSignificantToken
|
|
4
|
-
|
|
5
|
-
import YappLexer from "../lexer/yapp";
|
|
3
|
+
import { CommonLexer, WhitespaceToken, EndOfLineNonSignificantToken } from "occam-lexers";
|
|
6
4
|
|
|
7
5
|
const entries = [
|
|
8
6
|
{
|
|
@@ -10,14 +8,14 @@ const entries = [
|
|
|
10
8
|
}
|
|
11
9
|
];
|
|
12
10
|
|
|
13
|
-
export default class PlainTextLexer extends
|
|
11
|
+
export default class PlainTextLexer extends CommonLexer {
|
|
14
12
|
static entries = entries;
|
|
15
13
|
|
|
16
14
|
static EndOfLineToken = EndOfLineNonSignificantToken; ///
|
|
17
15
|
|
|
18
16
|
static WhitespaceToken = WhitespaceToken;
|
|
19
17
|
|
|
20
|
-
static EndOfLineCommentToken =
|
|
18
|
+
static EndOfLineCommentToken = null;
|
|
21
19
|
|
|
22
20
|
static SingleLineCommentToken = null;
|
|
23
21
|
|
|
@@ -33,9 +31,7 @@ export default class PlainTextLexer extends YappLexer {
|
|
|
33
31
|
|
|
34
32
|
static DoublyQuotedStringLiteralToken = null;
|
|
35
33
|
|
|
36
|
-
static fromNothing() { return
|
|
37
|
-
|
|
38
|
-
static fromRules(rules) { return YappLexer.fromRules(PlainTextLexer, rules); }
|
|
34
|
+
static fromNothing() { return CommonLexer.fromNothing(PlainTextLexer); }
|
|
39
35
|
|
|
40
|
-
static fromEntries(entries) { return
|
|
36
|
+
static fromEntries(entries) { return CommonLexer.fromEntries(PlainTextLexer, entries); }
|
|
41
37
|
}
|
package/src/lexer/xml.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import { WhitespaceToken, EndOfLineNonSignificantToken, DoublyQuotedStringLiteralToken } from "occam-lexers";
|
|
3
|
+
import { CommonLexer, WhitespaceToken, EndOfLineNonSignificantToken, DoublyQuotedStringLiteralToken } from "occam-lexers";
|
|
5
4
|
|
|
6
5
|
const entries = [
|
|
7
6
|
{
|
|
@@ -15,7 +14,7 @@ const entries = [
|
|
|
15
14
|
}
|
|
16
15
|
];
|
|
17
16
|
|
|
18
|
-
export default class XMLLexer extends
|
|
17
|
+
export default class XMLLexer extends CommonLexer {
|
|
19
18
|
static entries = entries;
|
|
20
19
|
|
|
21
20
|
static EndOfLineToken = EndOfLineNonSignificantToken; ///
|
|
@@ -38,9 +37,7 @@ export default class XMLLexer extends YappLexer {
|
|
|
38
37
|
|
|
39
38
|
static DoublyQuotedStringLiteralToken = DoublyQuotedStringLiteralToken;
|
|
40
39
|
|
|
41
|
-
static fromNothing() { return
|
|
40
|
+
static fromNothing() { return CommonLexer.fromNothing(XMLLexer); }
|
|
42
41
|
|
|
43
|
-
static
|
|
44
|
-
|
|
45
|
-
static fromEntries(entries) { return YappLexer.fromEntries(XMLLexer, entries); }
|
|
42
|
+
static fromEntries(entries) { return CommonLexer.fromEntries(XMLLexer, entries); }
|
|
46
43
|
}
|
package/src/parser/javascript.js
CHANGED
|
@@ -1,297 +1,294 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import { CommonParser } from "occam-parsers";
|
|
4
|
+
import { parserUtilities } from "occam-grammar-utilities";
|
|
5
|
+
|
|
6
|
+
const { rulesFromBNF, parserFromRules } = parserUtilities;
|
|
4
7
|
|
|
5
8
|
const bnf = `
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
document ::= preamble ( statement | function | class | error )*
|
|
11
|
+
|
|
12
|
+
| ( statement | function | class | error )+
|
|
13
|
+
|
|
14
|
+
;
|
|
12
15
|
|
|
13
16
|
|
|
14
17
|
|
|
15
|
-
|
|
18
|
+
preamble ::= ( "\\"use strict\\"" | "'use strict'" ) ";" ;
|
|
16
19
|
|
|
17
20
|
|
|
18
21
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
statement ::= statementBody... ";"
|
|
23
|
+
|
|
24
|
+
| "{" ( statement | function )* "}"
|
|
25
|
+
|
|
26
|
+
| "if" "(" expression... ")" statement ( "else" statement )?
|
|
24
27
|
|
|
25
|
-
|
|
28
|
+
| "for" ( ( "(" initialiser ( ";" expression )? ( ";" expression )? ")" statement )
|
|
26
29
|
|
|
27
|
-
|
|
30
|
+
| ( "(" variable "in" expression... ")" statement )
|
|
28
31
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
| ( "await"? "(" variable "of" expression... ")" statement )
|
|
33
|
+
|
|
34
|
+
)
|
|
32
35
|
|
|
33
|
-
|
|
36
|
+
| "do" statement "while" "(" expression... ")"
|
|
34
37
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
| "while" "(" expression... ")" statement
|
|
39
|
+
|
|
40
|
+
| "switch" "(" expression... ")" "{" case* defaultCase? "}"
|
|
38
41
|
|
|
39
|
-
|
|
42
|
+
| try ( ( catch* finally ) | catch+ )
|
|
40
43
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
;
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
45
48
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
class ::= ( "export" "default"? )? "class" name classBody
|
|
50
|
+
|
|
51
|
+
| "export" "default" "class" classBody
|
|
52
|
+
|
|
53
|
+
;
|
|
51
54
|
|
|
52
55
|
|
|
53
56
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
+
function ::= ( "export" "default"? )? "async"? "function" name functionBody
|
|
58
|
+
|
|
59
|
+
| "export" "default" "async"? "function" functionBody
|
|
57
60
|
|
|
58
|
-
|
|
61
|
+
;
|
|
59
62
|
|
|
60
63
|
|
|
61
64
|
|
|
62
|
-
|
|
65
|
+
statementBody ::= "import" ( [string-literal]
|
|
63
66
|
|
|
64
|
-
|
|
67
|
+
| ( name "from" [string-literal] )
|
|
65
68
|
|
|
66
|
-
|
|
69
|
+
| ( "{" names "}" "from" [string-literal] )
|
|
67
70
|
|
|
68
|
-
|
|
71
|
+
| ( "*" "as" name "from" [string-literal] )
|
|
69
72
|
|
|
70
|
-
|
|
73
|
+
)
|
|
71
74
|
|
|
72
|
-
|
|
75
|
+
| "export" ( ( "{" names "}" ( "from" [string-literal] )? )
|
|
73
76
|
|
|
74
|
-
|
|
77
|
+
| ( "const" "{" fields "}" "=" expression )
|
|
75
78
|
|
|
76
|
-
|
|
79
|
+
| ( "{" "default" "}" "from" [string-literal] )
|
|
77
80
|
|
|
78
|
-
|
|
81
|
+
| ( "*" ( "as" name )? "from" [string-literal] )
|
|
79
82
|
|
|
80
|
-
|
|
83
|
+
)
|
|
81
84
|
|
|
82
|
-
|
|
85
|
+
| "export"? ( ( "var" var ( "," var )* )
|
|
83
86
|
|
|
84
|
-
|
|
87
|
+
| ( "let" let ( "," let )* )
|
|
85
88
|
|
|
86
|
-
|
|
89
|
+
| ( "const" const ( "," const )* )
|
|
87
90
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
| ( "export" "default" )? expression
|
|
91
94
|
|
|
92
|
-
|
|
95
|
+
| "return" expression?
|
|
93
96
|
|
|
94
|
-
|
|
97
|
+
| "throw" expression
|
|
95
98
|
|
|
96
|
-
|
|
99
|
+
| "delete" expression
|
|
97
100
|
|
|
98
|
-
|
|
101
|
+
| "break"
|
|
99
102
|
|
|
100
|
-
|
|
103
|
+
| "continue"
|
|
101
104
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
+
| "debugger"
|
|
106
|
+
|
|
107
|
+
;
|
|
105
108
|
|
|
106
109
|
|
|
107
110
|
|
|
108
|
-
|
|
111
|
+
functionBody ::= "(" arguments? ")" "{" ( statement | function )* "}" ;
|
|
109
112
|
|
|
110
113
|
|
|
111
114
|
|
|
112
|
-
|
|
115
|
+
classBody ::= ( "extends" name )? "{" ( constructor | method | field )* "}" ;
|
|
113
116
|
|
|
114
117
|
|
|
115
118
|
|
|
116
|
-
|
|
119
|
+
constructor ::= "constructor" functionBody ;
|
|
117
120
|
|
|
118
|
-
|
|
121
|
+
method ::= "static"? name functionBody ;
|
|
119
122
|
|
|
120
|
-
|
|
123
|
+
field ::= "static"? name "=" expression... ";" ;
|
|
121
124
|
|
|
122
125
|
|
|
123
126
|
|
|
124
|
-
|
|
127
|
+
var ::= variable ( "=" expression )? | destructure "=" expression ;
|
|
125
128
|
|
|
126
|
-
|
|
129
|
+
let ::= variable ( "=" expression )? | destructure "=" expression ;
|
|
127
130
|
|
|
128
|
-
|
|
131
|
+
const ::= ( variable | destructure ) "=" expression ;
|
|
129
132
|
|
|
130
133
|
|
|
131
134
|
|
|
132
|
-
|
|
135
|
+
try ::= "try" "{" statement+ "}" ;
|
|
133
136
|
|
|
134
|
-
|
|
137
|
+
catch ::= "catch" "(" [identifier] ")" "{" statement+ "}" ;
|
|
135
138
|
|
|
136
|
-
|
|
139
|
+
finally ::= "finally" "{" statement+ "}" ;
|
|
137
140
|
|
|
138
141
|
|
|
139
142
|
|
|
140
|
-
|
|
143
|
+
case ::= "case" expression ":" statement ( "break" ";" )? ;
|
|
141
144
|
|
|
142
|
-
|
|
145
|
+
defaultCase ::= "default" ":" statement ( "break" ";" )? ;
|
|
143
146
|
|
|
144
147
|
|
|
145
148
|
|
|
146
|
-
|
|
149
|
+
initialiser ::= expression | "var" var ( "," var )* | "let" let ( "," let )* ;
|
|
147
150
|
|
|
148
151
|
|
|
149
152
|
|
|
150
|
-
|
|
153
|
+
destructure ::= "[" variable ( "=" expression )? ( "," variable ( "=" expression )? )* "]"
|
|
151
154
|
|
|
152
|
-
|
|
155
|
+
| "{" variable ( "=" expression )? ( "," variable ( "=" expression )? )* "}"
|
|
153
156
|
|
|
154
|
-
|
|
157
|
+
;
|
|
155
158
|
|
|
156
159
|
|
|
157
160
|
|
|
158
|
-
|
|
161
|
+
expression ::= jsx
|
|
159
162
|
|
|
160
|
-
|
|
163
|
+
| json
|
|
161
164
|
|
|
162
|
-
|
|
165
|
+
| arrowFunction
|
|
163
166
|
|
|
164
|
-
|
|
167
|
+
| templateLiteral
|
|
165
168
|
|
|
166
|
-
|
|
169
|
+
| anonymousFunction
|
|
167
170
|
|
|
168
|
-
|
|
171
|
+
| "(" expression ")"
|
|
169
172
|
|
|
170
|
-
|
|
173
|
+
| "{" ( property ( "," property )* )? "}"
|
|
171
174
|
|
|
172
|
-
|
|
175
|
+
| "[" ( expression ( "," expression )* ","? )? "]"
|
|
173
176
|
|
|
174
|
-
|
|
177
|
+
| "typeof" ( expression | ( "(" expression ")") )
|
|
175
178
|
|
|
176
|
-
|
|
179
|
+
| "void" ( expression | ( "(" expression ")") )
|
|
177
180
|
|
|
178
|
-
|
|
181
|
+
| "new" name<NO_WHITESPACE>"(" arguments? ")"
|
|
179
182
|
|
|
180
|
-
|
|
183
|
+
| [operator]<NO_WHITESPACE>expression
|
|
181
184
|
|
|
182
|
-
|
|
185
|
+
| expression<NO_WHITESPACE>( ( "."<NO_WHITESPACE>name )
|
|
183
186
|
|
|
184
|
-
|
|
187
|
+
| ( "[" expressions "]" )
|
|
185
188
|
|
|
186
|
-
|
|
189
|
+
| ( "(" expressions? ")" )
|
|
187
190
|
|
|
188
|
-
|
|
191
|
+
| templateLiteral
|
|
189
192
|
|
|
190
|
-
|
|
193
|
+
| [operator]
|
|
191
194
|
|
|
192
|
-
|
|
195
|
+
)
|
|
193
196
|
|
|
194
|
-
|
|
197
|
+
| expression ( ( [operator] expression )
|
|
195
198
|
|
|
196
|
-
|
|
199
|
+
| ( "?" expression ":" expression )
|
|
197
200
|
|
|
198
|
-
|
|
201
|
+
| ( "instanceof" expression )
|
|
199
202
|
|
|
200
|
-
|
|
203
|
+
| ( "in" expression )
|
|
201
204
|
|
|
202
|
-
|
|
205
|
+
)
|
|
203
206
|
|
|
204
|
-
|
|
207
|
+
| [number]
|
|
205
208
|
|
|
206
|
-
|
|
209
|
+
| variable
|
|
207
210
|
|
|
208
|
-
|
|
211
|
+
| primitive
|
|
209
212
|
|
|
210
|
-
|
|
213
|
+
| importMeta
|
|
211
214
|
|
|
212
|
-
|
|
215
|
+
| [string-literal]
|
|
213
216
|
|
|
214
|
-
|
|
217
|
+
| "super" | "this" | "true" | "false" | "null" | "undefined"
|
|
215
218
|
|
|
216
|
-
|
|
219
|
+
;
|
|
217
220
|
|
|
218
221
|
|
|
219
222
|
|
|
220
|
-
|
|
223
|
+
jsx ::= jsxCompleteTag | jsxStartTag ( jsx | ( "{" expression? "}" ) | string )* jsxEndTag ;
|
|
221
224
|
|
|
222
|
-
|
|
225
|
+
jsxCompleteTag ::= "<"<NO_WHITESPACE>name jsxAttribute* "/>" ;
|
|
223
226
|
|
|
224
|
-
|
|
227
|
+
jsxStartTag ::= "<"<NO_WHITESPACE>name jsxAttribute* ">" ;
|
|
225
228
|
|
|
226
|
-
|
|
229
|
+
jsxEndTag ::= "</"<NO_WHITESPACE>name ">" ;
|
|
227
230
|
|
|
228
|
-
|
|
231
|
+
jsxAttribute ::= name ( <NO_WHITESPACE>"=" ( ( <NO_WHITESPACE>[string-literal] ) | ( <NO_WHITESPACE>"{" expression "}" ) ) )? ;
|
|
229
232
|
|
|
230
233
|
|
|
231
234
|
|
|
232
|
-
|
|
235
|
+
json ::= jsonArray | jsonObject ;
|
|
233
236
|
|
|
234
|
-
|
|
237
|
+
jsonArray ::= "[" ( jsonElement ( "," jsonElement )* )? "]" ;
|
|
235
238
|
|
|
236
|
-
|
|
239
|
+
jsonObject ::= "{" ( [string-literal] ":" jsonElement ( "," [string-literal] ":" jsonElement )* )? "}" ;
|
|
237
240
|
|
|
238
|
-
|
|
241
|
+
jsonElement ::= json | [string-literal] | [number] | "true" | "false" | "null" ;
|
|
239
242
|
|
|
240
243
|
|
|
241
244
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
complexArrowFunction ::= "(" arguments? ")" "=>" arrowFunctionBody ;
|
|
245
|
-
|
|
246
|
-
simpleArrowFunction ::= argument "=>" arrowFunctionBody ;
|
|
247
|
-
|
|
248
|
-
arrowFunctionBody ::= expression | ( "{" statement* "}" ) ;
|
|
245
|
+
arrowFunction ::= "(" arguments? ")" "=>" ( expression | ( "{" statement* "}" ) ) ;
|
|
246
|
+
|
|
249
247
|
|
|
250
248
|
|
|
251
|
-
|
|
249
|
+
templateLiteral ::= "\`" ( ( "\${" expression? "}" ) | string )* "\`" ;
|
|
252
250
|
|
|
253
251
|
|
|
254
252
|
|
|
255
|
-
|
|
253
|
+
string ::= ( [number] | [special] | [operator]| [keyword] | [identifier] | [string-literal]| [broken-string-literal] | [unassigned] )+ ;
|
|
256
254
|
|
|
257
|
-
|
|
255
|
+
property ::= ( ( ( name | [string-literal] ) ":" expression ) | variable ) ;
|
|
258
256
|
|
|
259
|
-
|
|
257
|
+
importMeta ::= "import"<NO_WHITESPACE>"."<NO_WHITESPACE>"meta" ;
|
|
260
258
|
|
|
261
259
|
|
|
262
260
|
|
|
263
|
-
|
|
261
|
+
expressions ::= expression ( "," expression )* ;
|
|
264
262
|
|
|
265
|
-
|
|
263
|
+
arguments ::= spreadArgument | ( argument ( "," argument )* ( "," spreadArgument )? ) ;
|
|
266
264
|
|
|
267
|
-
|
|
265
|
+
fields ::= name ( ":" name )? ( "," name ( ":" name )? )* ;
|
|
268
266
|
|
|
269
|
-
|
|
267
|
+
names ::= name ( "as" name )? ( "," name ( "as" name )? )* ;
|
|
270
268
|
|
|
271
269
|
|
|
272
270
|
|
|
273
|
-
|
|
271
|
+
spreadArgument ::= "..."<NO_WHITESPACE>variable ;
|
|
274
272
|
|
|
275
|
-
|
|
273
|
+
argument ::= variable ( "=" expression )? | expression ;
|
|
276
274
|
|
|
277
|
-
|
|
275
|
+
variable ::= [identifier] ;
|
|
278
276
|
|
|
279
|
-
|
|
277
|
+
label ::= [identifier] ;
|
|
280
278
|
|
|
281
|
-
|
|
279
|
+
name ::= [identifier] ;
|
|
282
280
|
|
|
283
281
|
|
|
284
282
|
|
|
285
|
-
|
|
283
|
+
error ::= . ;
|
|
286
284
|
|
|
287
|
-
|
|
285
|
+
`,
|
|
286
|
+
rules = rulesFromBNF(bnf);
|
|
288
287
|
|
|
289
|
-
export default class JavaScriptParser extends
|
|
288
|
+
export default class JavaScriptParser extends CommonParser {
|
|
290
289
|
static bnf = bnf;
|
|
291
290
|
|
|
292
|
-
static fromNothing() { return
|
|
293
|
-
|
|
294
|
-
static fromBNF(bnf) { return YappParser.fromBNF(JavaScriptParser, bnf); }
|
|
291
|
+
static fromNothing() { return parserFromRules(JavaScriptParser, rules); }
|
|
295
292
|
|
|
296
|
-
static fromRules(rules) { return
|
|
293
|
+
static fromRules(rules) { return CommonParser.fromRules(JavaScriptParser, rules); }
|
|
297
294
|
}
|