Skip to content

Commit

Permalink
bf
Browse files Browse the repository at this point in the history
  • Loading branch information
vdelachaux committed Nov 20, 2024
1 parent d08577e commit d257f8e
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 55 deletions.
Binary file modified Build/4DPop-Macros.zip
Binary file not shown.
Binary file modified Build/Components/4DPop Macros.4dbase/Contents/4DPop Macros.4DZ
Binary file not shown.
4 changes: 2 additions & 2 deletions Build/Components/4DPop Macros.4dbase/Contents/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<key>CFBundleName</key>
<string>4DPop Macros</string>
<key>CFBundleVersion</key>
<string>293</string>
<string>295</string>
<key>NSHumanReadableCopyright</key>
<string>©vdl 2009-2024</string>
<key>CFBundleGetInfoString</key>
<string>20R8</string>
<key>CFBundleLongVersionString</key>
<string>20R8 (292)</string>
<string>20R8 (294)</string>
<key>CFBundleShortVersionString</key>
<string>20R8</string>
<key>CFBundleDisplayName</key>
Expand Down
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<key>CFBundleName</key>
<string>4DPop Macros</string>
<key>CFBundleVersion</key>
<string>293</string>
<string>295</string>
<key>NSHumanReadableCopyright</key>
<string>©vdl 2009-2024</string>
<key>CFBundleGetInfoString</key>
<string>20R8</string>
<key>CFBundleLongVersionString</key>
<string>20R8 (292)</string>
<string>20R8 (294)</string>
<key>CFBundleShortVersionString</key>
<string>20R8</string>
<key>CFBundleDisplayName</key>
Expand Down
60 changes: 50 additions & 10 deletions Project/Sources/Classes/beautifier.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Class constructor()
This:C1470._patterns.closure:="(?<!"+kCommentMark+")(?:"+This:C1470.closures.join("|")+")\\b"

