-
-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added debugging and tests, added value types, fixed bugs
fixed package-lock fixed prettier and eslint errors
- Loading branch information
1 parent
44283e8
commit bd37747
Showing
53 changed files
with
6,272 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extensions": ["ts"], | ||
"node-option": ["loader=ts-node/esm"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 42 additions & 35 deletions
77
src/plugins/Codemirror/KlipperCfgLang/parser/klipperCfg.grammar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,73 @@ | ||
@precedence { str @cut } | ||
@top Program { (Import | ConfigBlock )+ } | ||
|
||
@top Program { (Import | ConfigBlock)+ } | ||
@skip { AutoGenerated (newline | eof) | space | blankLine | Comment newline? } | ||
|
||
@skip { Comment newline? | AutoGenerated newline | space | blankLine } | ||
|
||
valueBlock<content> { indent (content newline | valueBlock<content>)+ (dedent | eof) } | ||
valueBlock<content> { indent (content (newline | eof) | valueBlock<content>)+ (dedent | eof) } | ||
sep<content, seperator> { content (seperator content)+ } | ||
|
||
|
||
Import { "[" ImportKeyword FilePath "]" (newline | eof) } | ||
ConfigBlock {"[" BlockType Identifier* "]" ( newline Body? | newline? eof ) } | ||
|
||
Import { "[" ImportKeyword FilePath "]" newline } | ||
ConfigBlock {"[" BlockType Identifier? "]" newline Body? } | ||
|
||
Body { Option+ } | ||
Option { Parameter ":" Value | GcodeKeyword ":" Jinja2 } | ||
Body { Option+ eof? } | ||
Option { Parameter ":" Value | GcodeKeyword Jinja2 } | ||
|
||
Value { value (newline | eof) | newline valueBlock<value> } | ||
Jinja2 { jinja2 (newline | eof) | newline valueBlock<jinja2> } | ||
Value { value (newline | eof) | value? newline valueBlock<value> } | ||
Jinja2 { jinja2 (newline | eof) | jinja2? newline valueBlock<jinja2> } | ||
|
||
value { Pin | pins | VirtualPin | VirtualPin | Cords | Number | String | Boolean | Path | FilePath } | ||
pins { sep<Pin, ","> } | ||
VirtualPin { string ":" string } | ||
value { Pin | pins | VirtualPin | Cords | Number | String | Boolean | Path | FilePath | Resolution | Ratio | Ipv4 | Ipv6 } | ||
pins { sep<(Pin | VirtualPin), ","> } | ||
Cords { sep<number, ","> } | ||
Number { number } | ||
String { string } | ||
Path { ("/"|"~/")? !str string ("/" string)* } | ||
FilePath { Path "." string} | ||
|
||
|
||
|
||
@context trackIndent from "./tokens.js" | ||
@external tokens indentation from "./tokens.js" { indent, dedent } | ||
@external tokens newlines from "./tokens.js" { newline, blankLine, eof } | ||
|
||
@tokens { | ||
extAscii { $[a-zA-Z0-9_\-.] } | ||
unixPath { ![/<>|:&{}\t\f #;\[\]\n\r] } | ||
|
||
ImportKeyword{ "include" } | ||
GcodeKeyword{ $[a-zA-Z0-9_.\-]* "gcode" } | ||
BlockType { $[a-zA-Z0-9_]+ } | ||
Identifier { $[a-zA-Z0-9_.\-]+ } | ||
Parameter { $[a-zA-Z0-9_]+ } | ||
|
||
string { ($[ a-zA-Z0-9_\-!:]+ | "//") } | ||
jinja2 { $[ \ta-zA-Z0-9_.\-"'{}%=]+ } | ||
GcodeKeyword{ extAscii* "gcode:" } | ||
BlockType { extAscii+ } | ||
Identifier { extAscii+ } | ||
Parameter { extAscii+ } | ||
Path { ("/"|"~/") unixPath+ ("/" unixPath+)* } | ||
FilePath { (Path | unixPath+) "." unixPath+ } | ||
Resolution { $[0-9]+ "x" $[0-9]+ } | ||
Ratio { $[0-9]+ ":" $[0-9]+ } | ||
Ipv4 { $[0-9]+ "." $[0-9]+ "." $[0-9]+ "." $[0-9]+ ((":"|"/") $[0-9]+)? } | ||
hex { $[0-9a-fA-F] } | ||
Ipv6 { (("::" (hex+ ":")* hex+) | ||
| (hex+ (":" hex+)* "::") | ||
| ((hex+ ":")+ (":" hex+)+) | ||
| ((hex+ ":" hex+ ":" hex+ ":" hex+ ":" hex+ ":" hex+))) | ||
("/" $[0-9]+)?} | ||
|
||
String { ![#;\n\r]+ } | ||
jinja2 { ![#;\n\r]+ } | ||
number { "-"? $[0-9]+ ("." $[0-9]*)? } | ||
Boolean { "True" | "False" } | ||
Pin { ("^" | "~")? "!"? "P" $[A-Z] $[0-9]+ } | ||
Boolean { "True" | "False" | "true" | "false" } | ||
Pin { ("^" | "~")? "!"? "P" $[A-Z]? $[0-9.]+ } | ||
VirtualPin { ("^" | "~")? "!"? extAscii+ ":" extAscii+ } | ||
|
||
AutoGenerated { "#*#" ![\n\r]* } | ||
Comment { "#" ![\n\r]* } | ||
Comment { ("#"|";") ![\n\r]* } | ||
|
||
space { $[ \t\f]+ } | ||
|
||
@precedence { space, jinja2, string } | ||
@precedence { AutoGenerated, Comment } | ||
@precedence { number, Pin, Boolean, ImportKeyword, string, "/" } | ||
@precedence { ImportKeyword, BlockType } | ||
@precedence { GcodeKeyword, Parameter } | ||
@precedence { space, jinja2, String } // because spaces are allowed in string/jinja2 | ||
@precedence { AutoGenerated, Comment } // AutoGenerated also starts with a # | ||
@precedence { Resolution, Ipv4, Ipv6, Ratio, number, Pin, VirtualPin, Boolean, ImportKeyword, FilePath, Path, String } | ||
@precedence { ImportKeyword, BlockType }// because the ImportKeyword can be canerated with extAscii | ||
@precedence { GcodeKeyword, Parameter } // because the GcodeKeyword can be canerated with extAscii | ||
} | ||
|
||
@external propSource klipperConfigHighlighting from "./highlight" | ||
|
||
@detectDelim | ||
|
||
// to generate the parser run: | ||
// npx @lezer/generator klipperCfg.grammar -o klipperCfgParser.js | ||
// npx lezer-generator klipperCfg.grammar -o klipperCfgParser.js |
20 changes: 0 additions & 20 deletions
20
src/plugins/Codemirror/KlipperCfgLang/parser/klipperCfgParser.js
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
src/plugins/Codemirror/KlipperCfgLang/parser/klipperCfgParser.terms.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { nodeResolve } from '@rollup/plugin-node-resolve' | ||
|
||
export default { | ||
input: 'src/plugins/Codemirror/KlipperCfgLang/parser/klipperCfgParser.js', | ||
output: [ | ||
{ | ||
format: 'cjs', | ||
file: 'src/plugins/Codemirror/KlipperCfgLang/dist/klipperCfgParser.cjs', | ||
}, | ||
{ | ||
format: 'es', | ||
file: 'src/plugins/Codemirror/KlipperCfgLang/dist/klipperCfgParser.es.js', | ||
}, | ||
], | ||
external(id) { | ||
return !/^[\.\/]/.test(id) | ||
}, | ||
plugins: [nodeResolve()], | ||
} |
Oops, something went wrong.