@formulavize/lezer-fiz 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 anthologen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,4 @@
1
+ # lezer-fiz
2
+ This is the fiz grammar for the [lezer](https://lezer.codemirror.net) parser system.
3
+
4
+ **fiz** is a functionally inspired language for describing workflows in [formulavize](https://github.com/formulavize/formulavize). It borrows many language constructs from [javascript](https://github.com/lezer-parser/javascript) and [CSS](https://github.com/lezer-parser/css).
package/dist/index.cjs ADDED
@@ -0,0 +1,107 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var lr = require('@lezer/lr');
6
+ var highlight = require('@lezer/highlight');
7
+
8
+ // This file was generated by lezer-generator. You probably shouldn't edit it.
9
+ const Unit = 1,
10
+ cssIdentifier = 33,
11
+ insertSemi = 34,
12
+ spaces = 36,
13
+ newline = 37,
14
+ LineComment = 2,
15
+ BlockComment = 3;
16
+
17
+ const space = [9, 10, 11, 12, 13, 32, 133, 160,
18
+ 5760, 8192, 8193, 8194, 8195, 8196, 8197, 8198, 8199, 8200,
19
+ 8201, 8202, 8232, 8233, 8239, 8287, 12288];
20
+
21
+ const percent = 37, dash = 45, underscore = 95, braceR = 125;
22
+
23
+ function isAlpha(ch) { return ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122 || ch >= 161 }
24
+
25
+ function isDigit(ch) { return ch >= 48 && ch <= 57 }
26
+
27
+ const trackNewline = new lr.ContextTracker({
28
+ start: false,
29
+ shift(context, term) {
30
+ return term == LineComment || term == BlockComment || term == spaces ? context : term == newline
31
+ },
32
+ strict: false
33
+ });
34
+
35
+ const insertSemicolon = new lr.ExternalTokenizer((input, stack) => {
36
+ let {next} = input;
37
+ if ((next == braceR || next == -1 || stack.context) && stack.canShift(insertSemi))
38
+ input.acceptToken(insertSemi);
39
+ }, {contextual: true, fallback: true});
40
+
41
+ const unitToken = new lr.ExternalTokenizer(input => {
42
+ if (!space.includes(input.peek(-1))) {
43
+ let {next} = input;
44
+ if (next == percent) { input.advance(); input.acceptToken(Unit); }
45
+ if (isAlpha(next)) {
46
+ do { input.advance(); } while (isAlpha(input.next))
47
+ input.acceptToken(Unit);
48
+ }
49
+ }
50
+ });
51
+
52
+ const cssIdentifierToken = new lr.ExternalTokenizer((input) => {
53
+ for (let inside = false, dashes = 0, i = 0;; i++) {
54
+ let {next} = input;
55
+ if (isAlpha(next) || next == dash || next == underscore || (inside && isDigit(next))) {
56
+ if (!inside && (next != dash || i > 0)) inside = true;
57
+ if (dashes === i && next == dash) dashes++;
58
+ input.advance();
59
+ } else {
60
+ if (inside)
61
+ input.acceptToken(cssIdentifier);
62
+ break
63
+ }
64
+ }
65
+ });
66
+
67
+ const fizHighlighting = highlight.styleTags({
68
+ Variable: highlight.tags.variableName,
69
+ Call: highlight.tags.function(highlight.tags.variableName),
70
+ LineComment: highlight.tags.lineComment,
71
+ BlockComment: highlight.tags.blockComment,
72
+ PropertyName: highlight.tags.propertyName,
73
+ NumberLiteral: highlight.tags.number,
74
+ StringLiteral: highlight.tags.string,
75
+ ColorLiteral: highlight.tags.color,
76
+ Unit: highlight.tags.unit,
77
+ StyleTag: highlight.tags.tagName,
78
+ "( )": highlight.tags.paren,
79
+ "{ }": highlight.tags.brace,
80
+ ":": highlight.tags.punctuation,
81
+ ", ;": highlight.tags.separator,
82
+ });
83
+
84
+ // This file was generated by lezer-generator. You probably shouldn't edit it.
85
+ const parser = lr.LRParser.deserialize({
86
+ version: 14,
87
+ states: "(jQ`QSOOOhQdO'#CfO!PQSO'#CpO!UQSO'#CsO!aQSO'#CrO!iQSO'#CvO!nQdO'#DSOOQO'#Cw'#CwQ`QSOOO!vQSO'#CeO#OQdO,58{OOQQ,59[,59[O#aQUO'#CiOOQO,59_,59_O#lQSO,59^O#qQSO'#C{O#vQSO,59aOOQ`,59b,59bOOQQ'#DX'#DXOOQO,59n,59nOOQO-E6u-E6uOOQO'#DT'#DTOOQ`,59P,59PO$OQSO,59POOQ`1G.g1G.gOOQO'#Ck'#CkO$WQSO'#CjOOQQ'#Cy'#CyO$]QUO,59TOOQ`,59T,59TOOQ`1G.x1G.xOOQ`1G.{1G.{OOQO'#Cf'#CfOOQO,59g,59gOOQO-E6y-E6yO$hQSO1G.{O#lQSO'#CxO$mQSO1G.kOOQ`1G.k1G.kO$uQWO,59UOOQQ-E6w-E6wOOQ`1G.o1G.oO%QQSO'#CaOOQ`7+$g7+$gOOQO,59d,59dOOQO-E6v-E6vOOQ`7+$V7+$VO%VQiO'#CnOOQ`'#DV'#DVO%nQhO1G.pOOQ`,59Y,59YOOQ`'#Cz'#CzO$uQWO'#CzO%nQhO7+$[OOQQ7+$[7+$[OOQ`,59f,59fOOQ`-E6x-E6xOOQQ<<Gv<<Gv",
88
+ stateData: "&S~OtOSuOSQOSROS~OUPOeQO~OWXO[YXhYXxYXVYXrYX|YX~OUZO~O[[OhgXxgX~Oh^Ox_O~O[[O~OrbO|bO~OUPOVfO~O[[OrTa|TaVTaxTa~OZmOeQOqiO~OUPO~OUpO~OhsOx_O~OVvOxtO~O`wO~OZyOeQOqiO~OUzO~OV!OOxtO~Oa!QOc!QOz!PO~OWXO~OP!SOabXcbXrbXxbXzbX|bX~Oa!QOc!QOrbOx!UOz!PO|bO~O",
89
+ goto: "$v|PPPPP}PPP!]!aPP!m!v!zPP#OP#UP#^#bP#^#^#i#o#u#{$RPPPPPP$X$]P$cP$mSUOWSeXtQo^R{sTYPzUROW_SeXtRn^Q]RQaTRhYTk[lTj[lX!Qw!R!U!VSTOWTk[lTUOWSSOWRq_QWORdWQugR}uQl[RxlQ!V!RR!Y!VQ`SRr`TVOWQgXR|tQ!RwS!T!R!VR!X!UQcUQ!W!RR!Z!V",
90
+ nodeNames: "⚠ Unit LineComment BlockComment Recipe Call Identifier ) ( ArgList Variable } { StyleArgList StyleDeclaration PropertyName : ColorLiteral NumberLiteral StringLiteral StyleTag # Alias LhsVariable Eq Assignment StyleTagDeclaration",
91
+ maxTerm: 44,
92
+ context: trackNewline,
93
+ nodeProps: [
94
+ ["group", -2,5,10,"Value",-3,17,18,19,"StyleValue"],
95
+ ["openedBy", 7,"(",11,"{"],
96
+ ["closedBy", 8,")",12,"}"]
97
+ ],
98
+ propSources: [fizHighlighting],
99
+ skippedNodes: [0,2,3],
100
+ repeatNodeCount: 5,
101
+ tokenData: ".k~RzXY#uYZ$jZ[#u]^$jpq#urs$ost%atu'rwx(Zxy(vyz({{|)Q|}*l}!O)Q!O!P)Z!P!Q*q!Q![*Z![!]+z!]!^,P!_!`,U!c!}'r#R#S'r#T#o'r#o#p,Z#q#r,`$f$g#u$g#BY'r#BY#BZ,e#BZ$IS'r$IS$I_,e$I_$I|'r$I|$I}.Q$I}$JO.Q$JO$JT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106
+
107
+ exports.parser = parser;
@@ -0,0 +1,3 @@
1
+ import {Parser} from "lezer"
2
+
3
+ export const parser: Parser
@@ -0,0 +1,103 @@
1
+ import { ContextTracker, ExternalTokenizer, LRParser } from '@lezer/lr';
2
+ import { styleTags, tags } from '@lezer/highlight';
3
+
4
+ // This file was generated by lezer-generator. You probably shouldn't edit it.
5
+ const Unit = 1,
6
+ cssIdentifier = 33,
7
+ insertSemi = 34,
8
+ spaces = 36,
9
+ newline = 37,
10
+ LineComment = 2,
11
+ BlockComment = 3;
12
+
13
+ const space = [9, 10, 11, 12, 13, 32, 133, 160,
14
+ 5760, 8192, 8193, 8194, 8195, 8196, 8197, 8198, 8199, 8200,
15
+ 8201, 8202, 8232, 8233, 8239, 8287, 12288];
16
+
17
+ const percent = 37, dash = 45, underscore = 95, braceR = 125;
18
+
19
+ function isAlpha(ch) { return ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122 || ch >= 161 }
20
+
21
+ function isDigit(ch) { return ch >= 48 && ch <= 57 }
22
+
23
+ const trackNewline = new ContextTracker({
24
+ start: false,
25
+ shift(context, term) {
26
+ return term == LineComment || term == BlockComment || term == spaces ? context : term == newline
27
+ },
28
+ strict: false
29
+ });
30
+
31
+ const insertSemicolon = new ExternalTokenizer((input, stack) => {
32
+ let {next} = input;
33
+ if ((next == braceR || next == -1 || stack.context) && stack.canShift(insertSemi))
34
+ input.acceptToken(insertSemi);
35
+ }, {contextual: true, fallback: true});
36
+
37
+ const unitToken = new ExternalTokenizer(input => {
38
+ if (!space.includes(input.peek(-1))) {
39
+ let {next} = input;
40
+ if (next == percent) { input.advance(); input.acceptToken(Unit); }
41
+ if (isAlpha(next)) {
42
+ do { input.advance(); } while (isAlpha(input.next))
43
+ input.acceptToken(Unit);
44
+ }
45
+ }
46
+ });
47
+
48
+ const cssIdentifierToken = new ExternalTokenizer((input) => {
49
+ for (let inside = false, dashes = 0, i = 0;; i++) {
50
+ let {next} = input;
51
+ if (isAlpha(next) || next == dash || next == underscore || (inside && isDigit(next))) {
52
+ if (!inside && (next != dash || i > 0)) inside = true;
53
+ if (dashes === i && next == dash) dashes++;
54
+ input.advance();
55
+ } else {
56
+ if (inside)
57
+ input.acceptToken(cssIdentifier);
58
+ break
59
+ }
60
+ }
61
+ });
62
+
63
+ const fizHighlighting = styleTags({
64
+ Variable: tags.variableName,
65
+ Call: tags.function(tags.variableName),
66
+ LineComment: tags.lineComment,
67
+ BlockComment: tags.blockComment,
68
+ PropertyName: tags.propertyName,
69
+ NumberLiteral: tags.number,
70
+ StringLiteral: tags.string,
71
+ ColorLiteral: tags.color,
72
+ Unit: tags.unit,
73
+ StyleTag: tags.tagName,
74
+ "( )": tags.paren,
75
+ "{ }": tags.brace,
76
+ ":": tags.punctuation,
77
+ ", ;": tags.separator,
78
+ });
79
+
80
+ // This file was generated by lezer-generator. You probably shouldn't edit it.
81
+ const parser = LRParser.deserialize({
82
+ version: 14,
83
+ states: "(jQ`QSOOOhQdO'#CfO!PQSO'#CpO!UQSO'#CsO!aQSO'#CrO!iQSO'#CvO!nQdO'#DSOOQO'#Cw'#CwQ`QSOOO!vQSO'#CeO#OQdO,58{OOQQ,59[,59[O#aQUO'#CiOOQO,59_,59_O#lQSO,59^O#qQSO'#C{O#vQSO,59aOOQ`,59b,59bOOQQ'#DX'#DXOOQO,59n,59nOOQO-E6u-E6uOOQO'#DT'#DTOOQ`,59P,59PO$OQSO,59POOQ`1G.g1G.gOOQO'#Ck'#CkO$WQSO'#CjOOQQ'#Cy'#CyO$]QUO,59TOOQ`,59T,59TOOQ`1G.x1G.xOOQ`1G.{1G.{OOQO'#Cf'#CfOOQO,59g,59gOOQO-E6y-E6yO$hQSO1G.{O#lQSO'#CxO$mQSO1G.kOOQ`1G.k1G.kO$uQWO,59UOOQQ-E6w-E6wOOQ`1G.o1G.oO%QQSO'#CaOOQ`7+$g7+$gOOQO,59d,59dOOQO-E6v-E6vOOQ`7+$V7+$VO%VQiO'#CnOOQ`'#DV'#DVO%nQhO1G.pOOQ`,59Y,59YOOQ`'#Cz'#CzO$uQWO'#CzO%nQhO7+$[OOQQ7+$[7+$[OOQ`,59f,59fOOQ`-E6x-E6xOOQQ<<Gv<<Gv",
84
+ stateData: "&S~OtOSuOSQOSROS~OUPOeQO~OWXO[YXhYXxYXVYXrYX|YX~OUZO~O[[OhgXxgX~Oh^Ox_O~O[[O~OrbO|bO~OUPOVfO~O[[OrTa|TaVTaxTa~OZmOeQOqiO~OUPO~OUpO~OhsOx_O~OVvOxtO~O`wO~OZyOeQOqiO~OUzO~OV!OOxtO~Oa!QOc!QOz!PO~OWXO~OP!SOabXcbXrbXxbXzbX|bX~Oa!QOc!QOrbOx!UOz!PO|bO~O",
85
+ goto: "$v|PPPPP}PPP!]!aPP!m!v!zPP#OP#UP#^#bP#^#^#i#o#u#{$RPPPPPP$X$]P$cP$mSUOWSeXtQo^R{sTYPzUROW_SeXtRn^Q]RQaTRhYTk[lTj[lX!Qw!R!U!VSTOWTk[lTUOWSSOWRq_QWORdWQugR}uQl[RxlQ!V!RR!Y!VQ`SRr`TVOWQgXR|tQ!RwS!T!R!VR!X!UQcUQ!W!RR!Z!V",
86
+ nodeNames: "⚠ Unit LineComment BlockComment Recipe Call Identifier ) ( ArgList Variable } { StyleArgList StyleDeclaration PropertyName : ColorLiteral NumberLiteral StringLiteral StyleTag # Alias LhsVariable Eq Assignment StyleTagDeclaration",
87
+ maxTerm: 44,
88
+ context: trackNewline,
89
+ nodeProps: [
90
+ ["group", -2,5,10,"Value",-3,17,18,19,"StyleValue"],
91
+ ["openedBy", 7,"(",11,"{"],
92
+ ["closedBy", 8,")",12,"}"]
93
+ ],
94
+ propSources: [fizHighlighting],
95
+ skippedNodes: [0,2,3],
96
+ repeatNodeCount: 5,
97
+ tokenData: ".k~RzXY#uYZ$jZ[#u]^$jpq#urs$ost%atu'rwx(Zxy(vyz({{|)Q|}*l}!O)Q!O!P)Z!P!Q*q!Q![*Z![!]+z!]!^,P!_!`,U!c!}'r#R#S'r#T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~'r",
98
+ tokenizers: [unitToken, cssIdentifierToken, 0, 1, insertSemicolon],
99
+ topRules: {"Recipe":[0,4]},
100
+ tokenPrec: 0
101
+ });
102
+
103
+ export { parser };
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@formulavize/lezer-fiz",
3
+ "version": "0.1.0",
4
+ "description": "fiz grammar for lezer",
5
+ "main": "dist/index.cjs",
6
+ "type": "module",
7
+ "exports": {
8
+ "import": "./dist/index.es.js",
9
+ "require": "./dist/index.cjs"
10
+ },
11
+ "module": "dist/index.es.js",
12
+ "types": "dist/index.d.ts",
13
+ "dependencies": {
14
+ "@lezer/highlight": "^1.0.0",
15
+ "@lezer/lr": "^1.0.0"
16
+ },
17
+ "devDependencies": {
18
+ "@lezer/generator": "^1.0.0",
19
+ "@rollup/plugin-node-resolve": "^13.3.0",
20
+ "mocha": "^10.0.0",
21
+ "rollup": "^2.75.6"
22
+ },
23
+ "scripts": {
24
+ "build": "lezer-generator src/fiz.grammar -o src/parser && rollup -c",
25
+ "build-debug": "lezer-generator src/fiz.grammar --names -o src/parser && rollup -c",
26
+ "prepare": "npm run build",
27
+ "test": "npm run build && mocha test/test-fiz.js"
28
+ },
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/formulavize/lezer-fiz.git"
32
+ },
33
+ "author": "anthologen",
34
+ "license": "MIT",
35
+ "homepage": "https://github.com/formulavize/lezer-fiz#readme"
36
+ }
@@ -0,0 +1,18 @@
1
+ import { nodeResolve } from "@rollup/plugin-node-resolve"
2
+
3
+ export default {
4
+ input: "./src/parser.js",
5
+ output: [{
6
+ format: "cjs",
7
+ file: "./dist/index.cjs"
8
+ }, {
9
+ format: "es",
10
+ file: "./dist/index.es.js"
11
+ }],
12
+ external(id) {
13
+ return !/^[\.\/]/.test(id)
14
+ },
15
+ plugins: [
16
+ nodeResolve()
17
+ ]
18
+ }
@@ -0,0 +1,89 @@
1
+ @top Recipe { statement* }
2
+
3
+ statement { ( Call | Alias | Assignment | StyleTagDeclaration ) semi }
4
+
5
+ Call { Identifier ArgList StyleArgList? }
6
+
7
+ ArgList { "(" ( value ("," value)* )? ")" }
8
+
9
+ value[@isGroup=Value] { Variable | Call }
10
+
11
+ Variable { Identifier }
12
+
13
+ Alias { LhsVariable "=" Variable }
14
+
15
+ Assignment { LhsVariable ("," LhsVariable)* "=" Call }
16
+
17
+ semi { ";" | insertSemi }
18
+
19
+ LhsVariable { Variable StyleArgList? }
20
+
21
+ NumberLiteral { numberLiteralInner Unit? }
22
+
23
+ // StyleValueName { cssIdentifier }
24
+ /* Tombstone: Adding StyleValueName to styleValue breaks NumberLiteral
25
+ unless we decide to make ';' mandatory in StyleDeclaration */
26
+
27
+ PropertyName { cssIdentifier }
28
+
29
+ styleValue[@isGroup=StyleValue] { ColorLiteral | NumberLiteral | StringLiteral }
30
+
31
+ StyleDeclaration { PropertyName ":" styleValue (","? styleValue)* semi }
32
+
33
+ StyleTagDeclaration { StyleTag StyleArgList }
34
+
35
+ StyleTag { "#" Identifier }
36
+
37
+ StyleArgList { "{" (StyleDeclaration | StyleTag)* "}" }
38
+
39
+ @skip { spaces | newline | LineComment | BlockComment }
40
+
41
+ @context trackNewline from "./tokens.js"
42
+
43
+ @external tokens unitToken from "./tokens" { Unit }
44
+
45
+ @external tokens cssIdentifierToken from "./tokens" { cssIdentifier }
46
+
47
+ @tokens {
48
+ spaces[@export] { $[\u0009 \u000b\u00a0\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]+ }
49
+ newline[@export] { $[\r\n\u2028\u2029] }
50
+
51
+ LineComment { "//" ![\n]* }
52
+
53
+ BlockComment { "/*" blockCommentRest }
54
+
55
+ blockCommentRest { ![*] blockCommentRest | "*" blockCommentAfterStar }
56
+
57
+ blockCommentAfterStar { "/" | "*" blockCommentAfterStar | ![/*] blockCommentRest }
58
+
59
+ identifierChar { std.asciiLetter | $[_$\u{a1}-\u{10ffff}] }
60
+
61
+ word { identifierChar (identifierChar | std.digit)* }
62
+
63
+ Identifier { word }
64
+
65
+ hexDigit { std.digit | $[a-fA-F] }
66
+
67
+ ColorLiteral { "#" hexDigit hexDigit hexDigit (hexDigit (hexDigit hexDigit (hexDigit hexDigit)?)?)? }
68
+
69
+ numberLiteralInner { ("+" | "-")? (std.digit+ ("." std.digit*)? | "." std.digit+) (("e" | "E") ("+" | "-")? std.digit+)? }
70
+
71
+ StringLiteral { "\"" (!["\n\\] | "\\" _)* "\"" | "'" (!['\n\\] | "\\" _)* "'" }
72
+
73
+ "="[@name=Eq]
74
+
75
+ @precedence { spaces, newline, Identifier }
76
+
77
+ "#"
78
+
79
+ ":"
80
+
81
+ "(" ")" "{" "}"
82
+
83
+ }
84
+
85
+ @external tokens insertSemicolon from "./tokens" { insertSemi }
86
+
87
+ @external propSource fizHighlighting from "./highlight"
88
+
89
+ @detectDelim
@@ -0,0 +1,18 @@
1
+ import {styleTags, tags as t} from "@lezer/highlight"
2
+
3
+ export const fizHighlighting = styleTags({
4
+ Variable: t.variableName,
5
+ Call: t.function(t.variableName),
6
+ LineComment: t.lineComment,
7
+ BlockComment: t.blockComment,
8
+ PropertyName: t.propertyName,
9
+ NumberLiteral: t.number,
10
+ StringLiteral: t.string,
11
+ ColorLiteral: t.color,
12
+ Unit: t.unit,
13
+ StyleTag: t.tagName,
14
+ "( )": t.paren,
15
+ "{ }": t.brace,
16
+ ":": t.punctuation,
17
+ ", ;": t.separator,
18
+ })
package/src/parser.js ADDED
@@ -0,0 +1,26 @@
1
+ // This file was generated by lezer-generator. You probably shouldn't edit it.
2
+ import {LRParser} from "@lezer/lr"
3
+ import {unitToken, cssIdentifierToken, insertSemicolon} from "./tokens"
4
+ import {trackNewline} from "./tokens.js"
5
+ import {fizHighlighting} from "./highlight"
6
+ export const parser = LRParser.deserialize({
7
+ version: 14,
8
+ states: "(jQ`QSOOOhQdO'#CfO!PQSO'#CpO!UQSO'#CsO!aQSO'#CrO!iQSO'#CvO!nQdO'#DSOOQO'#Cw'#CwQ`QSOOO!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UQcUQ!W!RR!Z!V",
11
+ nodeNames: "⚠ Unit LineComment BlockComment Recipe Call Identifier ) ( ArgList Variable } { StyleArgList StyleDeclaration PropertyName : ColorLiteral NumberLiteral StringLiteral StyleTag # Alias LhsVariable Eq Assignment StyleTagDeclaration",
12
+ maxTerm: 44,
13
+ context: trackNewline,
14
+ nodeProps: [
15
+ ["group", -2,5,10,"Value",-3,17,18,19,"StyleValue"],
16
+ ["openedBy", 7,"(",11,"{"],
17
+ ["closedBy", 8,")",12,"}"]
18
+ ],
19
+ propSources: [fizHighlighting],
20
+ skippedNodes: [0,2,3],
21
+ repeatNodeCount: 5,
22
+ tokenData: ".k~RzXY#uYZ$jZ[#u]^$jpq#urs$ost%atu'rwx(Zxy(vyz({{|)Q|}*l}!O)Q!O!P)Z!P!Q*q!Q![*Z![!]+z!]!^,P!_!`,U!c!}'r#R#S'r#T#o'r#o#p,Z#q#r,`$f$g#u$g#BY'r#BY#BZ,e#BZ$IS'r$IS$I_,e$I_$I|'r$I|$I}.Q$I}$JO.Q$JO$JT'r$JT$JU,e$JU$KV'r$KV$KW,e$KW&FU'r&FU&FV,e&FV?HT'r?HT?HU,e?HU~'r~#zYt~XY#uZ[#upq#u$f$g#u#BY#BZ#u$IS$I_#u$JT$JU#u$KV$KW#u&FU&FV#u?HT?HU#u~$oOu~~$rUOY$oZr$ors%Us#O$o#O#P%Z#P~$o~%ZOc~~%^PO~$oR%fReP!Q![%o!c!i%o#T#Z%oQ%rR!Q![%{!c!i%{#T#Z%{Q&OR!Q![&X!c!i&X#T#Z&XQ&^RaQ!Q![&g!c!i&g#T#Z&gQ&lRaQ!Q![&u!c!i&u#T#Z&uQ&xR!Q!['R!c!i'R#T#Z'RQ'WRaQ!Q!['a!c!i'a#T#Z'aQ'dR!Q!['m!c!i'm#T#Z'mQ'rOaQ~'wUU~tu'r!Q!['r!c!}'r#R#S'r#T#o'r$g~'r~(^UOY(ZZw(Zwx%Ux#O(Z#O#P(p#P~(Z~(sPO~(Z~({OW~~)QOV~~)TQ!O!P)Z!Q![*Z~)^P!Q![)a~)fRz~!Q![)a!g!h)o#X#Y)o~)rR{|){}!O){!Q![*R~*OP!Q![*R~*WPz~!Q![*R~*`Sz~!O!P)a!Q![*Z!g!h)o#X#Y)o~*qOx~~*tQz{*z!P!Q+o~*}ROz*zz{+W{~*z~+ZTOz*zz{+W{!P*z!P!Q+j!Q~*z~+oOR~~+tQQ~OY+oZ~+o~,PO`~~,UO|~~,ZOh~~,`O[~~,eOZ~~,lft~U~XY#uZ[#upq#utu'r!Q!['r!c!}'r#R#S'r#T#o'r$f$g#u$g#BY'r#BY#BZ,e#BZ$IS'r$IS$I_,e$I_$JT'r$JT$JU,e$JU$KV'r$KV$KW,e$KW&FU'r&FU&FV,e&FV?HT'r?HT?HU,e?HU~'r~.XUu~U~tu'r!Q!['r!c!}'r#R#S'r#T#o'r$g~'r",
23
+ tokenizers: [unitToken, cssIdentifierToken, 0, 1, insertSemicolon],
24
+ topRules: {"Recipe":[0,4]},
25
+ tokenPrec: 0
26
+ })
@@ -0,0 +1,25 @@
1
+ // This file was generated by lezer-generator. You probably shouldn't edit it.
2
+ export const
3
+ Unit = 1,
4
+ cssIdentifier = 33,
5
+ insertSemi = 34,
6
+ spaces = 36,
7
+ newline = 37,
8
+ LineComment = 2,
9
+ BlockComment = 3,
10
+ Recipe = 4,
11
+ Call = 5,
12
+ Identifier = 6,
13
+ ArgList = 9,
14
+ Variable = 10,
15
+ StyleArgList = 13,
16
+ StyleDeclaration = 14,
17
+ PropertyName = 15,
18
+ ColorLiteral = 17,
19
+ NumberLiteral = 18,
20
+ StringLiteral = 19,
21
+ StyleTag = 20,
22
+ Alias = 22,
23
+ LhsVariable = 23,
24
+ Assignment = 25,
25
+ StyleTagDeclaration = 26
package/src/tokens.js ADDED
@@ -0,0 +1,53 @@
1
+ import { ExternalTokenizer, ContextTracker } from "@lezer/lr"
2
+ import { insertSemi, spaces, newline,
3
+ LineComment, BlockComment, Unit, cssIdentifier } from "./parser.terms.js"
4
+
5
+ const space = [9, 10, 11, 12, 13, 32, 133, 160,
6
+ 5760, 8192, 8193, 8194, 8195, 8196, 8197, 8198, 8199, 8200,
7
+ 8201, 8202, 8232, 8233, 8239, 8287, 12288]
8
+
9
+ const percent = 37, dash = 45, underscore = 95, braceR = 125
10
+
11
+ function isAlpha(ch) { return ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122 || ch >= 161 }
12
+
13
+ function isDigit(ch) { return ch >= 48 && ch <= 57 }
14
+
15
+ export const trackNewline = new ContextTracker({
16
+ start: false,
17
+ shift(context, term) {
18
+ return term == LineComment || term == BlockComment || term == spaces ? context : term == newline
19
+ },
20
+ strict: false
21
+ })
22
+
23
+ export const insertSemicolon = new ExternalTokenizer((input, stack) => {
24
+ let {next} = input
25
+ if ((next == braceR || next == -1 || stack.context) && stack.canShift(insertSemi))
26
+ input.acceptToken(insertSemi)
27
+ }, {contextual: true, fallback: true})
28
+
29
+ export const unitToken = new ExternalTokenizer(input => {
30
+ if (!space.includes(input.peek(-1))) {
31
+ let {next} = input
32
+ if (next == percent) { input.advance(); input.acceptToken(Unit) }
33
+ if (isAlpha(next)) {
34
+ do { input.advance() } while (isAlpha(input.next))
35
+ input.acceptToken(Unit)
36
+ }
37
+ }
38
+ })
39
+
40
+ export const cssIdentifierToken = new ExternalTokenizer((input) => {
41
+ for (let inside = false, dashes = 0, i = 0;; i++) {
42
+ let {next} = input
43
+ if (isAlpha(next) || next == dash || next == underscore || (inside && isDigit(next))) {
44
+ if (!inside && (next != dash || i > 0)) inside = true
45
+ if (dashes === i && next == dash) dashes++
46
+ input.advance()
47
+ } else {
48
+ if (inside)
49
+ input.acceptToken(cssIdentifier)
50
+ break
51
+ }
52
+ }
53
+ })
@@ -0,0 +1,43 @@
1
+ # Single Variable Alias
2
+
3
+ x = y
4
+
5
+ ==>
6
+
7
+ Recipe(
8
+ Alias(
9
+ LhsVariable(Variable(Identifier)),
10
+ Eq,
11
+ Variable(Identifier)
12
+ )
13
+ )
14
+
15
+ # Single Variable Assignment
16
+
17
+ foo = f()
18
+
19
+ ==>
20
+
21
+ Recipe(
22
+ Assignment(
23
+ LhsVariable(Variable(Identifier)),
24
+ Eq,
25
+ Call(Identifier,ArgList)
26
+ )
27
+ )
28
+
29
+ # Unpacked Variable List Assignment
30
+
31
+ a, b, c = g()
32
+
33
+ ==>
34
+
35
+ Recipe(
36
+ Assignment(
37
+ LhsVariable(Variable(Identifier)),
38
+ LhsVariable(Variable(Identifier)),
39
+ LhsVariable(Variable(Identifier)),
40
+ Eq,
41
+ Call(Identifier,ArgList)
42
+ )
43
+ )
package/test/calls.txt ADDED
@@ -0,0 +1,126 @@
1
+ # No Parameters
2
+
3
+ func()
4
+
5
+ ==>
6
+
7
+ Recipe(
8
+ Call(Identifier,ArgList)
9
+ )
10
+
11
+ # One Variable
12
+
13
+ f( x )
14
+
15
+ ==>
16
+
17
+ Recipe(
18
+ Call(Identifier,ArgList(
19
+ Variable(Identifier)
20
+ ))
21
+ )
22
+
23
+ # Two Variables
24
+
25
+ f(x,y)
26
+
27
+ ==>
28
+
29
+ Recipe(
30
+ Call(Identifier,ArgList(
31
+ Variable(Identifier),
32
+ Variable(Identifier)
33
+ ))
34
+ )
35
+
36
+ # Three Variables
37
+
38
+ f(x, y, z)
39
+
40
+ ==>
41
+
42
+ Recipe(
43
+ Call(
44
+ Identifier,
45
+ ArgList(
46
+ Variable(Identifier),
47
+ Variable(Identifier),
48
+ Variable(Identifier)
49
+ )
50
+ )
51
+ )
52
+
53
+ # Nested Call
54
+
55
+ f(g())
56
+
57
+ ==>
58
+
59
+ Recipe(
60
+ Call(Identifier,ArgList(
61
+ Call(Identifier,ArgList)
62
+ ))
63
+ )
64
+
65
+ # Nested Nested Call
66
+
67
+ f( g( h() ) )
68
+
69
+ ==>
70
+
71
+ Recipe(
72
+ Call(Identifier,ArgList(
73
+ Call(Identifier,ArgList(
74
+ Call(Identifier,ArgList)
75
+ ))
76
+ ))
77
+ )
78
+
79
+ # Variable and Call
80
+
81
+ f ( x , g ( ) )
82
+
83
+ ==>
84
+
85
+ Recipe(
86
+ Call(Identifier,ArgList(
87
+ Variable(Identifier),
88
+ Call(Identifier,ArgList)
89
+ ))
90
+ )
91
+
92
+ # Call and Variable
93
+
94
+ f (
95
+ g ( ) ,
96
+ y
97
+ )
98
+
99
+ ==>
100
+
101
+ Recipe(
102
+ Call(Identifier,ArgList(
103
+ Call(Identifier,ArgList),
104
+ Variable(Identifier)
105
+ ))
106
+ )
107
+
108
+ # Nested Nested Call with Variable Parameters
109
+
110
+ f(
111
+ g(
112
+ h(x,y),
113
+ z
114
+ )
115
+ )
116
+
117
+ ==>
118
+
119
+ Recipe(
120
+ Call(Identifier,ArgList(
121
+ Call(Identifier,ArgList(
122
+ Call(Identifier,ArgList(Variable(Identifier), Variable(Identifier))),
123
+ Variable(Identifier)
124
+ ))
125
+ ))
126
+ )
@@ -0,0 +1,183 @@
1
+ # Empty
2
+
3
+
4
+
5
+ ==>
6
+
7
+ Recipe()
8
+
9
+ # Two Alias Statements
10
+
11
+ y = x
12
+ z = y
13
+
14
+ ==>
15
+
16
+ Recipe(
17
+ Alias(LhsVariable(Variable(Identifier)), Eq, Variable(Identifier)),
18
+ Alias(LhsVariable(Variable(Identifier)), Eq, Variable(Identifier))
19
+ )
20
+
21
+ # Mixed Statements
22
+
23
+ y = f(x)
24
+ x = y
25
+ g()
26
+
27
+ ==>
28
+
29
+ Recipe(
30
+ Assignment(
31
+ LhsVariable(Variable(Identifier)),
32
+ Eq,
33
+ Call(Identifier,ArgList(Variable(Identifier)))
34
+ )
35
+ Alias(LhsVariable(Variable(Identifier)), Eq, Variable(Identifier)),
36
+ Call(Identifier,ArgList)
37
+ )
38
+
39
+ # Line Comment
40
+
41
+ // Comment
42
+
43
+ ==>
44
+
45
+ Recipe(LineComment)
46
+
47
+ # Block Comments
48
+
49
+ /* OneLine */
50
+ /*
51
+ Newline
52
+ */
53
+ /*/*DoubleStart*/
54
+ /***
55
+ Stars
56
+ ***/
57
+
58
+ ==>
59
+
60
+ Recipe(BlockComment, BlockComment, BlockComment, BlockComment)
61
+
62
+ # Mixed Statements with Comments
63
+
64
+ // Comment
65
+ y = f(x)
66
+ /* Comment */
67
+ x = y
68
+ /*
69
+ Comment
70
+ */
71
+ g()
72
+
73
+ ==>
74
+
75
+ Recipe(
76
+ LineComment
77
+ Assignment(
78
+ LhsVariable(Variable(Identifier)),
79
+ Eq,
80
+ Call(Identifier,ArgList(Variable(Identifier)))
81
+ )
82
+ BlockComment
83
+ Alias(LhsVariable(Variable(Identifier)), Eq, Variable(Identifier)),
84
+ BlockComment
85
+ Call(Identifier,ArgList)
86
+ )
87
+
88
+ # Semicolons
89
+
90
+ y = f(x);
91
+ x = y;
92
+ g();
93
+
94
+ ==>
95
+
96
+ Recipe(
97
+ Assignment(
98
+ LhsVariable(Variable(Identifier)),
99
+ Eq,
100
+ Call(Identifier,ArgList(Variable(Identifier)))
101
+ )
102
+ Alias(LhsVariable(Variable(Identifier)), Eq, Variable(Identifier)),
103
+ Call(Identifier,ArgList)
104
+ )
105
+
106
+ # Semicolons Same Line
107
+
108
+ a=b();f();x=y;
109
+
110
+ ==>
111
+
112
+ Recipe(
113
+ Assignment(
114
+ LhsVariable(Variable(Identifier)),
115
+ Eq,
116
+ Call(Identifier,ArgList)
117
+ ),
118
+ Call(Identifier,ArgList),
119
+ Alias(LhsVariable(Variable(Identifier)), Eq, Variable(Identifier))
120
+ )
121
+
122
+ # Semicolon Same Line Divider
123
+
124
+ y = f(
125
+ x,
126
+ y,
127
+ z
128
+ ) ; a = b
129
+
130
+ ==>
131
+
132
+ Recipe(
133
+ Assignment(
134
+ LhsVariable(Variable(Identifier)),
135
+ Eq,
136
+ Call(Identifier,ArgList(
137
+ Variable(Identifier),
138
+ Variable(Identifier),
139
+ Variable(Identifier)
140
+ ))
141
+ ),
142
+ Alias(LhsVariable(Variable(Identifier)), Eq, Variable(Identifier))
143
+ )
144
+
145
+ # Diagram
146
+
147
+ x = f(i); y = g(j)
148
+ // | |
149
+ m = a(x); n = b(y)
150
+ // \ /
151
+ // \ /
152
+ // \ /
153
+ foo(m,n)
154
+
155
+ ==>
156
+
157
+ Recipe(
158
+ Assignment(
159
+ LhsVariable(Variable(Identifier)),
160
+ Eq,
161
+ Call(Identifier,ArgList(Variable(Identifier)))
162
+ ),
163
+ Assignment(
164
+ LhsVariable(Variable(Identifier)),
165
+ Eq,
166
+ Call(Identifier,ArgList(Variable(Identifier)))
167
+ ),
168
+ LineComment,
169
+ Assignment(
170
+ LhsVariable(Variable(Identifier)),
171
+ Eq,
172
+ Call(Identifier,ArgList(Variable(Identifier)))
173
+ ),
174
+ Assignment(
175
+ LhsVariable(Variable(Identifier)),
176
+ Eq,
177
+ Call(Identifier,ArgList(Variable(Identifier)))
178
+ ),
179
+ LineComment,
180
+ LineComment,
181
+ LineComment,
182
+ Call(Identifier,ArgList(Variable(Identifier), Variable(Identifier)))
183
+ )
@@ -0,0 +1,214 @@
1
+ # Empty Call StyleArgList
2
+
3
+ f(){}
4
+
5
+ ==>
6
+
7
+ Recipe(
8
+ Call(Identifier,ArgList,StyleArgList)
9
+ )
10
+
11
+ # Empty Variable StyleArgList
12
+
13
+ x{ } = f()
14
+
15
+ ==>
16
+
17
+ Recipe(
18
+ Assignment(
19
+ LhsVariable(Variable(Identifier), StyleArgList),
20
+ Eq,
21
+ Call(Identifier,ArgList)
22
+ )
23
+ )
24
+
25
+ # Styled and Unstyled Unpacked Assignment
26
+
27
+ x{}, y{} = z()
28
+ a{}, b = c()
29
+ i, j{} = k()
30
+
31
+ ==>
32
+
33
+ Recipe(
34
+ Assignment(
35
+ LhsVariable(Variable(Identifier), StyleArgList),
36
+ LhsVariable(Variable(Identifier), StyleArgList),
37
+ Eq,
38
+ Call(Identifier,ArgList)
39
+ )
40
+ Assignment(
41
+ LhsVariable(Variable(Identifier), StyleArgList),
42
+ LhsVariable(Variable(Identifier)),
43
+ Eq,
44
+ Call(Identifier,ArgList)
45
+ )
46
+ Assignment(
47
+ LhsVariable(Variable(Identifier)),
48
+ LhsVariable(Variable(Identifier), StyleArgList),
49
+ Eq,
50
+ Call(Identifier,ArgList)
51
+ )
52
+ )
53
+
54
+ # Style StringLiteral ending with }
55
+
56
+ f(){num: "abc"}
57
+
58
+ ==>
59
+
60
+ Recipe(
61
+ Call(
62
+ Identifier, ArgList,
63
+ StyleArgList(StyleDeclaration(PropertyName, StringLiteral))
64
+ )
65
+ )
66
+
67
+ # Style ColorLiteral ending with ;
68
+
69
+ f(){
70
+ color: #1234;
71
+ color: #7f7f7f;
72
+ }
73
+
74
+ ==>
75
+
76
+ Recipe(
77
+ Call(
78
+ Identifier, ArgList,
79
+ StyleArgList(
80
+ StyleDeclaration(PropertyName, ColorLiteral),
81
+ StyleDeclaration(PropertyName, ColorLiteral)
82
+ )
83
+ )
84
+ )
85
+
86
+ # Style NumberLiteral ending with newlines
87
+
88
+ f(){
89
+ a: 123
90
+ b: 1.2%
91
+ c: 3em
92
+ margin: 10E2px
93
+ margin: -456.7px
94
+ margin: -0.0px
95
+ }
96
+
97
+ ==>
98
+
99
+ Recipe(
100
+ Call(
101
+ Identifier, ArgList,
102
+ StyleArgList(
103
+ StyleDeclaration(PropertyName, NumberLiteral),
104
+ StyleDeclaration(PropertyName, NumberLiteral(Unit)),
105
+ StyleDeclaration(PropertyName, NumberLiteral(Unit)),
106
+ StyleDeclaration(PropertyName, NumberLiteral(Unit)),
107
+ StyleDeclaration(PropertyName, NumberLiteral(Unit)),
108
+ StyleDeclaration(PropertyName, NumberLiteral(Unit))
109
+ )
110
+ )
111
+ )
112
+
113
+
114
+ # StyleTag Used
115
+
116
+ f(){
117
+ #one #two
118
+ }
119
+
120
+ ==>
121
+
122
+ Recipe(
123
+ Call(
124
+ Identifier, ArgList,
125
+ StyleArgList(
126
+ StyleTag(Identifier),
127
+ StyleTag(Identifier)
128
+ )
129
+ )
130
+ )
131
+
132
+ # Empty StyleTag Declared
133
+
134
+ #empty{}
135
+
136
+ ==>
137
+
138
+ Recipe(
139
+ StyleTagDeclaration(
140
+ StyleTag(Identifier),
141
+ StyleArgList()
142
+ )
143
+ )
144
+
145
+ # Nested StyleTags
146
+
147
+ #mystyle{
148
+ #a
149
+ x: "y"
150
+ #c
151
+ }
152
+
153
+ ==>
154
+
155
+ Recipe(
156
+ StyleTagDeclaration(
157
+ StyleTag(Identifier),
158
+ StyleArgList(
159
+ StyleTag(Identifier),
160
+ StyleDeclaration(PropertyName, StringLiteral),
161
+ StyleTag(Identifier)
162
+ )
163
+ )
164
+ )
165
+
166
+ # StyleMap Value List
167
+
168
+ #mystyle{
169
+ a:1,2
170
+ b:3px 4 #123 "text"
171
+ }
172
+
173
+ ==>
174
+
175
+ Recipe(
176
+ StyleTagDeclaration(
177
+ StyleTag(Identifier),
178
+ StyleArgList(
179
+ StyleDeclaration(PropertyName, NumberLiteral, NumberLiteral)
180
+ StyleDeclaration(
181
+ PropertyName,
182
+ NumberLiteral(Unit),
183
+ NumberLiteral,
184
+ ColorLiteral,
185
+ StringLiteral
186
+ )
187
+ )
188
+ )
189
+ )
190
+
191
+ # PropertyName Cases
192
+
193
+ #cases{
194
+ snek_case: "hiss"
195
+ kebab-case: "🍢"
196
+ camelCase: "has 1 hump"
197
+ PascalCase: "has 2 humps"
198
+ LOUD_SNEK_CASE: "HISS!"
199
+ }
200
+
201
+ ==>
202
+
203
+ Recipe(
204
+ StyleTagDeclaration(
205
+ StyleTag(Identifier),
206
+ StyleArgList(
207
+ StyleDeclaration(PropertyName, StringLiteral),
208
+ StyleDeclaration(PropertyName, StringLiteral),
209
+ StyleDeclaration(PropertyName, StringLiteral),
210
+ StyleDeclaration(PropertyName, StringLiteral),
211
+ StyleDeclaration(PropertyName, StringLiteral),
212
+ )
213
+ )
214
+ )
@@ -0,0 +1,17 @@
1
+ import { parser } from '../dist/index.es.js'
2
+ import { fileTests } from '@lezer/generator/dist/test'
3
+
4
+ import fs from 'fs'
5
+ import path from 'path'
6
+ import { fileURLToPath } from 'url'
7
+ let caseDir = path.dirname(fileURLToPath(import.meta.url))
8
+
9
+ for (let file of fs.readdirSync(caseDir)) {
10
+ if (file === 'test-fiz.js') continue
11
+
12
+ let name = /^[^\.]*/.exec(file)[0]
13
+ describe(name, () => {
14
+ for (let { name, run } of fileTests(fs.readFileSync(path.join(caseDir, file), "utf8"), file))
15
+ it(name, () => run(parser))
16
+ })
17
+ }