// MARK: Localised closures
$t:="(?mi-s)(?<! // )(?<!//\\s)(?:/\\*.*\\*/)?({closure}[^\\R]*)(\\R)(\\R*)"
$t:="(?mi-s)(?<!"+kCommentMark+")(?<!"+kCommentMark+"\\s)(?:/\\*.*\\*/)?({closure}[^\\R]*)(\\R)(\\R*)"
This:C1470._patterns.closureInstructions:=[\
Replace string:C233($t; "{closure}"; This:C1470._controls.endIf); \
Replace string:C233($t; "{closure}"; This:C1470._controls.endCase); \
Expand All @@ -152,18 +152,20 @@ Class constructor()
+This:C1470._controls.endIf

// MARK: Choose
This:C1470._patterns.choose:="(?i-ms)"+Command name:C538(955)+"\\(([^;]*?);\\s*([^;]*?);\\s*([^;]*?)\\)(\\s* // .*?)?\\R"
This:C1470._patterns.choose:="(?i-ms)"+Command name:C538(955)+"\\(([^;]*?);\\s*([^;]*?);\\s*([^;]*?)\\)(\\s*"+kCommentMark+".*?)?\\R"

// MARK: Comparisson with empty string
This:C1470._patterns.emptyString:="(?mi-s)(?:\\(|;)([^)#=;]+)(?<!:)(#|=)\"\""

// MARK: Commands whose parameters must be divided into key/value lines
This:C1470._splittableCommands:=[\
{name: Command name:C538(1220); id: 1220; pattern: "(?mi-s)"+Command name:C538(1220)+"\\(([^;]*?);(.*?)\\)(\\s* // .*?)?$"; commentIndex: 4}; \
{name: Command name:C538(1055); id: 1055; pattern: "(?mi-s)"+Command name:C538(1055)+"\\((.*?)\\)(\\s* // .*?)?$"; commentIndex: 3}; \
{name: Command name:C538(865); id: 865; pattern: "(?mi-s)(.*?:=)"+Command name:C538(865)+"\\((.*?)\\)(\\s* // .*?)?$"; commentIndex: 4}; \
{name: Command name:C538(866); id: 866; pattern: "(?mi-s)"+Command name:C538(866)+"\\((.*?)\\)(\\s* // .*?)?$"; commentIndex: 3}; \
{name: Command name:C538(1093); id: 1093; pattern: "(?mi-s)"+Command name:C538(1093)+"\\((.*?)\\)(\\s* // .*?)?$"; commentIndex: 3}\
{name: Command name:C538(1471); id: 1471; pattern: "(?mi-s)(.*?:=)"+Command name:C538(1471)+"\\((.*?)\\)(.*?)$"; commentIndex: 4}; \
{name: Command name:C538(1220); id: 1220; pattern: "(?mi-s)"+Command name:C538(1220)+"\\(([^;]*?);(.*?)\\)(\\s*"+kCommentMark+".*?)?$"; commentIndex: 4}; \
{name: Command name:C538(1220); id: 1220; pattern: "(?mi-s)"+Command name:C538(1220)+"\\(([^;]*?);(.*?)\\)(\\s*"+kCommentMark+".*?)?$"; commentIndex: 4}; \
{name: Command name:C538(1055); id: 1055; pattern: "(?mi-s)"+Command name:C538(1055)+"\\((.*?)\\)(\\s*"+kCommentMark+".*?)?$"; commentIndex: 3}; \
{name: Command name:C538(865); id: 865; pattern: "(?mi-s)(.*?:=)"+Command name:C538(865)+"\\((.*?)\\)(\\s*/"+kCommentMark+".*?)?$"; commentIndex: 4}; \
{name: Command name:C538(866); id: 866; pattern: "(?mi-s)"+Command name:C538(866)+"\\((.*?)\\)(\\s*"+kCommentMark+".*?)?$"; commentIndex: 3}; \
{name: Command name:C538(1093); id: 1093; pattern: "(?mi-s)"+Command name:C538(1093)+"\\((.*?)\\)(\\s*"+kCommentMark+".*?)?$"; commentIndex: 3}\
]

// MARK: Splittable commands
Expand Down Expand Up @@ -459,7 +461,7 @@ Function before($code : Text) : Text
// Mark:Use var instead of (_o_)C_xxx
If (This:C1470.options.useVar)

$pattern:="(?-msi)(?<!//)(?<!//\\s){C_}\\((?![\\w\\s]+;\\s*\\$\\{?\\d+\\}?)([^{\\)]*)\\)"
$pattern:="(?-msi)(?<!"+kCommentMark+")(?<!"+kCommentMark+"\\s){C_}\\((?![\\w\\s]+;\\s*\\$\\{?\\d+\\}?)([^{\\)]*)\\)"
$code:=This:C1470.rgx.setTarget($code).setPattern(Replace string:C233($pattern; "{C_}"; Command name:C538(604))).substitute("var \\1 : Blob")
$code:=This:C1470.rgx.setTarget($code).setPattern(Replace string:C233($pattern; "{C_}"; Command name:C538(305))).substitute("var \\1 : Boolean")
$code:=This:C1470.rgx.setTarget($code).setPattern(Replace string:C233($pattern; "{C_}"; Command name:C538(1488))).substitute("var \\1 : Collection")
Expand Down Expand Up @@ -487,6 +489,9 @@ Function before($code : Text) : Text
// Mark:Use ternary operator
If (This:C1470.options.replaceIfElseEndIfByChoose) // Use ternary operator

$code:=This:C1470.rgx.setTarget($code).setPattern("(?mi-s)"+Command name:C538(955)+"\\(([^();]*?);([^();]*?);([^();]*?)\\)").substitute("\\1 ? \\2 : \\3")
$code:=This:C1470.rgx.setTarget($code).setPattern("(?mi-s)"+Command name:C538(955)+"\\(([^();]*?);([^();]*?);([^();]*?)\\)").substitute("\\1 ? \\2 : \\3") // Yes, twice ;-)

Try

$t:=This:C1470.unusedCharacter($code)
Expand Down Expand Up @@ -934,7 +939,7 @@ Function _splitLiterals($line : Text; $dlmt : Text) : Text

var $var : Text:=$c[0]

$c:=Split string:C1554($c[1]; kCommentMark)
$c:=Split string:C1554($c[1]; kCommentMark; sk trim spaces:K86:2)

If ($c.length=2)

Expand All @@ -956,7 +961,7 @@ Function _splitLiterals($line : Text; $dlmt : Text) : Text
var $out : Collection:=$c.map(Formula:C1597($1.value+";\\"))
$out.push($t)

return $var+":="+$dlmt[[1]]+"\\\r"+$out.join("\r")+$dlmt[[2]]+(Length:C16($comment)>0 ? kCommentMark+$comment : "")
return $var+":="+$dlmt[[1]]+"\\\r"+$out.join("\r")+$dlmt[[2]]+(Length:C16($comment)>0 ? " "+kCommentMark+$comment : "")

// === === === === === === === === === === === === === === === === === === === === === === === === === ===
Function splitKeyValueLine($line : Text) : Text
Expand Down Expand Up @@ -985,6 +990,41 @@ Function _splitIntoKeyAndValue($code : Text; $cmd : Object) : Text

Case of

// MARK:-New object -> Use literal notation
: ($cmd.id=1471)

If (Not:C34(This:C1470.rgx.setPattern($cmd.pattern).match(True:C214)))

return $code

End if

$c:=Split string:C1554(This:C1470.rgx.matches[2].data; ";"; sk trim spaces:K86:2)

$code:=This:C1470.rgx.matches[1].data+"{"

For ($i; 0; $c.length-1; 2)

$code+=Replace string:C233($c[$i]; "\""; "")+":"+$c[$i+1]

If (($i+1)<($c.length-1))

$code+=";"

End if
End for

$code+="}"

If (This:C1470.rgx.matches.length>=$cmd.commentIndex)

$code+=This:C1470.rgx.matches[$cmd.commentIndex-1].data

End if

return $code


// MARK:-SVG SET ATTRIBUTE
: ($cmd.id=1055)

Expand Down
4 changes: 2 additions & 2 deletions Project/Sources/Methods/BEAUTIFIER_TEST.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ If (True:C214)

$count:=$count*$i



var $isWindows; $isMac; $isLinux : Boolean
$txt:=Choose:C955($isWindows; "windows"; Choose:C955($isMac; "mac"; Choose:C955($isLinux; "linux"; "?"))) //comment


//mark:REMOVE THE MULTIPLE EMPTY LINES ABOVE
Expand Down
38 changes: 0 additions & 38 deletions Project/Sources/Methods/beautifier_test_11.4dm

This file was deleted.

51 changes: 51 additions & 0 deletions Project/Sources/Methods/beautifier_test_splitKeysValues.4dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//%attributes = {"invisible":true,"preemptive":"incapable"}
//1220
var $node; $root; $xpath; $txt : Text
var $pic : Picture

// mark:SPLIT LITERAL OBJECT WITH MORE THAN 2 MEMBERS
var $o : Object:={hello: "hello"; world: "World"}/* 2 PROPERTIES OR LESS = NOT SPLITTED */

$o:={property1: "value1"; property2: "value2"; property3: "value3"; property4: "value4"; property5: "value5"}

$o:=New object:C1471("alignement"; "horizontal"; "hAlignment"; Align right:K42:4; "space"; 13) // USE OBJECT LITETERAL NOTATION

// SAME FOR COLLECTIONS
var $c : Collection:=["hello"; "world"]/* 2 MEMBERS OR LESS = NOT SPLITTED */

$c:=[1; 2; "hello"; "world"]

// mark:Splittable commands
OB SET:C1220($o; "property"; 0; "property1"; 1; "property2"; 2; "property3"; 3)

OB SET:C1220($o; "property"; 12-(10*2); "property1"; "value1"; "property2"; "valu2"; "property3"; "value3") // Test2

OB SET:C1220($o; "property"; "value"; "property1"; {test: "hello"; test2: "world"}; "property2"; "valu2"; "property3"; "value3")/* NOT YET MANAGED */

OB SET:C1220($o; "property"; "value"; "property"; "value")/* LESS THAN 3 KEY/VALUE PAIRS = NOT SPLITTED */

/* ERROR IN PARAMETER COUNT = NOT SPLITTED */
//OB SET($o; "property"; 0; "property1"; 1; "property2"; 2; "property3"; 3; "zz")

SVG SET ATTRIBUTE:C1055(*; "toto"; "id"; "attribute"; "value"; "attribute1"; "value1"; "attribute2"; "value2")

SVG SET ATTRIBUTE:C1055($pic; "id"; "attribute"; "value"; "attribute1"; "value1"; "attribute2"; "value2")

SVG SET ATTRIBUTE:C1055($pic; "id"; "attribute"; "value"; "attribute1"; "value1"; "attribute2"; "value2") // Comment

SVG SET ATTRIBUTE:C1055(*; "toto"; "id"; "attribute"; "value"; "attribute1"; "value1")

SVG SET ATTRIBUTE:C1055(*; "toto"; "id"; "attribute"; "value")/* NOT SPLITTED */

SVG SET ATTRIBUTE:C1055($pic; "id"; "attribute"; "value")/* NOT SPLITTED */

DOM SET XML ATTRIBUTE:C866($node; "attribute"; "value"; "attribute1"; "value1"; "attribute2"; "value2") // Comment

DOM SET XML ATTRIBUTE:C866($node; "attribute"; "value")/* NOT SPLITTED */

$node:=DOM Create XML element:C865($root; $xpath; "attribute"; "value"; "attribute1"; "value1"; "attribute2"; "value2") // Comment

//ST SET ATTRIBUTES(*; "toto"; 10; 20; "attribute"; 0; "attribute1"; 1; "attribute2"; 2) // Comment

//ST SET ATTRIBUTES($txt; ST Start text; ST End text; "attribute"; "value"; "attribute1"; "value1"; "attribute2"; "value2") // Comment

2 changes: 1 addition & 1 deletion Project/Sources/folders.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@
"_test_choose",
"00_test_Dot_Notation",
"BEAUTIFIER_TEST",
"beautifier_test_11",
"beautifier_test_12",
"beautifier_test_13",
"beautifier_test_14",
Expand All @@ -189,6 +188,7 @@
"beautifier_test_7",
"beautifier_test_8",
"beautifier_test_9",
"beautifier_test_splitKeysValues",
"beutifier_OB",
"createFR2USMacro",
"DECLARATION_Formula",
Expand Down
Binary file modified Resources/InfoPlist.strings
Binary file not shown.

0 comments on commit d257f8e

Please sign in to comment.