@formulavize/lezer-fiz 2.0.0 → 2.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/.github/workflows/ci.yml +2 -2
- package/dist/index.cjs +12 -12
- package/dist/index.es.js +12 -12
- package/package.json +7 -7
- package/railroad-diagram.html +517 -0
- package/src/fiz.grammar +5 -0
- package/test/styling.txt +75 -0
package/.github/workflows/ci.yml
CHANGED
|
@@ -19,12 +19,12 @@ jobs:
|
|
|
19
19
|
- name: Install pnpm
|
|
20
20
|
uses: pnpm/action-setup@v4
|
|
21
21
|
with:
|
|
22
|
-
version:
|
|
22
|
+
version: 11
|
|
23
23
|
|
|
24
24
|
- name: Set up Node.js
|
|
25
25
|
uses: actions/setup-node@v4
|
|
26
26
|
with:
|
|
27
|
-
node-version:
|
|
27
|
+
node-version: 26
|
|
28
28
|
cache: pnpm
|
|
29
29
|
|
|
30
30
|
- run: pnpm install --frozen-lockfile
|
package/dist/index.cjs
CHANGED
|
@@ -5,10 +5,10 @@ var highlight = require('@lezer/highlight');
|
|
|
5
5
|
|
|
6
6
|
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
|
7
7
|
const Unit = 1,
|
|
8
|
-
cssIdentifier =
|
|
9
|
-
insertSemi =
|
|
10
|
-
spaces =
|
|
11
|
-
newline =
|
|
8
|
+
cssIdentifier = 45,
|
|
9
|
+
insertSemi = 46,
|
|
10
|
+
spaces = 48,
|
|
11
|
+
newline = 49,
|
|
12
12
|
LineComment = 2,
|
|
13
13
|
BlockComment = 3;
|
|
14
14
|
|
|
@@ -110,24 +110,24 @@ const fizHighlighting = highlight.styleTags({
|
|
|
110
110
|
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
|
111
111
|
const parser = lr.LRParser.deserialize({
|
|
112
112
|
version: 14,
|
|
113
|
-
states: "
|
|
114
|
-
stateData: ")
|
|
115
|
-
goto: "
|
|
116
|
-
nodeNames: "⚠ Unit LineComment BlockComment Recipe Call Identifier ) ( ArgList RhsVariable QualifiableIdentifier . } { StyleArgList StyleDeclaration PropertyName : ColorLiteral NumberLiteral StringLiteral StyleTag # Assignment LhsVariable Eq Namespace ] [ StatementList Import @ StyleTagDeclaration StyleBinding %",
|
|
117
|
-
maxTerm:
|
|
113
|
+
states: "+|Q`QSOOO!YQdO'#CgOOQ`'#Cf'#CfO!gQSO'#CzO!nQdO'#CwO!|QSO'#C{O#RQSO'#CtO#ZQSO'#C}O#`QSO'#DOO#eQSO'#DQO#jQdO'#D`OOQO'#DS'#DSQ`QSOOO#rQSO'#DTO#wQfO,59RO$fQSO'#CeO$nQUO'#CkO$|QdO,58{OOQO,59a,59aO%_QdO,59cO%mQSO,59gOOQ`,59f,59fO%rQSO,59fOOQ`,59c,59cO%bQdO,59cOOQ`,59g,59gO%yQSO'#DXO&OQSO,59`O&WQSO,59`O&cQSO,59iO&cQSO,59jO&cQSO,59lOOQQ'#De'#DeOOQO,59z,59zOOQO-E7Q-E7QOOQb,59o,59oOOQb-E7R-E7RO&hQSO'#CgOOQO'#Da'#DaOOQ`,59P,59PO&vQSO,59POOQO'#Cm'#CmO'OQSO'#ClO'TQSO'#CrOOQQ'#DV'#DVO'YQUO,59VOOQ`,59V,59VOOQ`1G.g1G.gOOQ`1G.}1G.}O'hQdO1G.}OOQ`1G/R1G/ROOQ`1G/Q1G/QO'sQSO'#CuOOQO,59s,59sOOQO-E7V-E7VO&WQSO1G.zOtQdO'#CgOOQ`1G.z1G.zOOQ`1G/T1G/TOOQ`1G/U1G/UOOQ`1G/W1G/WO(OQSO'#DUO(TQSO1G.kOOQ`1G.k1G.kO(]QWO,59WO(hQUO'#CgOOQQ,59^,59^OOQQ-E7T-E7TOOQ`1G.q1G.qOOQ`7+$i7+$iOOQ`7+$f7+$fOOQO,59p,59pOOQO-E7S-E7SOOQ`7+$V7+$VO(yQeO'#CpOOQ`'#Dc'#DcO)XQdO1G.rOOQ`,59[,59[O(]QWO'#DWO)XQdO7+$^OOQQ7+$^7+$^OOQ`,59r,59rOOQ`-E7U-E7UOOQQ<<Gx<<Gx",
|
|
114
|
+
stateData: ")i~O!QOS!ROSQOSROS~OUPOgVOmROpTOsWOuXO~OW_O[]OmROpdO!OZX!YZX~O^`OjiX!UiX~PtOleO~P`OW_O^`O!OkX!YkX~OeiO~OjlO!UjO~OUmO~OUnO~OUoO~O!OpO!YpO~OUsO~O[]O!OZa!YZaVZa!UZa]ZaeZagZa}Za~OUuOVwO~O]!OOe|Og{O}yO~O^`O!OTa!YTaVTa!UTa~OW_O^`O!Oka!Yka~Oe!SO~Ol!TO~P`OU!UO~Oj!XO!UjO~OU!YOmROpTO~O^`O~OW_O[]OVZX!UZX~OV!aO!U!_O~Ob!bO~OU!cO~O]!fOe|Og{O}yO~O^`O!Oki!Yki~O^`OjiX!UiX~OUuO~OV!kO!U!_O~Oc!mOe!mO!W!lO~O[]O]ZXeZXgZX}ZX~OP!oO!OdX!UdX!YdX~O!OpO!U!pO!YpO~O!Q!RU!R~",
|
|
115
|
+
goto: "&^!YPPPPP!ZPPP!k!Z!vPPP#T#o#sPP#wP#oP#{$RP$[PP$h$[P#{#{P#{P$t%O%X%_%e%kPPPPPP%q%wP%}P&TWYOR[fSv_!_Q!ZlR!h!XUaPu!YQhSR!Rc`QOR[_fl!X!_R!d{SbP!UQgSQ!PaS!QchQ![mQ!]nQ!^oR!g!RT|`}Tz`}T!m!b!pXYOR[fWUOR[fR!VjWYOR[fQ!ZlR!h!X[SOR[fl!XTcP!YQ[OQfRTr[fW^Pu!Y!cRt^Q!`xR!j!`Q}`R!e}Q!q!nR!t!qQkUR!WkXZOR[fQx_R!i!_Q!n!bR!s!pQqYQ!r!nR!u!q",
|
|
116
|
+
nodeNames: "⚠ Unit LineComment BlockComment Recipe Call Identifier ) ( ArgList RhsVariable QualifiableIdentifier . } { StyleArgList StyleDeclaration PropertyName : ColorLiteral NumberLiteral StringLiteral StyleTag # Assignment LhsVariable Eq Namespace ] [ StatementList Import @ StyleTagDeclaration StyleBinding % GlobalStyleBinding *",
|
|
117
|
+
maxTerm: 56,
|
|
118
118
|
context: trackNewline,
|
|
119
119
|
nodeProps: [
|
|
120
|
-
["group", -2,5,10,"Statement Value",-3,19,20,21,"StyleValue",-
|
|
120
|
+
["group", -2,5,10,"Statement Value",-3,19,20,21,"StyleValue",-6,24,27,31,33,34,36,"Statement"],
|
|
121
121
|
["openedBy", 7,"(",13,"{",28,"["],
|
|
122
122
|
["closedBy", 8,")",14,"}",29,"]"]
|
|
123
123
|
],
|
|
124
124
|
propSources: [fizHighlighting],
|
|
125
125
|
skippedNodes: [0,2,3],
|
|
126
126
|
repeatNodeCount: 6,
|
|
127
|
-
tokenData: "
|
|
127
|
+
tokenData: "3P~R!RXY$[YZ%PZ[$[]^%Ppq$[rs%Ust&xtu)Zuv*Owx*Txy+ryz+wz{+|{|,R|}-m}!O,R!O!P-r!P!Q-z!Q![-[![!]/s!]!^/x!_!`/}!b!c0S!c!})Z!}#O0X#P#Q0^#R#S)Z#T#o)Z#o#p0c#q#r0h$f$g$[$g#BY)Z#BY#BZ0m#BZ$IS)Z$IS$I_0m$I_$I|)Z$I|$I}2`$I}$JO2`$JO$JT)Z$JT$JU0m$JU$KV)Z$KV$KW0m$KW&FU)Z&FU&FV0m&FV;'S)Z;'S;=`)x<%l?HT)Z?HT?HU0m?HUO)Z~$aY!Q~XY$[Z[$[pq$[$f$g$[#BY#BZ$[$IS$I_$[$JT$JU$[$KV$KW$[&FU&FV$[?HT?HU$[~%UO!R~~%XWOY%UZr%Urs%qs#O%U#O#P%v#P;'S%U;'S;=`&r<%lO%U~%vOe~~%yRO;'S%U;'S;=`&S;=`O%U~&VXOY%UZr%Urs%qs#O%U#O#P%v#P;'S%U;'S;=`&r;=`<%l%U<%lO%U~&uP;=`<%l%UR&}RgP!Q!['W!c!i'W#T#Z'WQ'ZR!Q!['d!c!i'd#T#Z'dQ'gR!Q!['p!c!i'p#T#Z'pQ'uRcQ!Q![(O!c!i(O#T#Z(OQ(T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recipe":[0,4]},
|
|
130
|
-
tokenPrec:
|
|
130
|
+
tokenPrec: 388
|
|
131
131
|
});
|
|
132
132
|
|
|
133
133
|
exports.parser = parser;
|
package/dist/index.es.js
CHANGED
|
@@ -3,10 +3,10 @@ import { styleTags, tags } from '@lezer/highlight';
|
|
|
3
3
|
|
|
4
4
|
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
|
5
5
|
const Unit = 1,
|
|
6
|
-
cssIdentifier =
|
|
7
|
-
insertSemi =
|
|
8
|
-
spaces =
|
|
9
|
-
newline =
|
|
6
|
+
cssIdentifier = 45,
|
|
7
|
+
insertSemi = 46,
|
|
8
|
+
spaces = 48,
|
|
9
|
+
newline = 49,
|
|
10
10
|
LineComment = 2,
|
|
11
11
|
BlockComment = 3;
|
|
12
12
|
|
|
@@ -108,24 +108,24 @@ const fizHighlighting = styleTags({
|
|
|
108
108
|
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
|
109
109
|
const parser = LRParser.deserialize({
|
|
110
110
|
version: 14,
|
|
111
|
-
states: "
|
|
112
|
-
stateData: ")
|
|
113
|
-
goto: "
|
|
114
|
-
nodeNames: "⚠ Unit LineComment BlockComment Recipe Call Identifier ) ( ArgList RhsVariable QualifiableIdentifier . } { StyleArgList StyleDeclaration PropertyName : ColorLiteral NumberLiteral StringLiteral StyleTag # Assignment LhsVariable Eq Namespace ] [ StatementList Import @ StyleTagDeclaration StyleBinding %",
|
|
115
|
-
maxTerm:
|
|
111
|
+
states: "+|Q`QSOOO!YQdO'#CgOOQ`'#Cf'#CfO!gQSO'#CzO!nQdO'#CwO!|QSO'#C{O#RQSO'#CtO#ZQSO'#C}O#`QSO'#DOO#eQSO'#DQO#jQdO'#D`OOQO'#DS'#DSQ`QSOOO#rQSO'#DTO#wQfO,59RO$fQSO'#CeO$nQUO'#CkO$|QdO,58{OOQO,59a,59aO%_QdO,59cO%mQSO,59gOOQ`,59f,59fO%rQSO,59fOOQ`,59c,59cO%bQdO,59cOOQ`,59g,59g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X~OUuO~OV!kO!U!_O~Oc!mOe!mO!W!lO~O[]O]ZXeZXgZX}ZX~OP!oO!OdX!UdX!YdX~O!OpO!U!pO!YpO~O!Q!RU!R~",
|
|
113
|
+
goto: "&^!YPPPPP!ZPPP!k!Z!vPPP#T#o#sPP#wP#oP#{$RP$[PP$h$[P#{#{P#{P$t%O%X%_%e%kPPPPPP%q%wP%}P&TWYOR[fSv_!_Q!ZlR!h!XUaPu!YQhSR!Rc`QOR[_fl!X!_R!d{SbP!UQgSQ!PaS!QchQ![mQ!]nQ!^oR!g!RT|`}Tz`}T!m!b!pXYOR[fWUOR[fR!VjWYOR[fQ!ZlR!h!X[SOR[fl!XTcP!YQ[OQfRTr[fW^Pu!Y!cRt^Q!`xR!j!`Q}`R!e}Q!q!nR!t!qQkUR!WkXZOR[fQx_R!i!_Q!n!bR!s!pQqYQ!r!nR!u!q",
|
|
114
|
+
nodeNames: "⚠ Unit LineComment BlockComment Recipe Call Identifier ) ( ArgList RhsVariable QualifiableIdentifier . } { StyleArgList StyleDeclaration PropertyName : ColorLiteral NumberLiteral StringLiteral StyleTag # Assignment LhsVariable Eq Namespace ] [ StatementList Import @ StyleTagDeclaration StyleBinding % GlobalStyleBinding *",
|
|
115
|
+
maxTerm: 56,
|
|
116
116
|
context: trackNewline,
|
|
117
117
|
nodeProps: [
|
|
118
|
-
["group", -2,5,10,"Statement Value",-3,19,20,21,"StyleValue",-
|
|
118
|
+
["group", -2,5,10,"Statement Value",-3,19,20,21,"StyleValue",-6,24,27,31,33,34,36,"Statement"],
|
|
119
119
|
["openedBy", 7,"(",13,"{",28,"["],
|
|
120
120
|
["closedBy", 8,")",14,"}",29,"]"]
|
|
121
121
|
],
|
|
122
122
|
propSources: [fizHighlighting],
|
|
123
123
|
skippedNodes: [0,2,3],
|
|
124
124
|
repeatNodeCount: 6,
|
|
125
|
-
tokenData: "
|
|
125
|
+
tokenData: "3P~R!RXY$[YZ%PZ[$[]^%Ppq$[rs%Ust&xtu)Zuv*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q![-SQ-PP!Q![-SQ-XP!WQ!Q![-SQ-aS!WQ!O!P,b!Q![-[!g!h,p#X#Y,p~-rO!U~R-wP[P!Q![,b~-}Qz{.T!P!Q/[~.WTOz.Tz{.g{;'S.T;'S;=`/U<%lO.T~.jVOz.Tz{.g{!P.T!P!Q/P!Q;'S.T;'S;=`/U<%lO.T~/UOR~~/XP;=`<%l.T~/aSQ~OY/[Z;'S/[;'S;=`/m<%lO/[~/pP;=`<%l/[~/xOb~~/}O!Y~~0SOj~~0XOp~~0^Om~~0cOl~~0hO^~~0mO]~~0th!Q~U~XY$[Z[$[pq$[tu)Z!Q![)Z!c!})Z#R#S)Z#T#o)Z$f$g$[$g#BY)Z#BY#BZ0m#BZ$IS)Z$IS$I_0m$I_$JT)Z$JT$JU0m$JU$KV)Z$KV$KW0m$KW&FU)Z&FU&FV0m&FV;'S)Z;'S;=`)x<%l?HT)Z?HT?HU0m?HUO)Z~2gW!R~U~tu)Z!Q![)Z!c!})Z#R#S)Z#T#o)Z$g;'S)Z;'S;=`)x<%lO)Z",
|
|
126
126
|
tokenizers: [unitToken, cssIdentifierToken, 0, 1, insertSemicolon],
|
|
127
127
|
topRules: {"Recipe":[0,4]},
|
|
128
|
-
tokenPrec:
|
|
128
|
+
tokenPrec: 388
|
|
129
129
|
});
|
|
130
130
|
|
|
131
131
|
export { parser };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formulavize/lezer-fiz",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "fiz grammar for lezer",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"type": "module",
|
|
@@ -12,20 +12,20 @@
|
|
|
12
12
|
"types": "dist/index.d.ts",
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@lezer/highlight": "^1.2.3",
|
|
15
|
-
"@lezer/lr": "^1.4.
|
|
15
|
+
"@lezer/lr": "^1.4.10"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"@lezer/generator": "^1.8.0",
|
|
19
19
|
"chokidar-cli": "^3.0.0",
|
|
20
|
-
"mocha": "^11.
|
|
20
|
+
"mocha": "^11.8.0",
|
|
21
21
|
"npm-run-all": "^4.1.5",
|
|
22
22
|
"only-allow": "^1.2.2",
|
|
23
|
-
"prettier": "^3.
|
|
24
|
-
"rollup": "^4.
|
|
23
|
+
"prettier": "^3.9.6",
|
|
24
|
+
"rollup": "^4.62.4"
|
|
25
25
|
},
|
|
26
26
|
"engines": {
|
|
27
|
-
"node": ">=
|
|
28
|
-
"pnpm": ">=
|
|
27
|
+
"node": ">=26.0",
|
|
28
|
+
"pnpm": ">=11"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
31
|
"preinstall": "npx only-allow pnpm",
|
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>fiz Grammar — Railroad Diagrams</title>
|
|
7
|
+
<style>
|
|
8
|
+
body {
|
|
9
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
|
10
|
+
max-width: 1200px;
|
|
11
|
+
margin: 0 auto;
|
|
12
|
+
padding: 2rem;
|
|
13
|
+
background: #fafafa;
|
|
14
|
+
color: #222;
|
|
15
|
+
}
|
|
16
|
+
h1 { margin-bottom: 0.25rem; }
|
|
17
|
+
h1 + p { color: #666; margin-top: 0; }
|
|
18
|
+
.toc { margin: 1rem 0 2rem; columns: 3; column-gap: 2rem; }
|
|
19
|
+
.toc a { font-family: "SF Mono", "Fira Code", monospace; font-size: 0.9rem; display: block; margin-bottom: 0.3rem; }
|
|
20
|
+
section { margin-bottom: 2.5rem; scroll-margin-top: 1rem; }
|
|
21
|
+
h2 {
|
|
22
|
+
font-size: 1.1rem;
|
|
23
|
+
font-family: "SF Mono", "Fira Code", "Cascadia Code", monospace;
|
|
24
|
+
background: #e8e8e8;
|
|
25
|
+
display: inline-block;
|
|
26
|
+
padding: 0.2rem 0.6rem;
|
|
27
|
+
border-radius: 4px;
|
|
28
|
+
margin-bottom: 0.5rem;
|
|
29
|
+
}
|
|
30
|
+
.note {
|
|
31
|
+
font-size: 0.85rem;
|
|
32
|
+
color: #666;
|
|
33
|
+
margin-top: 0.25rem;
|
|
34
|
+
font-style: italic;
|
|
35
|
+
}
|
|
36
|
+
svg { display: block; margin: 0.5rem 0; border: 1px solid #ddd; border-radius: 6px; background: #fff; }
|
|
37
|
+
</style>
|
|
38
|
+
</head>
|
|
39
|
+
<body>
|
|
40
|
+
|
|
41
|
+
<h1>fiz Grammar — Railroad Diagrams</h1>
|
|
42
|
+
<p>Auto-generated from <code>lezer-fiz/src/fiz.grammar</code></p>
|
|
43
|
+
|
|
44
|
+
<div id="toc" class="toc"></div>
|
|
45
|
+
<div id="diagrams"></div>
|
|
46
|
+
|
|
47
|
+
<script>
|
|
48
|
+
// ── Minimal railroad diagram renderer ──────────────────────────
|
|
49
|
+
// Generates SVG railroad/syntax diagrams without any dependencies.
|
|
50
|
+
|
|
51
|
+
const FONT = '13px "SF Mono","Fira Code","Cascadia Code",monospace';
|
|
52
|
+
const PAD = 6; // text padding inside boxes
|
|
53
|
+
const H = 24; // box height
|
|
54
|
+
const R = 10; // arc radius
|
|
55
|
+
const GAP = 10; // horizontal gap between elements
|
|
56
|
+
const VGAP = 8; // vertical gap between choice branches
|
|
57
|
+
const ARROW = 8; // arrowhead size
|
|
58
|
+
|
|
59
|
+
// Measure text width (approximate, works offline)
|
|
60
|
+
const _canvas = document.createElement("canvas");
|
|
61
|
+
const _ctx = _canvas.getContext("2d");
|
|
62
|
+
_ctx.font = FONT;
|
|
63
|
+
function tw(text) { return _ctx.measureText(text).width; }
|
|
64
|
+
|
|
65
|
+
// SVG helpers
|
|
66
|
+
function svgEl(tag, attrs, ...children) {
|
|
67
|
+
const el = document.createElementNS("http://www.w3.org/2000/svg", tag);
|
|
68
|
+
for (const [k, v] of Object.entries(attrs || {})) el.setAttribute(k, v);
|
|
69
|
+
for (const c of children) {
|
|
70
|
+
if (typeof c === "string") el.appendChild(document.createTextNode(c));
|
|
71
|
+
else if (c) el.appendChild(c);
|
|
72
|
+
}
|
|
73
|
+
return el;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function path(d) { return svgEl("path", { d, fill: "none", stroke: "#333", "stroke-width": "2" }); }
|
|
77
|
+
|
|
78
|
+
// ── Node types ──────────────────────────────────────────────────
|
|
79
|
+
|
|
80
|
+
class Terminal {
|
|
81
|
+
constructor(text) { this.text = text; this.w = tw(text) + PAD * 2 + 8; this.h = H; this.label = null; }
|
|
82
|
+
render(x, y) {
|
|
83
|
+
const g = svgEl("g");
|
|
84
|
+
const r = 6;
|
|
85
|
+
g.appendChild(svgEl("rect", { x, y: y - this.h / 2, width: this.w, height: this.h, rx: r, ry: r, fill: "#ddf4ff", stroke: "#333", "stroke-width": "1.5" }));
|
|
86
|
+
g.appendChild(svgEl("text", { x: x + this.w / 2, y: y + 4.5, "text-anchor": "middle", fill: "#222", style: `font: ${FONT}` }, this.text));
|
|
87
|
+
return g;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
class NonTerminal {
|
|
92
|
+
constructor(text) { this.text = text; this.w = tw(text) + PAD * 2 + 8; this.h = H; this.label = null; }
|
|
93
|
+
render(x, y) {
|
|
94
|
+
const g = svgEl("g");
|
|
95
|
+
g.appendChild(svgEl("rect", { x, y: y - this.h / 2, width: this.w, height: this.h, fill: "#fff3cd", stroke: "#333", "stroke-width": "1.5" }));
|
|
96
|
+
g.appendChild(svgEl("text", { x: x + this.w / 2, y: y + 4.5, "text-anchor": "middle", fill: "#222", style: `font: ${FONT}` }, this.text));
|
|
97
|
+
return g;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
class Seq {
|
|
102
|
+
constructor(items) {
|
|
103
|
+
this.items = items;
|
|
104
|
+
this.h = Math.max(...items.map(i => i.h));
|
|
105
|
+
this.w = items.reduce((s, i) => s + i.w, 0) + GAP * (items.length - 1);
|
|
106
|
+
this.label = null;
|
|
107
|
+
}
|
|
108
|
+
render(x, y) {
|
|
109
|
+
const g = svgEl("g");
|
|
110
|
+
let cx = x;
|
|
111
|
+
for (let i = 0; i < this.items.length; i++) {
|
|
112
|
+
const item = this.items[i];
|
|
113
|
+
g.appendChild(item.render(cx, y));
|
|
114
|
+
cx += item.w;
|
|
115
|
+
if (i < this.items.length - 1) {
|
|
116
|
+
g.appendChild(path(`M${cx},${y} h${GAP}`));
|
|
117
|
+
cx += GAP;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return g;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function measureBranches(items) {
|
|
125
|
+
// For each item, measure height above and below center
|
|
126
|
+
const above = [];
|
|
127
|
+
const below = [];
|
|
128
|
+
for (const item of items) {
|
|
129
|
+
above.push(item.h / 2);
|
|
130
|
+
below.push(item.h / 2);
|
|
131
|
+
}
|
|
132
|
+
return { above, below };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
class ChoiceNode {
|
|
136
|
+
constructor(defaultIdx, items) {
|
|
137
|
+
this.defaultIdx = defaultIdx;
|
|
138
|
+
this.items = items;
|
|
139
|
+
const maxW = Math.max(...items.map(i => i.w));
|
|
140
|
+
this.innerW = maxW;
|
|
141
|
+
this.w = maxW + R * 4 + GAP * 2;
|
|
142
|
+
|
|
143
|
+
// Calculate total height
|
|
144
|
+
let totalH = 0;
|
|
145
|
+
for (let i = 0; i < items.length; i++) {
|
|
146
|
+
totalH += items[i].h;
|
|
147
|
+
if (i < items.length - 1) totalH += VGAP;
|
|
148
|
+
}
|
|
149
|
+
this.h = totalH;
|
|
150
|
+
this.label = null;
|
|
151
|
+
|
|
152
|
+
// Pre-calculate y offsets for each branch (relative to center of default branch)
|
|
153
|
+
this.branchY = [];
|
|
154
|
+
let accum = 0;
|
|
155
|
+
for (let i = 0; i < items.length; i++) {
|
|
156
|
+
this.branchY.push(accum + items[i].h / 2);
|
|
157
|
+
accum += items[i].h + VGAP;
|
|
158
|
+
}
|
|
159
|
+
const defaultCenter = this.branchY[defaultIdx];
|
|
160
|
+
for (let i = 0; i < this.branchY.length; i++) this.branchY[i] -= defaultCenter;
|
|
161
|
+
}
|
|
162
|
+
render(x, y) {
|
|
163
|
+
const g = svgEl("g");
|
|
164
|
+
const midX = x + this.w / 2;
|
|
165
|
+
for (let i = 0; i < this.items.length; i++) {
|
|
166
|
+
const item = this.items[i];
|
|
167
|
+
const by = y + this.branchY[i];
|
|
168
|
+
const itemX = midX - item.w / 2;
|
|
169
|
+
// Left connector
|
|
170
|
+
if (i === this.defaultIdx) {
|
|
171
|
+
g.appendChild(path(`M${x},${y} H${itemX}`));
|
|
172
|
+
} else {
|
|
173
|
+
const goDown = by > y;
|
|
174
|
+
if (goDown) {
|
|
175
|
+
g.appendChild(path(`M${x},${y} v${by - y - R} a${R},${R} 0 0,0 ${R},${R} H${itemX}`));
|
|
176
|
+
} else {
|
|
177
|
+
g.appendChild(path(`M${x},${y} v${by - y + R} a${R},${R} 0 0,1 ${R},-${R} H${itemX}`));
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
g.appendChild(item.render(itemX, by));
|
|
181
|
+
// Right connector
|
|
182
|
+
const rightEnd = x + this.w;
|
|
183
|
+
const itemRight = itemX + item.w;
|
|
184
|
+
if (i === this.defaultIdx) {
|
|
185
|
+
g.appendChild(path(`M${itemRight},${by} H${rightEnd}`));
|
|
186
|
+
} else {
|
|
187
|
+
const goUp = by > y;
|
|
188
|
+
if (goUp) {
|
|
189
|
+
g.appendChild(path(`M${itemRight},${by} H${rightEnd - R} a${R},${R} 0 0,0 ${R},-${R} V${y}`));
|
|
190
|
+
} else {
|
|
191
|
+
g.appendChild(path(`M${itemRight},${by} H${rightEnd - R} a${R},${R} 0 0,1 ${R},${R} V${y}`));
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return g;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
class LoopNode {
|
|
200
|
+
// item going forward, rep going backward (optional)
|
|
201
|
+
constructor(item, rep, skipAllowed) {
|
|
202
|
+
this.item = item;
|
|
203
|
+
this.rep = rep;
|
|
204
|
+
this.skipAllowed = skipAllowed;
|
|
205
|
+
this.w = Math.max(item.w, rep ? rep.w : 0) + R * 4 + GAP * 2;
|
|
206
|
+
const repH = rep ? rep.h : H * 0.6;
|
|
207
|
+
this.h = item.h + repH + VGAP;
|
|
208
|
+
this.label = null;
|
|
209
|
+
}
|
|
210
|
+
render(x, y) {
|
|
211
|
+
const g = svgEl("g");
|
|
212
|
+
const midX = x + this.w / 2;
|
|
213
|
+
const itemX = midX - this.item.w / 2;
|
|
214
|
+
const loopY = y + this.item.h / 2 + VGAP + (this.rep ? this.rep.h / 2 : 4);
|
|
215
|
+
|
|
216
|
+
if (this.skipAllowed) {
|
|
217
|
+
// Draw skip path above
|
|
218
|
+
const skipY = y - this.item.h / 2 - VGAP;
|
|
219
|
+
g.appendChild(path(`M${x},${y} v${skipY - y + R} a${R},${R} 0 0,1 ${R},-${R} H${x + this.w - R} a${R},${R} 0 0,1 ${R},${R} V${y}`));
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// Forward path
|
|
223
|
+
g.appendChild(path(`M${x},${y} H${itemX}`));
|
|
224
|
+
g.appendChild(this.item.render(itemX, y));
|
|
225
|
+
g.appendChild(path(`M${itemX + this.item.w},${y} H${x + this.w}`));
|
|
226
|
+
|
|
227
|
+
// Loop-back path
|
|
228
|
+
const repX = this.rep ? midX - this.rep.w / 2 : midX;
|
|
229
|
+
// Right side going down
|
|
230
|
+
g.appendChild(path(`M${x + this.w - R},${y} a${R},${R} 0 0,1 ${R},${R} V${loopY - R} a${R},${R} 0 0,1 -${R},${R}`));
|
|
231
|
+
if (this.rep) {
|
|
232
|
+
g.appendChild(path(`M${x + this.w - R},${loopY} H${repX + this.rep.w}`));
|
|
233
|
+
g.appendChild(this.rep.render(repX, loopY));
|
|
234
|
+
g.appendChild(path(`M${repX},${loopY} H${x + R}`));
|
|
235
|
+
} else {
|
|
236
|
+
// Just a line with arrow
|
|
237
|
+
g.appendChild(path(`M${x + this.w - R},${loopY} H${x + R}`));
|
|
238
|
+
// Arrow in middle pointing left
|
|
239
|
+
const arrowX = midX;
|
|
240
|
+
g.appendChild(svgEl("polygon", { points: `${arrowX + 4},${loopY - 4} ${arrowX - 4},${loopY} ${arrowX + 4},${loopY + 4}`, fill: "#333", stroke: "none" }));
|
|
241
|
+
}
|
|
242
|
+
// Left side going up
|
|
243
|
+
g.appendChild(path(`M${x + R},${loopY} a${R},${R} 0 0,1 -${R},-${R} V${y + R} a${R},${R} 0 0,1 ${R},-${R}`));
|
|
244
|
+
|
|
245
|
+
return g;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
class OptNode {
|
|
250
|
+
constructor(item) {
|
|
251
|
+
this.item = item;
|
|
252
|
+
this.w = item.w + R * 4 + GAP * 2;
|
|
253
|
+
this.h = item.h + VGAP + R * 2;
|
|
254
|
+
this.label = null;
|
|
255
|
+
}
|
|
256
|
+
render(x, y) {
|
|
257
|
+
const g = svgEl("g");
|
|
258
|
+
const midX = x + this.w / 2;
|
|
259
|
+
const itemX = midX - this.item.w / 2;
|
|
260
|
+
|
|
261
|
+
// Main path through item
|
|
262
|
+
g.appendChild(path(`M${x},${y} H${itemX}`));
|
|
263
|
+
g.appendChild(this.item.render(itemX, y));
|
|
264
|
+
g.appendChild(path(`M${itemX + this.item.w},${y} H${x + this.w}`));
|
|
265
|
+
|
|
266
|
+
// Skip path (below)
|
|
267
|
+
const skipY = y + this.item.h / 2 + VGAP;
|
|
268
|
+
g.appendChild(path(`M${x},${y} v${skipY - y - R} a${R},${R} 0 0,0 ${R},${R} H${x + this.w - R} a${R},${R} 0 0,0 ${R},-${R} V${y}`));
|
|
269
|
+
|
|
270
|
+
return g;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// ── Builder functions ───────────────────────────────────────────
|
|
275
|
+
|
|
276
|
+
function T(text) { return new Terminal(text); }
|
|
277
|
+
function NT(text) { return new NonTerminal(text); }
|
|
278
|
+
function Seq_(...items) { return items.length === 1 ? items[0] : new Seq(items); }
|
|
279
|
+
function Choice(defaultIdx, ...items) { return items.length === 1 ? items[0] : new ChoiceNode(defaultIdx, items); }
|
|
280
|
+
function Opt(item) { return new OptNode(item); }
|
|
281
|
+
function ZeroOrMore(item, rep) { return new LoopNode(item, rep || null, true); }
|
|
282
|
+
function OneOrMore(item, rep) { return new LoopNode(item, rep || null, false); }
|
|
283
|
+
|
|
284
|
+
function renderDiagram(node) {
|
|
285
|
+
const padX = 20;
|
|
286
|
+
const padY = 20;
|
|
287
|
+
const totalW = node.w + padX * 2 + 30; // extra for entry/exit lines
|
|
288
|
+
const totalH = node.h + padY * 2;
|
|
289
|
+
|
|
290
|
+
const svg = svgEl("svg", {
|
|
291
|
+
width: totalW,
|
|
292
|
+
height: totalH,
|
|
293
|
+
viewBox: `0 0 ${totalW} ${totalH}`,
|
|
294
|
+
class: "railroad-diagram",
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
const centerY = totalH / 2;
|
|
298
|
+
const startX = padX;
|
|
299
|
+
const nodeX = padX + 15;
|
|
300
|
+
|
|
301
|
+
// Entry line
|
|
302
|
+
svg.appendChild(path(`M${startX},${centerY} H${nodeX}`));
|
|
303
|
+
// Entry circle
|
|
304
|
+
svg.appendChild(svgEl("circle", { cx: startX, cy: centerY, r: 3, fill: "#333" }));
|
|
305
|
+
|
|
306
|
+
// Main content
|
|
307
|
+
svg.appendChild(node.render(nodeX, centerY));
|
|
308
|
+
|
|
309
|
+
// Exit line
|
|
310
|
+
const exitStart = nodeX + node.w;
|
|
311
|
+
const exitEnd = exitStart + 15;
|
|
312
|
+
svg.appendChild(path(`M${exitStart},${centerY} H${exitEnd}`));
|
|
313
|
+
// Exit double line
|
|
314
|
+
svg.appendChild(svgEl("circle", { cx: exitEnd, cy: centerY, r: 3, fill: "#333" }));
|
|
315
|
+
svg.appendChild(svgEl("circle", { cx: exitEnd, cy: centerY, r: 6, fill: "none", stroke: "#333", "stroke-width": "1.5" }));
|
|
316
|
+
|
|
317
|
+
return svg;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// ── Grammar definitions ─────────────────────────────────────────
|
|
321
|
+
|
|
322
|
+
const rules = [];
|
|
323
|
+
function def(name, node, note) { rules.push({ name, node, note }); }
|
|
324
|
+
|
|
325
|
+
// Recipe (top-level)
|
|
326
|
+
def("Recipe",
|
|
327
|
+
ZeroOrMore(NT("statement"))
|
|
328
|
+
);
|
|
329
|
+
|
|
330
|
+
// statement
|
|
331
|
+
def("statement",
|
|
332
|
+
Seq_(
|
|
333
|
+
Choice(0,
|
|
334
|
+
NT("Call"),
|
|
335
|
+
NT("RhsVariable"),
|
|
336
|
+
NT("Assignment"),
|
|
337
|
+
NT("StyleTagDeclaration"),
|
|
338
|
+
NT("StyleBinding"),
|
|
339
|
+
NT("GlobalStyleBinding"),
|
|
340
|
+
NT("Namespace"),
|
|
341
|
+
NT("Import"),
|
|
342
|
+
),
|
|
343
|
+
NT("semi"),
|
|
344
|
+
)
|
|
345
|
+
);
|
|
346
|
+
|
|
347
|
+
// semi
|
|
348
|
+
def("semi",
|
|
349
|
+
Choice(0, T(";"), T("\u23CE auto-insert")),
|
|
350
|
+
"Semicolons are automatically inserted at newlines (ASI)"
|
|
351
|
+
);
|
|
352
|
+
|
|
353
|
+
// QualifiableIdentifier
|
|
354
|
+
def("QualifiableIdentifier",
|
|
355
|
+
Seq_(T("Identifier"), ZeroOrMore(Seq_(T("."), T("Identifier"))))
|
|
356
|
+
);
|
|
357
|
+
|
|
358
|
+
// Call
|
|
359
|
+
def("Call",
|
|
360
|
+
Seq_(T("Identifier"), NT("ArgList"), Opt(NT("StyleArgList")))
|
|
361
|
+
);
|
|
362
|
+
|
|
363
|
+
// ArgList
|
|
364
|
+
def("ArgList",
|
|
365
|
+
Seq_(T("("), Opt(Seq_(NT("value"), ZeroOrMore(Seq_(T(","), NT("value"))))), T(")"))
|
|
366
|
+
);
|
|
367
|
+
|
|
368
|
+
// value
|
|
369
|
+
def("value",
|
|
370
|
+
Choice(0, NT("RhsVariable"), NT("Call")),
|
|
371
|
+
"Namespace and Import are disallowed inside ArgList for readability"
|
|
372
|
+
);
|
|
373
|
+
|
|
374
|
+
// RhsVariable
|
|
375
|
+
def("RhsVariable",
|
|
376
|
+
NT("QualifiableIdentifier")
|
|
377
|
+
);
|
|
378
|
+
|
|
379
|
+
// LhsVariable
|
|
380
|
+
def("LhsVariable",
|
|
381
|
+
Seq_(T("Identifier"), Opt(NT("StyleArgList")))
|
|
382
|
+
);
|
|
383
|
+
|
|
384
|
+
// Assignment
|
|
385
|
+
def("Assignment",
|
|
386
|
+
Seq_(
|
|
387
|
+
NT("LhsVariable"),
|
|
388
|
+
ZeroOrMore(Seq_(T(","), NT("LhsVariable"))),
|
|
389
|
+
T("="),
|
|
390
|
+
Choice(0, NT("Call"), NT("RhsVariable"), NT("Namespace"), NT("Import")),
|
|
391
|
+
)
|
|
392
|
+
);
|
|
393
|
+
|
|
394
|
+
// Namespace
|
|
395
|
+
def("Namespace",
|
|
396
|
+
Seq_(Opt(T("Identifier")), NT("StatementList"), Opt(NT("ArgList")), Opt(NT("StyleArgList")))
|
|
397
|
+
);
|
|
398
|
+
|
|
399
|
+
// StatementList
|
|
400
|
+
def("StatementList",
|
|
401
|
+
Seq_(T("["), ZeroOrMore(NT("statement")), T("]"))
|
|
402
|
+
);
|
|
403
|
+
|
|
404
|
+
// Import
|
|
405
|
+
def("Import",
|
|
406
|
+
Seq_(Opt(T("Identifier")), T("@"), T("StringLiteral")),
|
|
407
|
+
"StringLiteral is a path-like resource identifier"
|
|
408
|
+
);
|
|
409
|
+
|
|
410
|
+
// StyleTagDeclaration
|
|
411
|
+
def("StyleTagDeclaration",
|
|
412
|
+
Seq_(T("#"), T("Identifier"), NT("StyleArgList"))
|
|
413
|
+
);
|
|
414
|
+
|
|
415
|
+
// StyleTag
|
|
416
|
+
def("StyleTag",
|
|
417
|
+
Seq_(T("#"), NT("QualifiableIdentifier"))
|
|
418
|
+
);
|
|
419
|
+
|
|
420
|
+
// StyleArgList
|
|
421
|
+
def("StyleArgList",
|
|
422
|
+
Seq_(T("{"), ZeroOrMore(Choice(0, NT("StyleDeclaration"), NT("StyleTag"), T("StringLiteral"))), T("}"))
|
|
423
|
+
);
|
|
424
|
+
|
|
425
|
+
// StyleDeclaration
|
|
426
|
+
def("StyleDeclaration",
|
|
427
|
+
Seq_(NT("PropertyName"), T(":"), NT("styleValue"), ZeroOrMore(Seq_(T(","), NT("styleValue"))), NT("semi"))
|
|
428
|
+
);
|
|
429
|
+
|
|
430
|
+
// styleValue
|
|
431
|
+
def("styleValue",
|
|
432
|
+
Choice(0, T("ColorLiteral"), NT("NumberLiteral"), T("StringLiteral"))
|
|
433
|
+
);
|
|
434
|
+
|
|
435
|
+
// StyleBinding
|
|
436
|
+
def("StyleBinding",
|
|
437
|
+
Seq_(T("%"), T("Identifier"), NT("StyleArgList"))
|
|
438
|
+
);
|
|
439
|
+
|
|
440
|
+
// GlobalStyleBinding
|
|
441
|
+
def("GlobalStyleBinding",
|
|
442
|
+
Seq_(T("*"), T("Identifier"), NT("StyleArgList"))
|
|
443
|
+
);
|
|
444
|
+
|
|
445
|
+
// NumberLiteral
|
|
446
|
+
def("NumberLiteral",
|
|
447
|
+
Seq_(T("number"), Opt(T("Unit")))
|
|
448
|
+
);
|
|
449
|
+
|
|
450
|
+
// PropertyName
|
|
451
|
+
def("PropertyName",
|
|
452
|
+
T("cssIdentifier")
|
|
453
|
+
);
|
|
454
|
+
|
|
455
|
+
// Identifier (token)
|
|
456
|
+
def("Identifier",
|
|
457
|
+
Seq_(T("letter | _ | $"), ZeroOrMore(T("letter | digit | _ | $"))),
|
|
458
|
+
"Token rule — also allows Unicode \\u00A1+"
|
|
459
|
+
);
|
|
460
|
+
|
|
461
|
+
// ColorLiteral (token)
|
|
462
|
+
def("ColorLiteral",
|
|
463
|
+
Seq_(T("#"), T("hex\u00D7 3"), Opt(Seq_(T("hex"), Opt(Seq_(T("hex\u00D7 2"), Opt(T("hex\u00D7 2"))))))),
|
|
464
|
+
"Supports #RGB, #RGBA, #RRGGBB, #RRGGBBAA"
|
|
465
|
+
);
|
|
466
|
+
|
|
467
|
+
// StringLiteral (token)
|
|
468
|
+
def("StringLiteral",
|
|
469
|
+
Choice(0,
|
|
470
|
+
Seq_(T('"'), ZeroOrMore(Choice(0, T("char"), Seq_(T("\\"), T("any")))), T('"')),
|
|
471
|
+
Seq_(T("'"), ZeroOrMore(Choice(0, T("char"), Seq_(T("\\"), T("any")))), T("'")),
|
|
472
|
+
),
|
|
473
|
+
"Double or single quoted with backslash escapes"
|
|
474
|
+
);
|
|
475
|
+
|
|
476
|
+
// ── Render all ──────────────────────────────────────────────────
|
|
477
|
+
|
|
478
|
+
const container = document.getElementById("diagrams");
|
|
479
|
+
const tocEl = document.getElementById("toc");
|
|
480
|
+
|
|
481
|
+
for (const { name, node, note } of rules) {
|
|
482
|
+
const id = "rule-" + name;
|
|
483
|
+
|
|
484
|
+
// TOC entry
|
|
485
|
+
const a = document.createElement("a");
|
|
486
|
+
a.href = "#" + id;
|
|
487
|
+
a.textContent = name;
|
|
488
|
+
tocEl.appendChild(a);
|
|
489
|
+
|
|
490
|
+
// Section
|
|
491
|
+
const section = document.createElement("section");
|
|
492
|
+
section.id = id;
|
|
493
|
+
const heading = document.createElement("h2");
|
|
494
|
+
heading.textContent = name;
|
|
495
|
+
section.appendChild(heading);
|
|
496
|
+
|
|
497
|
+
try {
|
|
498
|
+
section.appendChild(renderDiagram(node));
|
|
499
|
+
} catch (e) {
|
|
500
|
+
const err = document.createElement("pre");
|
|
501
|
+
err.style.color = "red";
|
|
502
|
+
err.textContent = "Error rendering: " + e.message;
|
|
503
|
+
section.appendChild(err);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
if (note) {
|
|
507
|
+
const p = document.createElement("p");
|
|
508
|
+
p.className = "note";
|
|
509
|
+
p.textContent = note;
|
|
510
|
+
section.appendChild(p);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
container.appendChild(section);
|
|
514
|
+
}
|
|
515
|
+
</script>
|
|
516
|
+
</body>
|
|
517
|
+
</html>
|
package/src/fiz.grammar
CHANGED
|
@@ -7,6 +7,7 @@ statement[@isGroup=Statement] {
|
|
|
7
7
|
Assignment |
|
|
8
8
|
StyleTagDeclaration |
|
|
9
9
|
StyleBinding |
|
|
10
|
+
GlobalStyleBinding |
|
|
10
11
|
Namespace |
|
|
11
12
|
Import
|
|
12
13
|
)
|
|
@@ -50,6 +51,8 @@ StyleArgList { "{" (StyleDeclaration | StyleTag | StringLiteral)* "}" }
|
|
|
50
51
|
|
|
51
52
|
StyleBinding { "%" Identifier StyleArgList }
|
|
52
53
|
|
|
54
|
+
GlobalStyleBinding { "*" Identifier StyleArgList }
|
|
55
|
+
|
|
53
56
|
StatementList { "[" statement* "]" }
|
|
54
57
|
|
|
55
58
|
Namespace { Identifier? StatementList ArgList? StyleArgList? }
|
|
@@ -106,6 +109,8 @@ Import { Identifier? "@" StringLiteral }
|
|
|
106
109
|
|
|
107
110
|
"@"
|
|
108
111
|
|
|
112
|
+
"*"
|
|
113
|
+
|
|
109
114
|
"(" ")" "{" "}" "[" "]"
|
|
110
115
|
|
|
111
116
|
}
|
package/test/styling.txt
CHANGED
|
@@ -292,6 +292,81 @@ Recipe(
|
|
|
292
292
|
)
|
|
293
293
|
)
|
|
294
294
|
|
|
295
|
+
# Global Style Binding with StyleTags
|
|
296
|
+
|
|
297
|
+
*nodes{}
|
|
298
|
+
*edges{
|
|
299
|
+
#x #y
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
==>
|
|
303
|
+
|
|
304
|
+
Recipe(
|
|
305
|
+
GlobalStyleBinding(Identifier, StyleArgList())
|
|
306
|
+
GlobalStyleBinding(
|
|
307
|
+
Identifier,
|
|
308
|
+
StyleArgList(
|
|
309
|
+
StyleTag(QualifiableIdentifier(Identifier))
|
|
310
|
+
StyleTag(QualifiableIdentifier(Identifier)),
|
|
311
|
+
)
|
|
312
|
+
)
|
|
313
|
+
)
|
|
314
|
+
|
|
315
|
+
# Global Style Binding with Style Declarations
|
|
316
|
+
|
|
317
|
+
*nodes{
|
|
318
|
+
color: #ff0000
|
|
319
|
+
font-size: 12px
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
==>
|
|
323
|
+
|
|
324
|
+
Recipe(
|
|
325
|
+
GlobalStyleBinding(
|
|
326
|
+
Identifier,
|
|
327
|
+
StyleArgList(
|
|
328
|
+
StyleDeclaration(PropertyName, ColorLiteral),
|
|
329
|
+
StyleDeclaration(PropertyName, NumberLiteral(Unit))
|
|
330
|
+
)
|
|
331
|
+
)
|
|
332
|
+
)
|
|
333
|
+
|
|
334
|
+
# Global Style Binding with StringLiteral
|
|
335
|
+
|
|
336
|
+
*nodes{
|
|
337
|
+
"description"
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
==>
|
|
341
|
+
|
|
342
|
+
Recipe(
|
|
343
|
+
GlobalStyleBinding(
|
|
344
|
+
Identifier,
|
|
345
|
+
StyleArgList(StringLiteral)
|
|
346
|
+
)
|
|
347
|
+
)
|
|
348
|
+
|
|
349
|
+
# Global Style Binding Mixed Content
|
|
350
|
+
|
|
351
|
+
*nodes{
|
|
352
|
+
#base
|
|
353
|
+
color: #abc
|
|
354
|
+
"note"
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
==>
|
|
358
|
+
|
|
359
|
+
Recipe(
|
|
360
|
+
GlobalStyleBinding(
|
|
361
|
+
Identifier,
|
|
362
|
+
StyleArgList(
|
|
363
|
+
StyleTag(QualifiableIdentifier(Identifier)),
|
|
364
|
+
StyleDeclaration(PropertyName, ColorLiteral),
|
|
365
|
+
StringLiteral
|
|
366
|
+
)
|
|
367
|
+
)
|
|
368
|
+
)
|
|
369
|
+
|
|
295
370
|
# Description Shortcut
|
|
296
371
|
|
|
297
372
|
#a{
|