From 41e9889fea345f0855fada5fa8e4205ff9d3098f Mon Sep 17 00:00:00 2001 From: yannick Date: Tue, 19 Dec 2023 16:30:00 +0100 Subject: [PATCH 1/2] fix: bug when float starts with a dot --- internal/formatter/testdata/float_start_with_dot_bug.scad | 1 + .../formatter/testdata/float_start_with_dot_bug.scad.expected | 1 + internal/parser/OpenSCAD.g4 | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 internal/formatter/testdata/float_start_with_dot_bug.scad create mode 100644 internal/formatter/testdata/float_start_with_dot_bug.scad.expected diff --git a/internal/formatter/testdata/float_start_with_dot_bug.scad b/internal/formatter/testdata/float_start_with_dot_bug.scad new file mode 100644 index 0000000..68c8301 --- /dev/null +++ b/internal/formatter/testdata/float_start_with_dot_bug.scad @@ -0,0 +1 @@ +a=.1; diff --git a/internal/formatter/testdata/float_start_with_dot_bug.scad.expected b/internal/formatter/testdata/float_start_with_dot_bug.scad.expected new file mode 100644 index 0000000..8c3a647 --- /dev/null +++ b/internal/formatter/testdata/float_start_with_dot_bug.scad.expected @@ -0,0 +1 @@ +a = .1; diff --git a/internal/parser/OpenSCAD.g4 b/internal/parser/OpenSCAD.g4 index f9e68c1..75ef84d 100644 --- a/internal/parser/OpenSCAD.g4 +++ b/internal/parser/OpenSCAD.g4 @@ -544,7 +544,7 @@ NUMBER FLOAT : - DIGIT+ '.' DIGIT+ + DIGIT* '.' DIGIT+ ; INTEGER From c3da5165318c2f380b17ace30d37d3d2a3af9fb8 Mon Sep 17 00:00:00 2001 From: yannick Date: Tue, 19 Dec 2023 16:43:58 +0100 Subject: [PATCH 2/2] docs: add exemple of command that format all files recursively --- README.md | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 98d17cd..a723c9a 100644 --- a/README.md +++ b/README.md @@ -20,16 +20,33 @@ SCADFormat is a command line tool. SCADFormat can be run directly on a file by specifying the filename on the command line: - $ scadformat my-source.scad - INFO formatting file my-source.scad - +```bash +scadformat my-source.scad +``` +``` +INFO formatting file my-source.scad +``` In this mode, SCADFormat will overwrite the existing code with the formatted version. Note that SCADFormat creates a backup of the original file (with a .scadbak extension) before overwriting it. ### Read from stdin / write to stdout SCADFormat can also read from stdin and write to stdout as follows: - $ scadformat my-source-formatted.scad +```bash +scadformat my-source-formatted.scad +``` + +### Format all .scad recursively + +Format all .scad files in the directory "." recursively +```bash +find . -type f -name "*.scad" -exec scadformat "{}" \; +``` + +If you are ok with the result, you can delete all backup files (.scadbak) +```bash +find $directory -type f -name "*.scadbak" -exec rm "{}" \; +``` ## Building @@ -59,7 +76,6 @@ ANTLR Parser Generator Version 4.13.1 ... ``` - ### Checkout And Build Once ANTLR and Go are installed, the SCADFormat can be built as follows: