Skip to content

Commit

Permalink
feat: parse parameters with special characters
Browse files Browse the repository at this point in the history
  • Loading branch information
seasick committed Jan 21, 2024
1 parent 75e696f commit a59793f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/openSCAD/parseParameter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function parseParameters(script: string): Parameter[] {
script = script.split(/^(module |function )/m)[0];

const parameters: Record<string, Parameter> = {};
const parameterRegex = /^(\w+)\s*=\s*([^;]+)/gm; // TODO: Use AST parser instead of regex
const parameterRegex = /^([a-z0-9A-Z_\$]+)\s*=\s*([^;]+)/gm; // TODO: Use AST parser instead of regex
const groupRegex = /^\/\*\s*\[([^\]]+)\]\s*\*\//gm;

const groupSections: { id: string; group: string; code: string }[] = [];
Expand Down
33 changes: 33 additions & 0 deletions tests/__snapshots__/openSCADparseParameters.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,39 @@ exports[`testing parameter parsing of openscad scripts testing slider.scad: slid
]
`;

exports[`testing parameter parsing of openscad scripts testing specialChars.scad: specialChars.scad 1`] = `
[
{
"description": undefined,
"group": "Settings",
"name": "$fn",
"type": "number",
"value": 200,
},
{
"description": undefined,
"group": "Settings",
"name": "width",
"type": "number",
"value": 30,
},
{
"description": undefined,
"group": "Settings",
"name": "length",
"type": "number",
"value": 50,
},
{
"description": undefined,
"group": "Hidden",
"name": "height",
"type": "number",
"value": 10,
},
]
`;

exports[`testing parameter parsing of openscad scripts testing specialVector.scad: specialVector.scad 1`] = `
[
{
Expand Down
13 changes: 13 additions & 0 deletions tests/fixtures/openSCAD/specialChars.scad
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// test

/* [Settings] */

$fn = 200;
width = 30;
length = 50;

/* [Hidden] */

height = 10;

cube([width,length,height]);

0 comments on commit a59793f

Please sign in to comment.