klue-langcraft 0.0.6 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.builders/generators/project-plan.rb +5 -0
- data/CHANGELOG.md +14 -0
- data/README.md +0 -2
- data/docs/dsl-examples.md +105 -0
- data/docs/dsl-rules.md +155 -0
- data/docs/dsl-samples/index.md +4 -0
- data/docs/dsl-samples/youtube-launch-optimizer-old.klue +300 -0
- data/docs/dsl-samples/youtube-launch-optimizer-strawberry.json +132 -0
- data/docs/dsl-samples/youtube-launch-optimizer-strawberry.klue +47 -0
- data/docs/dsl-samples/youtube-launch-optimizer.defn.klue +51 -0
- data/docs/dsl-samples/youtube-launch-optimizer.json +337 -0
- data/docs/dsl-samples/youtube-launch-optimizer.klue +47 -0
- data/docs/project-plan/project.drawio +27 -21
- data/docs/project-plan/project_done.svg +1 -1
- data/docs/project-plan/project_in_progress.svg +1 -1
- data/docs/project-plan/project_todo.svg +1 -1
- data/lib/klue/langcraft/-brief.md +357 -0
- data/lib/klue/langcraft/parser.rb +78 -0
- data/lib/klue/langcraft/sample_usage.rb +15 -0
- data/lib/klue/langcraft/tokenizer.rb +20 -0
- data/lib/klue/langcraft/version.rb +1 -1
- data/package-lock.json +2 -2
- data/package.json +1 -1
- metadata +15 -2
@@ -1,56 +1,62 @@
|
|
1
|
-
<mxfile host="
|
2
|
-
<diagram id="
|
1
|
+
<mxfile host="DKN">
|
2
|
+
<diagram id="y30" name="In progress">
|
3
3
|
<mxGraphModel dx="0" dy="0" background="#FFFAFA" grid="0" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1169" pageHeight="827" math="0" shadow="0">
|
4
4
|
<root>
|
5
|
-
<mxCell id="
|
6
|
-
<mxCell id="
|
7
|
-
<mxCell id="
|
5
|
+
<mxCell id="page_root_y30" parent="y30"/>
|
6
|
+
<mxCell id="node_root_y30" parent="page_root_y30"/>
|
7
|
+
<mxCell id="y30-2" value="DSLs as Code sample DSL" style="whiteSpace=wrap;html=1;rounded=1;glass=1;fillColor=#d5e8d4;strokeColor=#82b366;fontColor=#333333" vertex="1" parent="node_root_y30">
|
8
8
|
<mxGeometry x="10" y="10" width="300" height="60" as="geometry"/>
|
9
9
|
</mxCell>
|
10
|
+
<mxCell id="y30-3" value="Automate Base DSL setup" style="whiteSpace=wrap;html=1;rounded=1;glass=1;fillColor=#d5e8d4;strokeColor=#82b366;fontColor=#333333" vertex="1" parent="node_root_y30">
|
11
|
+
<mxGeometry x="330" y="10" width="300" height="60" as="geometry"/>
|
12
|
+
</mxCell>
|
13
|
+
<mxCell id="y30-4" value="Automate DSL definion/designer for target DSL" style="whiteSpace=wrap;html=1;rounded=1;glass=1;fillColor=#d5e8d4;strokeColor=#82b366;fontColor=#333333" vertex="1" parent="node_root_y30">
|
14
|
+
<mxGeometry x="650" y="10" width="300" height="60" as="geometry"/>
|
15
|
+
</mxCell>
|
10
16
|
</root>
|
11
17
|
</mxGraphModel>
|
12
18
|
</diagram>
|
13
|
-
<diagram id="
|
19
|
+
<diagram id="gaX" name="To Do">
|
14
20
|
<mxGraphModel dx="0" dy="0" background="#FFFAFA" grid="0" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1169" pageHeight="827" math="0" shadow="0">
|
15
21
|
<root>
|
16
|
-
<mxCell id="
|
17
|
-
<mxCell id="
|
18
|
-
<mxCell id="
|
22
|
+
<mxCell id="page_root_gaX" parent="gaX"/>
|
23
|
+
<mxCell id="node_root_gaX" parent="page_root_gaX"/>
|
24
|
+
<mxCell id="gaX-2" value="Add guideline documentation" style="whiteSpace=wrap;html=1;rounded=1;glass=1;fillColor=#dae8fc;strokeColor=#6c8ebf;fontColor=#333333" vertex="1" parent="node_root_gaX">
|
19
25
|
<mxGeometry x="10" y="10" width="300" height="60" as="geometry"/>
|
20
26
|
</mxCell>
|
21
|
-
<mxCell id="
|
27
|
+
<mxCell id="gaX-3" value="Docs as Code sample DSL" style="whiteSpace=wrap;html=1;rounded=1;glass=1;fillColor=#dae8fc;strokeColor=#6c8ebf;fontColor=#333333" vertex="1" parent="node_root_gaX">
|
22
28
|
<mxGeometry x="330" y="10" width="300" height="60" as="geometry"/>
|
23
29
|
</mxCell>
|
24
|
-
<mxCell id="
|
30
|
+
<mxCell id="gaX-4" value="Agent as Code sample DSL" style="whiteSpace=wrap;html=1;rounded=1;glass=1;fillColor=#dae8fc;strokeColor=#6c8ebf;fontColor=#333333" vertex="1" parent="node_root_gaX">
|
25
31
|
<mxGeometry x="650" y="10" width="300" height="60" as="geometry"/>
|
26
32
|
</mxCell>
|
27
|
-
<mxCell id="
|
33
|
+
<mxCell id="gaX-5" value="Poly as Code sample DSL" style="whiteSpace=wrap;html=1;rounded=1;glass=1;fillColor=#dae8fc;strokeColor=#6c8ebf;fontColor=#333333" vertex="1" parent="node_root_gaX">
|
28
34
|
<mxGeometry x="10" y="90" width="300" height="60" as="geometry"/>
|
29
35
|
</mxCell>
|
30
|
-
<mxCell id="
|
36
|
+
<mxCell id="gaX-6" value="Voice as Code sample DSL" style="whiteSpace=wrap;html=1;rounded=1;glass=1;fillColor=#dae8fc;strokeColor=#6c8ebf;fontColor=#333333" vertex="1" parent="node_root_gaX">
|
31
37
|
<mxGeometry x="330" y="90" width="300" height="60" as="geometry"/>
|
32
38
|
</mxCell>
|
33
|
-
<mxCell id="
|
39
|
+
<mxCell id="gaX-7" value="Data as Code sample DSL" style="whiteSpace=wrap;html=1;rounded=1;glass=1;fillColor=#dae8fc;strokeColor=#6c8ebf;fontColor=#333333" vertex="1" parent="node_root_gaX">
|
34
40
|
<mxGeometry x="650" y="90" width="300" height="60" as="geometry"/>
|
35
41
|
</mxCell>
|
36
|
-
<mxCell id="
|
42
|
+
<mxCell id="gaX-8" value="Chart Design as Code sample DSL" style="whiteSpace=wrap;html=1;rounded=1;glass=1;fillColor=#dae8fc;strokeColor=#6c8ebf;fontColor=#333333" vertex="1" parent="node_root_gaX">
|
37
43
|
<mxGeometry x="10" y="170" width="300" height="60" as="geometry"/>
|
38
44
|
</mxCell>
|
39
|
-
<mxCell id="
|
45
|
+
<mxCell id="gaX-9" value="Video as Code sample DSL" style="whiteSpace=wrap;html=1;rounded=1;glass=1;fillColor=#dae8fc;strokeColor=#6c8ebf;fontColor=#333333" vertex="1" parent="node_root_gaX">
|
40
46
|
<mxGeometry x="330" y="170" width="300" height="60" as="geometry"/>
|
41
47
|
</mxCell>
|
42
|
-
<mxCell id="
|
48
|
+
<mxCell id="gaX-10" value="Image as Code sample DSL" style="whiteSpace=wrap;html=1;rounded=1;glass=1;fillColor=#dae8fc;strokeColor=#6c8ebf;fontColor=#333333" vertex="1" parent="node_root_gaX">
|
43
49
|
<mxGeometry x="650" y="170" width="300" height="60" as="geometry"/>
|
44
50
|
</mxCell>
|
45
51
|
</root>
|
46
52
|
</mxGraphModel>
|
47
53
|
</diagram>
|
48
|
-
<diagram id="
|
54
|
+
<diagram id="Iaa" name="Done">
|
49
55
|
<mxGraphModel dx="0" dy="0" background="#FFFAFA" grid="0" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1169" pageHeight="827" math="0" shadow="0">
|
50
56
|
<root>
|
51
|
-
<mxCell id="
|
52
|
-
<mxCell id="
|
53
|
-
<mxCell id="
|
57
|
+
<mxCell id="page_root_Iaa" parent="Iaa"/>
|
58
|
+
<mxCell id="node_root_Iaa" parent="page_root_Iaa"/>
|
59
|
+
<mxCell id="Iaa-2" value="Setup project with CI/CD, tests, linting, basic doumentation, semantic versioning" style="whiteSpace=wrap;html=1;rounded=1;glass=1;fillColor=#f8cecc;strokeColor=#b85450;fontColor=#333333" vertex="1" parent="node_root_Iaa">
|
54
60
|
<mxGeometry x="10" y="10" width="300" height="60" as="geometry"/>
|
55
61
|
</mxCell>
|
56
62
|
</root>
|
@@ -1,3 +1,3 @@
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
2
2
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
3
|
-
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="302px" height="62px" viewBox="-0.5 -0.5 302 62"><defs><linearGradient x1="0%" y1="0%" x2="0%" y2="100%" id="mx-gradient-ffffff-0.9-ffffff-0.1-s-0"><stop offset="0%" style="stop-color: rgb(255, 255, 255); stop-opacity: 0.9;"/><stop offset="100%" style="stop-color: rgb(255, 255, 255); stop-opacity: 0.1;"/></linearGradient></defs><g><g data-cell-id="
|
3
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="302px" height="62px" viewBox="-0.5 -0.5 302 62"><defs><linearGradient x1="0%" y1="0%" x2="0%" y2="100%" id="mx-gradient-ffffff-0.9-ffffff-0.1-s-0"><stop offset="0%" style="stop-color: rgb(255, 255, 255); stop-opacity: 0.9;"/><stop offset="100%" style="stop-color: rgb(255, 255, 255); stop-opacity: 0.1;"/></linearGradient></defs><g><g data-cell-id="page_root_Iaa"><g data-cell-id="node_root_Iaa"><g data-cell-id="Iaa-2"><g><rect x="0" y="0" width="300" height="60" rx="9" ry="9" fill="#f8cecc" stroke="#b85450" pointer-events="all"/><path d="M 10.15 -1 Q -1 -1 -1 10.15 L -1 24 Q 150 42 301 24 L 301 10.15 Q 301 -1 289.85 -1 Z" fill="url(#mx-gradient-ffffff-0.9-ffffff-0.1-s-0)" stroke="none" pointer-events="all"/></g><g><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 298px; height: 1px; padding-top: 30px; margin-left: 1px;"><div data-drawio-colors="color: #333333; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(51, 51, 51); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">Setup project with CI/CD, tests, linting, basic doumentation, semantic versioning</div></div></div></foreignObject><text x="150" y="34" fill="#333333" font-family=""Helvetica"" font-size="12px" text-anchor="middle">Setup project with CI/CD, tests, linting, basic do...</text></switch></g></g></g></g></g></g><switch><g requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"/><a transform="translate(0,-5)" xlink:href="https://www.drawio.com/doc/faq/svg-export-text-problems" target="_blank"><text text-anchor="middle" font-size="10px" x="50%" y="100%">Text is not SVG - cannot display</text></a></switch></svg>
|
@@ -1,3 +1,3 @@
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
2
2
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
3
|
-
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="
|
3
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="942px" height="62px" viewBox="-0.5 -0.5 942 62"><defs><linearGradient x1="0%" y1="0%" x2="0%" y2="100%" id="mx-gradient-ffffff-0.9-ffffff-0.1-s-0"><stop offset="0%" style="stop-color: rgb(255, 255, 255); stop-opacity: 0.9;"/><stop offset="100%" style="stop-color: rgb(255, 255, 255); stop-opacity: 0.1;"/></linearGradient></defs><g><g data-cell-id="page_root_y30"><g data-cell-id="node_root_y30"><g data-cell-id="y30-2"><g><rect x="0" y="0" width="300" height="60" rx="9" ry="9" fill="#d5e8d4" stroke="#82b366" pointer-events="all"/><path d="M 10.15 -1 Q -1 -1 -1 10.15 L -1 24 Q 150 42 301 24 L 301 10.15 Q 301 -1 289.85 -1 Z" fill="url(#mx-gradient-ffffff-0.9-ffffff-0.1-s-0)" stroke="none" pointer-events="all"/></g><g><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 298px; height: 1px; padding-top: 30px; margin-left: 1px;"><div data-drawio-colors="color: #333333; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(51, 51, 51); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">DSLs as Code sample DSL</div></div></div></foreignObject><text x="150" y="34" fill="#333333" font-family=""Helvetica"" font-size="12px" text-anchor="middle">DSLs as Code sample DSL</text></switch></g></g></g><g data-cell-id="y30-3"><g><rect x="320" y="0" width="300" height="60" rx="9" ry="9" fill="#d5e8d4" stroke="#82b366" pointer-events="all"/><path d="M 330.15 -1 Q 319 -1 319 10.15 L 319 24 Q 470 42 621 24 L 621 10.15 Q 621 -1 609.85 -1 Z" fill="url(#mx-gradient-ffffff-0.9-ffffff-0.1-s-0)" stroke="none" pointer-events="all"/></g><g><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 298px; height: 1px; padding-top: 30px; margin-left: 321px;"><div data-drawio-colors="color: #333333; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(51, 51, 51); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">Automate Base DSL setup</div></div></div></foreignObject><text x="470" y="34" fill="#333333" font-family=""Helvetica"" font-size="12px" text-anchor="middle">Automate Base DSL setup</text></switch></g></g></g><g data-cell-id="y30-4"><g><rect x="640" y="0" width="300" height="60" rx="9" ry="9" fill="#d5e8d4" stroke="#82b366" pointer-events="all"/><path d="M 650.15 -1 Q 639 -1 639 10.15 L 639 24 Q 790 42 941 24 L 941 10.15 Q 941 -1 929.85 -1 Z" fill="url(#mx-gradient-ffffff-0.9-ffffff-0.1-s-0)" stroke="none" pointer-events="all"/></g><g><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 298px; height: 1px; padding-top: 30px; margin-left: 641px;"><div data-drawio-colors="color: #333333; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(51, 51, 51); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">Automate DSL definion/designer for target DSL</div></div></div></foreignObject><text x="790" y="34" fill="#333333" font-family=""Helvetica"" font-size="12px" text-anchor="middle">Automate DSL definion/designer for target DSL</text></switch></g></g></g></g></g></g><switch><g requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"/><a transform="translate(0,-5)" xlink:href="https://www.drawio.com/doc/faq/svg-export-text-problems" target="_blank"><text text-anchor="middle" font-size="10px" x="50%" y="100%">Text is not SVG - cannot display</text></a></switch></svg>
|
@@ -1,3 +1,3 @@
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
2
2
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
3
|
-
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="942px" height="222px" viewBox="-0.5 -0.5 942 222"><defs><linearGradient x1="0%" y1="0%" x2="0%" y2="100%" id="mx-gradient-ffffff-0.9-ffffff-0.1-s-0"><stop offset="0%" style="stop-color: rgb(255, 255, 255); stop-opacity: 0.9;"/><stop offset="100%" style="stop-color: rgb(255, 255, 255); stop-opacity: 0.1;"/></linearGradient></defs><g><g data-cell-id="page_root_QnN"><g data-cell-id="node_root_QnN"><g data-cell-id="QnN-2"><g><rect x="0" y="0" width="300" height="60" rx="9" ry="9" fill="#dae8fc" stroke="#6c8ebf" pointer-events="all"/><path d="M 10.15 -1 Q -1 -1 -1 10.15 L -1 24 Q 150 42 301 24 L 301 10.15 Q 301 -1 289.85 -1 Z" fill="url(#mx-gradient-ffffff-0.9-ffffff-0.1-s-0)" stroke="none" pointer-events="all"/></g><g><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 298px; height: 1px; padding-top: 30px; margin-left: 1px;"><div data-drawio-colors="color: #333333; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(51, 51, 51); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">Add guideline documentation</div></div></div></foreignObject><text x="150" y="34" fill="#333333" font-family=""Helvetica"" font-size="12px" text-anchor="middle">Add guideline documentation</text></switch></g></g></g><g data-cell-id="QnN-3"><g><rect x="320" y="0" width="300" height="60" rx="9" ry="9" fill="#dae8fc" stroke="#6c8ebf" pointer-events="all"/><path d="M 330.15 -1 Q 319 -1 319 10.15 L 319 24 Q 470 42 621 24 L 621 10.15 Q 621 -1 609.85 -1 Z" fill="url(#mx-gradient-ffffff-0.9-ffffff-0.1-s-0)" stroke="none" pointer-events="all"/></g><g><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 298px; height: 1px; padding-top: 30px; margin-left: 321px;"><div data-drawio-colors="color: #333333; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(51, 51, 51); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">Docs as Code sample DSL</div></div></div></foreignObject><text x="470" y="34" fill="#333333" font-family=""Helvetica"" font-size="12px" text-anchor="middle">Docs as Code sample DSL</text></switch></g></g></g><g data-cell-id="QnN-4"><g><rect x="640" y="0" width="300" height="60" rx="9" ry="9" fill="#dae8fc" stroke="#6c8ebf" pointer-events="all"/><path d="M 650.15 -1 Q 639 -1 639 10.15 L 639 24 Q 790 42 941 24 L 941 10.15 Q 941 -1 929.85 -1 Z" fill="url(#mx-gradient-ffffff-0.9-ffffff-0.1-s-0)" stroke="none" pointer-events="all"/></g><g><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 298px; height: 1px; padding-top: 30px; margin-left: 641px;"><div data-drawio-colors="color: #333333; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(51, 51, 51); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">Agent as Code sample DSL</div></div></div></foreignObject><text x="790" y="34" fill="#333333" font-family=""Helvetica"" font-size="12px" text-anchor="middle">Agent as Code sample DSL</text></switch></g></g></g><g data-cell-id="QnN-5"><g><rect x="0" y="80" width="300" height="60" rx="9" ry="9" fill="#dae8fc" stroke="#6c8ebf" pointer-events="all"/><path d="M 10.15 79 Q -1 79 -1 90.15 L -1 104 Q 150 122 301 104 L 301 90.15 Q 301 79 289.85 79 Z" fill="url(#mx-gradient-ffffff-0.9-ffffff-0.1-s-0)" stroke="none" pointer-events="all"/></g><g><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 298px; height: 1px; padding-top: 110px; margin-left: 1px;"><div data-drawio-colors="color: #333333; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(51, 51, 51); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">Poly as Code sample DSL</div></div></div></foreignObject><text x="150" y="114" fill="#333333" font-family=""Helvetica"" font-size="12px" text-anchor="middle">Poly as Code sample DSL</text></switch></g></g></g><g data-cell-id="QnN-6"><g><rect x="320" y="80" width="300" height="60" rx="9" ry="9" fill="#dae8fc" stroke="#6c8ebf" pointer-events="all"/><path d="M 330.15 79 Q 319 79 319 90.15 L 319 104 Q 470 122 621 104 L 621 90.15 Q 621 79 609.85 79 Z" fill="url(#mx-gradient-ffffff-0.9-ffffff-0.1-s-0)" stroke="none" pointer-events="all"/></g><g><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 298px; height: 1px; padding-top: 110px; margin-left: 321px;"><div data-drawio-colors="color: #333333; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(51, 51, 51); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">Voice as Code sample DSL</div></div></div></foreignObject><text x="470" y="114" fill="#333333" font-family=""Helvetica"" font-size="12px" text-anchor="middle">Voice as Code sample DSL</text></switch></g></g></g><g data-cell-id="QnN-7"><g><rect x="640" y="80" width="300" height="60" rx="9" ry="9" fill="#dae8fc" stroke="#6c8ebf" pointer-events="all"/><path d="M 650.15 79 Q 639 79 639 90.15 L 639 104 Q 790 122 941 104 L 941 90.15 Q 941 79 929.85 79 Z" fill="url(#mx-gradient-ffffff-0.9-ffffff-0.1-s-0)" stroke="none" pointer-events="all"/></g><g><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 298px; height: 1px; padding-top: 110px; margin-left: 641px;"><div data-drawio-colors="color: #333333; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(51, 51, 51); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">Data as Code sample DSL</div></div></div></foreignObject><text x="790" y="114" fill="#333333" font-family=""Helvetica"" font-size="12px" text-anchor="middle">Data as Code sample DSL</text></switch></g></g></g><g data-cell-id="QnN-8"><g><rect x="0" y="160" width="300" height="60" rx="9" ry="9" fill="#dae8fc" stroke="#6c8ebf" pointer-events="all"/><path d="M 10.15 159 Q -1 159 -1 170.15 L -1 184 Q 150 202 301 184 L 301 170.15 Q 301 159 289.85 159 Z" fill="url(#mx-gradient-ffffff-0.9-ffffff-0.1-s-0)" stroke="none" pointer-events="all"/></g><g><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 298px; height: 1px; padding-top: 190px; margin-left: 1px;"><div data-drawio-colors="color: #333333; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(51, 51, 51); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">Chart Design as Code sample DSL</div></div></div></foreignObject><text x="150" y="194" fill="#333333" font-family=""Helvetica"" font-size="12px" text-anchor="middle">Chart Design as Code sample DSL</text></switch></g></g></g><g data-cell-id="QnN-9"><g><rect x="320" y="160" width="300" height="60" rx="9" ry="9" fill="#dae8fc" stroke="#6c8ebf" pointer-events="all"/><path d="M 330.15 159 Q 319 159 319 170.15 L 319 184 Q 470 202 621 184 L 621 170.15 Q 621 159 609.85 159 Z" fill="url(#mx-gradient-ffffff-0.9-ffffff-0.1-s-0)" stroke="none" pointer-events="all"/></g><g><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 298px; height: 1px; padding-top: 190px; margin-left: 321px;"><div data-drawio-colors="color: #333333; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(51, 51, 51); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">Video as Code sample DSL</div></div></div></foreignObject><text x="470" y="194" fill="#333333" font-family=""Helvetica"" font-size="12px" text-anchor="middle">Video as Code sample DSL</text></switch></g></g></g><g data-cell-id="QnN-10"><g><rect x="640" y="160" width="300" height="60" rx="9" ry="9" fill="#dae8fc" stroke="#6c8ebf" pointer-events="all"/><path d="M 650.15 159 Q 639 159 639 170.15 L 639 184 Q 790 202 941 184 L 941 170.15 Q 941 159 929.85 159 Z" fill="url(#mx-gradient-ffffff-0.9-ffffff-0.1-s-0)" stroke="none" pointer-events="all"/></g><g><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 298px; height: 1px; padding-top: 190px; margin-left: 641px;"><div data-drawio-colors="color: #333333; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(51, 51, 51); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">Image as Code sample DSL</div></div></div></foreignObject><text x="790" y="194" fill="#333333" font-family=""Helvetica"" font-size="12px" text-anchor="middle">Image as Code sample DSL</text></switch></g></g></g></g></g></g><switch><g requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"/><a transform="translate(0,-5)" xlink:href="https://www.drawio.com/doc/faq/svg-export-text-problems" target="_blank"><text text-anchor="middle" font-size="10px" x="50%" y="100%">Text is not SVG - cannot display</text></a></switch></svg>
|
3
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="942px" height="222px" viewBox="-0.5 -0.5 942 222"><defs><linearGradient x1="0%" y1="0%" x2="0%" y2="100%" id="mx-gradient-ffffff-0.9-ffffff-0.1-s-0"><stop offset="0%" style="stop-color: rgb(255, 255, 255); stop-opacity: 0.9;"/><stop offset="100%" style="stop-color: rgb(255, 255, 255); stop-opacity: 0.1;"/></linearGradient></defs><g><g data-cell-id="page_root_gaX"><g data-cell-id="node_root_gaX"><g data-cell-id="gaX-2"><g><rect x="0" y="0" width="300" height="60" rx="9" ry="9" fill="#dae8fc" stroke="#6c8ebf" pointer-events="all"/><path d="M 10.15 -1 Q -1 -1 -1 10.15 L -1 24 Q 150 42 301 24 L 301 10.15 Q 301 -1 289.85 -1 Z" fill="url(#mx-gradient-ffffff-0.9-ffffff-0.1-s-0)" stroke="none" pointer-events="all"/></g><g><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 298px; height: 1px; padding-top: 30px; margin-left: 1px;"><div data-drawio-colors="color: #333333; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(51, 51, 51); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">Add guideline documentation</div></div></div></foreignObject><text x="150" y="34" fill="#333333" font-family=""Helvetica"" font-size="12px" text-anchor="middle">Add guideline documentation</text></switch></g></g></g><g data-cell-id="gaX-3"><g><rect x="320" y="0" width="300" height="60" rx="9" ry="9" fill="#dae8fc" stroke="#6c8ebf" pointer-events="all"/><path d="M 330.15 -1 Q 319 -1 319 10.15 L 319 24 Q 470 42 621 24 L 621 10.15 Q 621 -1 609.85 -1 Z" fill="url(#mx-gradient-ffffff-0.9-ffffff-0.1-s-0)" stroke="none" pointer-events="all"/></g><g><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 298px; height: 1px; padding-top: 30px; margin-left: 321px;"><div data-drawio-colors="color: #333333; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(51, 51, 51); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">Docs as Code sample DSL</div></div></div></foreignObject><text x="470" y="34" fill="#333333" font-family=""Helvetica"" font-size="12px" text-anchor="middle">Docs as Code sample DSL</text></switch></g></g></g><g data-cell-id="gaX-4"><g><rect x="640" y="0" width="300" height="60" rx="9" ry="9" fill="#dae8fc" stroke="#6c8ebf" pointer-events="all"/><path d="M 650.15 -1 Q 639 -1 639 10.15 L 639 24 Q 790 42 941 24 L 941 10.15 Q 941 -1 929.85 -1 Z" fill="url(#mx-gradient-ffffff-0.9-ffffff-0.1-s-0)" stroke="none" pointer-events="all"/></g><g><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 298px; height: 1px; padding-top: 30px; margin-left: 641px;"><div data-drawio-colors="color: #333333; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(51, 51, 51); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">Agent as Code sample DSL</div></div></div></foreignObject><text x="790" y="34" fill="#333333" font-family=""Helvetica"" font-size="12px" text-anchor="middle">Agent as Code sample DSL</text></switch></g></g></g><g data-cell-id="gaX-5"><g><rect x="0" y="80" width="300" height="60" rx="9" ry="9" fill="#dae8fc" stroke="#6c8ebf" pointer-events="all"/><path d="M 10.15 79 Q -1 79 -1 90.15 L -1 104 Q 150 122 301 104 L 301 90.15 Q 301 79 289.85 79 Z" fill="url(#mx-gradient-ffffff-0.9-ffffff-0.1-s-0)" stroke="none" pointer-events="all"/></g><g><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 298px; height: 1px; padding-top: 110px; margin-left: 1px;"><div data-drawio-colors="color: #333333; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(51, 51, 51); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">Poly as Code sample DSL</div></div></div></foreignObject><text x="150" y="114" fill="#333333" font-family=""Helvetica"" font-size="12px" text-anchor="middle">Poly as Code sample DSL</text></switch></g></g></g><g data-cell-id="gaX-6"><g><rect x="320" y="80" width="300" height="60" rx="9" ry="9" fill="#dae8fc" stroke="#6c8ebf" pointer-events="all"/><path d="M 330.15 79 Q 319 79 319 90.15 L 319 104 Q 470 122 621 104 L 621 90.15 Q 621 79 609.85 79 Z" fill="url(#mx-gradient-ffffff-0.9-ffffff-0.1-s-0)" stroke="none" pointer-events="all"/></g><g><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 298px; height: 1px; padding-top: 110px; margin-left: 321px;"><div data-drawio-colors="color: #333333; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(51, 51, 51); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">Voice as Code sample DSL</div></div></div></foreignObject><text x="470" y="114" fill="#333333" font-family=""Helvetica"" font-size="12px" text-anchor="middle">Voice as Code sample DSL</text></switch></g></g></g><g data-cell-id="gaX-7"><g><rect x="640" y="80" width="300" height="60" rx="9" ry="9" fill="#dae8fc" stroke="#6c8ebf" pointer-events="all"/><path d="M 650.15 79 Q 639 79 639 90.15 L 639 104 Q 790 122 941 104 L 941 90.15 Q 941 79 929.85 79 Z" fill="url(#mx-gradient-ffffff-0.9-ffffff-0.1-s-0)" stroke="none" pointer-events="all"/></g><g><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 298px; height: 1px; padding-top: 110px; margin-left: 641px;"><div data-drawio-colors="color: #333333; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(51, 51, 51); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">Data as Code sample DSL</div></div></div></foreignObject><text x="790" y="114" fill="#333333" font-family=""Helvetica"" font-size="12px" text-anchor="middle">Data as Code sample DSL</text></switch></g></g></g><g data-cell-id="gaX-8"><g><rect x="0" y="160" width="300" height="60" rx="9" ry="9" fill="#dae8fc" stroke="#6c8ebf" pointer-events="all"/><path d="M 10.15 159 Q -1 159 -1 170.15 L -1 184 Q 150 202 301 184 L 301 170.15 Q 301 159 289.85 159 Z" fill="url(#mx-gradient-ffffff-0.9-ffffff-0.1-s-0)" stroke="none" pointer-events="all"/></g><g><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 298px; height: 1px; padding-top: 190px; margin-left: 1px;"><div data-drawio-colors="color: #333333; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(51, 51, 51); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">Chart Design as Code sample DSL</div></div></div></foreignObject><text x="150" y="194" fill="#333333" font-family=""Helvetica"" font-size="12px" text-anchor="middle">Chart Design as Code sample DSL</text></switch></g></g></g><g data-cell-id="gaX-9"><g><rect x="320" y="160" width="300" height="60" rx="9" ry="9" fill="#dae8fc" stroke="#6c8ebf" pointer-events="all"/><path d="M 330.15 159 Q 319 159 319 170.15 L 319 184 Q 470 202 621 184 L 621 170.15 Q 621 159 609.85 159 Z" fill="url(#mx-gradient-ffffff-0.9-ffffff-0.1-s-0)" stroke="none" pointer-events="all"/></g><g><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 298px; height: 1px; padding-top: 190px; margin-left: 321px;"><div data-drawio-colors="color: #333333; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(51, 51, 51); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">Video as Code sample DSL</div></div></div></foreignObject><text x="470" y="194" fill="#333333" font-family=""Helvetica"" font-size="12px" text-anchor="middle">Video as Code sample DSL</text></switch></g></g></g><g data-cell-id="gaX-10"><g><rect x="640" y="160" width="300" height="60" rx="9" ry="9" fill="#dae8fc" stroke="#6c8ebf" pointer-events="all"/><path d="M 650.15 159 Q 639 159 639 170.15 L 639 184 Q 790 202 941 184 L 941 170.15 Q 941 159 929.85 159 Z" fill="url(#mx-gradient-ffffff-0.9-ffffff-0.1-s-0)" stroke="none" pointer-events="all"/></g><g><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 298px; height: 1px; padding-top: 190px; margin-left: 641px;"><div data-drawio-colors="color: #333333; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(51, 51, 51); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">Image as Code sample DSL</div></div></div></foreignObject><text x="790" y="194" fill="#333333" font-family=""Helvetica"" font-size="12px" text-anchor="middle">Image as Code sample DSL</text></switch></g></g></g></g></g></g><switch><g requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"/><a transform="translate(0,-5)" xlink:href="https://www.drawio.com/doc/faq/svg-export-text-problems" target="_blank"><text text-anchor="middle" font-size="10px" x="50%" y="100%">Text is not SVG - cannot display</text></a></switch></svg>
|
@@ -0,0 +1,357 @@
|
|
1
|
+
# Brief for creating the Parser, Tokenizer and Parsing our first DSL
|
2
|
+
|
3
|
+
# 1. Parsing Libraries in Ruby
|
4
|
+
|
5
|
+
Here are three Ruby parsing libraries with their pros and cons:
|
6
|
+
|
7
|
+
### Parslet
|
8
|
+
**Pros:**
|
9
|
+
- Pure Ruby library for constructing parsers using parsing expression grammars (PEG).
|
10
|
+
- Intuitive and readable grammar definitions embedded in Ruby code.
|
11
|
+
- Actively maintained with compatibility for modern Ruby versions.
|
12
|
+
|
13
|
+
**Cons:**
|
14
|
+
- Can be slower for large inputs due to backtracking.
|
15
|
+
- Verbose grammars can become complex for intricate DSLs.
|
16
|
+
|
17
|
+
### Racc
|
18
|
+
**Pros:**
|
19
|
+
- LALR(1) parser generator that comes standard with Ruby.
|
20
|
+
- Generates fast parsers suitable for complex grammars.
|
21
|
+
- Actively maintained as part of the Ruby language.
|
22
|
+
|
23
|
+
**Cons:**
|
24
|
+
- Steeper learning curve with Yacc-like syntax.
|
25
|
+
- Less intuitive for those unfamiliar with parser generators.
|
26
|
+
|
27
|
+
### Treetop
|
28
|
+
**Pros:**
|
29
|
+
- Provides a powerful parsing DSL and supports PEG.
|
30
|
+
- Clean syntax with grammars defined in separate files.
|
31
|
+
- Memoization for improved parsing performance.
|
32
|
+
|
33
|
+
**Cons:**
|
34
|
+
- Less active development; may not be updated for recent Ruby versions.
|
35
|
+
- Potential compatibility issues with newer Ruby releases.
|
36
|
+
|
37
|
+
**Note:** Based on maintenance and compatibility, Parslet and Racc are more suitable for your needs.
|
38
|
+
|
39
|
+
---
|
40
|
+
|
41
|
+
# 2. Converting the DSL Definition into JSON
|
42
|
+
|
43
|
+
Transforming your DSL definition into JSON will facilitate parsing and validation. Here's how your DSL definition can be represented in JSON:
|
44
|
+
|
45
|
+
```json
|
46
|
+
{
|
47
|
+
"definition": {
|
48
|
+
"name": "workflow",
|
49
|
+
"params": [
|
50
|
+
{
|
51
|
+
"name": "name",
|
52
|
+
"type": "positional"
|
53
|
+
}
|
54
|
+
],
|
55
|
+
"nodes": [
|
56
|
+
{
|
57
|
+
"name": "description",
|
58
|
+
"params": [
|
59
|
+
{
|
60
|
+
"name": "description",
|
61
|
+
"type": "positional"
|
62
|
+
}
|
63
|
+
]
|
64
|
+
},
|
65
|
+
{
|
66
|
+
"name": "settings",
|
67
|
+
"nodes": [
|
68
|
+
{
|
69
|
+
"name": "setting",
|
70
|
+
"repeat": true,
|
71
|
+
"params": [
|
72
|
+
{
|
73
|
+
"name": "key",
|
74
|
+
"type": "declarative"
|
75
|
+
},
|
76
|
+
{
|
77
|
+
"name": "value",
|
78
|
+
"type": "positional"
|
79
|
+
}
|
80
|
+
]
|
81
|
+
}
|
82
|
+
]
|
83
|
+
},
|
84
|
+
{
|
85
|
+
"name": "prompts",
|
86
|
+
"nodes": [
|
87
|
+
{
|
88
|
+
"name": "prompt",
|
89
|
+
"repeat": true,
|
90
|
+
"params": [
|
91
|
+
{
|
92
|
+
"name": "key",
|
93
|
+
"type": "positional"
|
94
|
+
},
|
95
|
+
{
|
96
|
+
"name": "content",
|
97
|
+
"type": "named",
|
98
|
+
"default": ""
|
99
|
+
}
|
100
|
+
]
|
101
|
+
}
|
102
|
+
]
|
103
|
+
},
|
104
|
+
{
|
105
|
+
"name": "section",
|
106
|
+
"repeat": true,
|
107
|
+
"params": [
|
108
|
+
{
|
109
|
+
"name": "name",
|
110
|
+
"type": "positional"
|
111
|
+
}
|
112
|
+
],
|
113
|
+
"nodes": [
|
114
|
+
{
|
115
|
+
"name": "step",
|
116
|
+
"repeat": true,
|
117
|
+
"params": [
|
118
|
+
{
|
119
|
+
"name": "key",
|
120
|
+
"type": "positional"
|
121
|
+
}
|
122
|
+
],
|
123
|
+
"nodes": [
|
124
|
+
{
|
125
|
+
"name": "input",
|
126
|
+
"repeat": true,
|
127
|
+
"params": [
|
128
|
+
{
|
129
|
+
"name": "key",
|
130
|
+
"type": "positional"
|
131
|
+
}
|
132
|
+
]
|
133
|
+
},
|
134
|
+
{
|
135
|
+
"name": "prompt",
|
136
|
+
"params": [
|
137
|
+
{
|
138
|
+
"name": "key",
|
139
|
+
"type": "positional"
|
140
|
+
}
|
141
|
+
]
|
142
|
+
},
|
143
|
+
{
|
144
|
+
"name": "output",
|
145
|
+
"repeat": true,
|
146
|
+
"params": [
|
147
|
+
{
|
148
|
+
"name": "key",
|
149
|
+
"type": "positional"
|
150
|
+
}
|
151
|
+
]
|
152
|
+
}
|
153
|
+
]
|
154
|
+
}
|
155
|
+
]
|
156
|
+
},
|
157
|
+
{
|
158
|
+
"name": "actions",
|
159
|
+
"nodes": [
|
160
|
+
{
|
161
|
+
"name": "save",
|
162
|
+
"params": []
|
163
|
+
},
|
164
|
+
{
|
165
|
+
"name": "save_json",
|
166
|
+
"params": [
|
167
|
+
{
|
168
|
+
"name": "path",
|
169
|
+
"type": "positional"
|
170
|
+
}
|
171
|
+
]
|
172
|
+
}
|
173
|
+
]
|
174
|
+
}
|
175
|
+
]
|
176
|
+
}
|
177
|
+
}
|
178
|
+
```
|
179
|
+
|
180
|
+
# 3. Writing a Parser in Raw Ruby
|
181
|
+
|
182
|
+
Given the simplicity and hierarchical nature of your DSL, you can write a custom parser in Ruby without external libraries. Below is an outline of how to approach this:
|
183
|
+
|
184
|
+
### Step 1: Tokenization
|
185
|
+
- Create a tokenizer that reads the DSL code and breaks it down into tokens (keywords, symbols, identifiers, strings, etc.).
|
186
|
+
|
187
|
+
```ruby
|
188
|
+
class Tokenizer
|
189
|
+
attr_reader :tokens
|
190
|
+
|
191
|
+
def initialize(code)
|
192
|
+
@code = code
|
193
|
+
@tokens = []
|
194
|
+
end
|
195
|
+
|
196
|
+
def tokenize
|
197
|
+
# Implement logic to convert code into tokens
|
198
|
+
# Handle strings, symbols, keywords, and delimiters
|
199
|
+
end
|
200
|
+
end
|
201
|
+
```
|
202
|
+
|
203
|
+
### Step 2: Parsing
|
204
|
+
- Use recursive descent parsing to process tokens according to the rules defined in your JSON schema.
|
205
|
+
|
206
|
+
```ruby
|
207
|
+
class Parser
|
208
|
+
def initialize(tokens, schema)
|
209
|
+
@tokens = tokens
|
210
|
+
@schema = schema
|
211
|
+
@position = 0
|
212
|
+
end
|
213
|
+
|
214
|
+
def parse
|
215
|
+
parse_node(@schema['definition'])
|
216
|
+
end
|
217
|
+
|
218
|
+
private
|
219
|
+
|
220
|
+
def parse_node(node_schema)
|
221
|
+
node = { 'name' => node_schema['name'], 'params' => {}, 'children' => [] }
|
222
|
+
|
223
|
+
# Parse parameters
|
224
|
+
node['params'] = parse_params(node_schema['params'])
|
225
|
+
|
226
|
+
# If node has child nodes
|
227
|
+
if node_schema['nodes']
|
228
|
+
# Expect 'do'
|
229
|
+
expect('do')
|
230
|
+
|
231
|
+
# Parse child nodes
|
232
|
+
while peek != 'end'
|
233
|
+
child_node_schema = match_node_schema(node_schema['nodes'])
|
234
|
+
node['children'] << parse_node(child_node_schema)
|
235
|
+
end
|
236
|
+
|
237
|
+
expect('end')
|
238
|
+
end
|
239
|
+
|
240
|
+
node
|
241
|
+
end
|
242
|
+
|
243
|
+
def parse_params(params_schema)
|
244
|
+
params = {}
|
245
|
+
params_schema.each do |param_schema|
|
246
|
+
# Extract parameter based on its type
|
247
|
+
params[param_schema['name']] = extract_param(param_schema)
|
248
|
+
end
|
249
|
+
params
|
250
|
+
end
|
251
|
+
|
252
|
+
def extract_param(param_schema)
|
253
|
+
# Implement extraction logic based on param_schema['type']
|
254
|
+
end
|
255
|
+
|
256
|
+
def expect(expected_token)
|
257
|
+
actual_token = next_token
|
258
|
+
if actual_token != expected_token
|
259
|
+
raise "Expected '#{expected_token}', got '#{actual_token}'"
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
def next_token
|
264
|
+
token = @tokens[@position]
|
265
|
+
@position += 1
|
266
|
+
token
|
267
|
+
end
|
268
|
+
|
269
|
+
def peek
|
270
|
+
@tokens[@position]
|
271
|
+
end
|
272
|
+
|
273
|
+
def match_node_schema(nodes_schema)
|
274
|
+
current_token = peek
|
275
|
+
nodes_schema.find { |ns| ns['name'] == current_token } || raise("Unknown node '#{current_token}'")
|
276
|
+
end
|
277
|
+
end
|
278
|
+
```
|
279
|
+
|
280
|
+
### Step 3: Building the Abstract Syntax Tree (AST)
|
281
|
+
- As you parse, construct an AST that captures both the structural elements and their associated data.
|
282
|
+
|
283
|
+
#### Example Usage:
|
284
|
+
|
285
|
+
```ruby
|
286
|
+
# Read DSL code from file
|
287
|
+
dsl_code = File.read('workflow_dsl.rb')
|
288
|
+
|
289
|
+
# Tokenize the DSL code
|
290
|
+
tokenizer = Tokenizer.new(dsl_code)
|
291
|
+
tokenizer.tokenize
|
292
|
+
|
293
|
+
# Parse tokens into an AST
|
294
|
+
parser = Parser.new(tokenizer.tokens, schema)
|
295
|
+
ast = parser.parse
|
296
|
+
|
297
|
+
# Output the AST
|
298
|
+
puts ast.inspect
|
299
|
+
```
|
300
|
+
|
301
|
+
### Considerations:
|
302
|
+
|
303
|
+
#### Parsing Parameters:
|
304
|
+
- Implement the `parse_params` method to handle different parameter types:
|
305
|
+
- **Positional Parameters:** Split `params_str` by commas or spaces, and assign values in order.
|
306
|
+
- **Declarative Parameters:** Use the node name as the parameter value.
|
307
|
+
- **Named Parameters:** Look for `key: value` pairs.
|
308
|
+
|
309
|
+
#### Handling Repetition:
|
310
|
+
- For nodes with `repeat: true`, allow multiple instances by continuing to parse matching nodes until none are found.
|
311
|
+
|
312
|
+
### Advantages:
|
313
|
+
- **Simplicity:** Direct control over parsing logic tailored to your DSL.
|
314
|
+
- **No Dependencies:** Eliminates issues with outdated libraries.
|
315
|
+
- **Customizable:** Easy to modify as your DSL evolves.
|
316
|
+
|
317
|
+
### Challenges:
|
318
|
+
- **Complexity Management:** As your DSL grows, the parser logic may become more complex.
|
319
|
+
- **Testing:** Thorough testing is needed to ensure reliability.
|
320
|
+
- **Performance:** May need optimization for large DSL files.
|
321
|
+
|
322
|
+
---
|
323
|
+
|
324
|
+
# 5. Additional Considerations
|
325
|
+
|
326
|
+
While your immediate focus is on building the engine, keep in mind future integration with tools like IDEs:
|
327
|
+
|
328
|
+
- **Abstract Syntax Tree (AST):** A well-structured AST can facilitate features like syntax highlighting and code completion.
|
329
|
+
- **Language Server Protocol (LSP):** If you decide to provide IDE support, structuring your parser to output data compatible with LSP can be beneficial.
|
330
|
+
- **Extensibility:** Designing your parser and data structures with future enhancements in mind can save time later.
|
331
|
+
|
332
|
+
---
|
333
|
+
|
334
|
+
# 6. Conclusion
|
335
|
+
|
336
|
+
Creating a custom parser in Ruby without external libraries is feasible for your DSL, especially given its hierarchical and relatively simple structure. This approach offers:
|
337
|
+
|
338
|
+
- **Control and Flexibility:** Tailor the parser to your specific needs without external constraints.
|
339
|
+
- **Understanding:** Deepens your knowledge of parsing techniques and the inner workings of your DSL.
|
340
|
+
- **Maintainability:** Avoids dependency issues associated with outdated gems.
|
341
|
+
|
342
|
+
### Next Steps:
|
343
|
+
1. **Implement the Parser:** Start coding the parser using the outlined approaches.
|
344
|
+
2. **Test with Examples:** Use your existing DSL examples to validate the parser's functionality.
|
345
|
+
3. **Iterate:** Refine the parser based on testing, adding error handling and edge case management as needed.
|
346
|
+
- **Parameter Types:** Implement logic for different parameter types (positional, declarative, named, etc.).
|
347
|
+
- **Repeating Nodes:** Handle nodes with `repeat: true` by looping until no more matching nodes are found.
|
348
|
+
- **Error Handling:** Include meaningful error messages for unexpected tokens or structure violations.
|
349
|
+
- **Whitespace and Comments:** Strip out or ignore to simplify tokenization.
|
350
|
+
|
351
|
+
---
|
352
|
+
|
353
|
+
# 4. Writing the Parser Without External Libraries
|
354
|
+
|
355
|
+
You can implement the parser using Ruby's built-in capabilities, focusing on string manipulation and control structures.
|
356
|
+
|
357
|
+
### Simplified Parser Example:
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Klue
|
4
|
+
module Langcraft
|
5
|
+
# Parser class
|
6
|
+
class Parser
|
7
|
+
def initialize(tokens, schema)
|
8
|
+
@tokens = tokens
|
9
|
+
@schema = schema
|
10
|
+
@position = 0
|
11
|
+
end
|
12
|
+
|
13
|
+
def parse
|
14
|
+
parse_node(@schema['definition'])
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def parse_node(node_schema)
|
20
|
+
node = { 'name' => node_schema['name'], 'params' => {}, 'children' => [] }
|
21
|
+
|
22
|
+
# Parse parameters
|
23
|
+
node['params'] = parse_params(node_schema['params'])
|
24
|
+
|
25
|
+
# If node has child nodes
|
26
|
+
if node_schema['nodes']
|
27
|
+
# Expect 'do'
|
28
|
+
expect('do')
|
29
|
+
|
30
|
+
# Parse child nodes
|
31
|
+
while peek != 'end'
|
32
|
+
child_node_schema = match_node_schema(node_schema['nodes'])
|
33
|
+
node['children'] << parse_node(child_node_schema)
|
34
|
+
end
|
35
|
+
|
36
|
+
expect('end')
|
37
|
+
end
|
38
|
+
|
39
|
+
node
|
40
|
+
end
|
41
|
+
|
42
|
+
def parse_params(params_schema)
|
43
|
+
params = {}
|
44
|
+
params_schema.each do |param_schema|
|
45
|
+
# Extract parameter based on its type
|
46
|
+
params[param_schema['name']] = extract_param(param_schema)
|
47
|
+
end
|
48
|
+
params
|
49
|
+
end
|
50
|
+
|
51
|
+
def extract_param(param_schema)
|
52
|
+
# Implement extraction logic based on param_schema['type']
|
53
|
+
end
|
54
|
+
|
55
|
+
def expect(expected_token)
|
56
|
+
actual_token = next_token
|
57
|
+
return unless actual_token != expected_token
|
58
|
+
|
59
|
+
raise "Expected '#{expected_token}', got '#{actual_token}'"
|
60
|
+
end
|
61
|
+
|
62
|
+
def next_token
|
63
|
+
token = @tokens[@position]
|
64
|
+
@position += 1
|
65
|
+
token
|
66
|
+
end
|
67
|
+
|
68
|
+
def peek
|
69
|
+
@tokens[@position]
|
70
|
+
end
|
71
|
+
|
72
|
+
def match_node_schema(nodes_schema)
|
73
|
+
current_token = peek
|
74
|
+
nodes_schema.find { |ns| ns['name'] == current_token } || raise("Unknown node '#{current_token}'")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|