Skip to content

Commit

Permalink
improved macro declaration with a better "clairvoyance"
Browse files Browse the repository at this point in the history
manage cs.<namespace>.class
manage +=, -=, /= & *= operators
  • Loading branch information
vdelachaux committed Nov 22, 2024
1 parent 2fd46d3 commit ed5d80a
Show file tree
Hide file tree
Showing 16 changed files with 194 additions and 200 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.
19 changes: 12 additions & 7 deletions Build/Components/4DPop Macros.4dbase/Contents/Info.plist
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<plist>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">

<dict>
<key>CFBundleName</key>
<string>4DPop Macros</string>
<key>CFBundleVersion</key>
<string>296</string>
<key>NSHumanReadableCopyright</key>
<string>©vdl 2009-2024</string>
<key>CFBundleGetInfoString</key>
<string>20R8</string>
<key>CFBundleLongVersionString</key>
<string>20R8 (295)</string>
<key>CFBundleShortVersionString</key>
<string>20R8</string>
<key>CFBundleDisplayName</key>
<string>4DPop Macros</string>
<key>CFBundleShortVersionString</key>
<string></string>
<key>NSHumanReadableCopyright</key>
<string></string>
<key>CFBundleVersion</key>
<string></string>
</dict>

</plist>
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<key>CFBundleName</key>
<string>4DPop Macros</string>
<key>CFBundleVersion</key>
<string>295</string>
<string>296</string>
<key>NSHumanReadableCopyright</key>
<string>©vdl 2009-2024</string>
<key>CFBundleGetInfoString</key>
Expand Down
69 changes: 47 additions & 22 deletions Project/Sources/Classes/declaration.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ property parameterNumber : Integer:=0
property _patterns : Object
property _notforArray : Collection:=["collection"; "variant"]

property windowRef : Integer

Class extends macro

Class constructor
Expand Down Expand Up @@ -168,6 +170,28 @@ Class constructor

This:C1470.loadGramSyntax()

This:C1470.parse()

If (This:C1470.variables.length>0)

This:C1470.windowRef:=Open form window:C675("DECLARATION"; Movable form dialog box:K39:8; Horizontally centered:K39:1; At the top:K39:5; *)
DIALOG:C40("DECLARATION"; This:C1470)

If (Bool:C1537(OK))

This:C1470.paste(This:C1470.method)
//SET MACRO PARAMETER(Choose(This.withSelection; Highlighted method text; Full method text); This.method)

End if

CLOSE WINDOW:C154(This:C1470.windowRef)

Else

ALERT:C41("No local variable or parameter to declare!")

End if

// === === === === === === === === === === === === === === === === === === === === === === === === === ===
Function split() : cs:C1710.declaration

Expand Down Expand Up @@ -570,12 +594,14 @@ declaration macro must omit the parameters of a formula

If ($var.type=Is object:K8:27)

var $class : Object:=This:C1470.classes.query("value = :1"; $var.value).first()

Case of

//╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌
: (Match regex:C1019("(?mi-s)\\"+$var.value+":=((?:cs|4d)\\.\\w*)\\.new\\([^)]*\\)(?!\\.)"; $line.code; 1; $pos; $len))
: ($class#Null:C1517)

$var.class:=Substring:C12($line.code; $pos{1}; $len{1})
$var.class:=$class.class

//╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌
: (Match regex:C1019("(?mi-s)\\"+$var.value+":="+Parse formula:C1576("File:C1566")+"\\([^)]*\\)(?!\\.)"; $line.code; 1))
Expand Down Expand Up @@ -605,7 +631,7 @@ declaration macro must omit the parameters of a formula
//____________________________________
: (False:C215)

// MARK:#TODO - get from member fonction or attribute
// TODO: Get from member fonction or attribute

//____________________________________
Else
Expand All @@ -615,11 +641,6 @@ declaration macro must omit the parameters of a formula
//____________________________________
End case

//╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌
Else

// A "Case of" statement should never omit "Else"

//╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌
End case

Expand Down Expand Up @@ -1350,6 +1371,10 @@ Function clairvoyant($text : Text; $line : Text) : Integer
ARRAY LONGINT:C221($len; 0)
ARRAY LONGINT:C221($pos; 0)

$t:=Replace string:C233(Replace string:C233($text; "{"; "\\{"); "}"; "\\}")



// MARK:- Literal syntax
Case of

Expand Down Expand Up @@ -1378,12 +1403,10 @@ Function clairvoyant($text : Text; $line : Text) : Integer
End case

// mark:-
$t:=Replace string:C233(Replace string:C233($text; "{"; "\\{"); "}"; "\\}")

Case of

//┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅
: (Match regex:C1019("(?m-si)(\\$\\w*):=((?:cs|4d)\\.\\w*)\\.new\\([^)]*\\)(?!\\.)"; $line; 1; $pos; $len)) // Class
: (Match regex:C1019("(?mi-s)(\\$\\w+):=((?:cs|4d)\\.\\w+(?:\\.\\w+)?)+\\.new\\("; $line; 1; $pos; $len)) // Class

// Keep class definition
This:C1470.classes.push({\
Expand All @@ -1393,28 +1416,30 @@ Function clairvoyant($text : Text; $line : Text) : Integer
return Is object:K8:27

//┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅
: (Match regex:C1019("(?m-si)\\"+$t+":=\"[^\"]*\""+"|"+Command name:C538(16)+"\\(\\"+$t+"\\)"; $line; 1)) // Length
: (Match regex:C1019("(?m-si)\\"+$t+"[-+:]=\"[^\"]*\""+"|"+Command name:C538(16)+"\\(\\"+$t+"\\)"; $line; 1))

return Is text:K8:3

//┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅
: (Match regex:C1019("(?mi-s)\\"+$t+"[-+/\\*:]=-*\\d+\\.\\d*"; $line; 1))\
|| (Match regex:C1019("(?mi-s)\\"+$t+"[:><]?[=><]?\\d+\\.\\d*"; $line; 1))\
|| (Match regex:C1019("[-+/\\*:]=\\s*"+Parse formula:C1576("Pi:K30:1"); $line; 1))\
|| (Match regex:C1019("[-+/\\*:]==\\s*"+Parse formula:C1576("Degree:K30:2"); $line; 1))\
|| (Match regex:C1019("[-+/\\*:]=\\s*"+Parse formula:C1576("Radian:K30:3"); $line; 1))\
|| (Match regex:C1019("[-+/\\*:]=\\s*"+Parse formula:C1576("e number:K30:4"); $line; 1))

return Is real:K8:4

//┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅
: (Match regex:C1019("(?m-si)\\"+$t+"[:><]?[=><]?\\d+"; $line; 1))\
|| (Match regex:C1019("(?mi-s)\\"+$t+"\\s\\?[?+-]\\s\\d*"; $line; 1))\
|| (Match regex:C1019(":=\\s*"+Parse formula:C1576("MAXINT:K35:1"); $line; 1))\
|| (Match regex:C1019(":=\\s*"+Parse formula:C1576("MAXLONG:K35:2"); $line; 1))\
|| (Match regex:C1019(":=\\s*"+Parse formula:C1576("MAXTEXTLENBEFOREV11:K35:3"); $line; 1))
|| (Match regex:C1019(":=\\s*"+Parse formula:C1576("MAXTEXTLENBEFOREV11:K35:3"); $line; 1))\
|| (Match regex:C1019("[-+/\\*:]=-*\\d"; $line; 1))

return Is longint:K8:6

//┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅
: (Match regex:C1019("(?mi-s)\\"+$t+"[:><]?[=><]?\\d+[."+This:C1470.decimalSeparator+"]\\d+"; $line; 1))\
|| (Match regex:C1019(":=\\s*"+Parse formula:C1576("Pi:K30:1"); $line; 1))\
|| (Match regex:C1019(":=\\s*"+Parse formula:C1576("Degree:K30:2"); $line; 1))\
|| (Match regex:C1019(":=\\s*"+Parse formula:C1576("Radian:K30:3"); $line; 1))\
|| (Match regex:C1019(":=\\s*"+Parse formula:C1576("e number:K30:4"); $line; 1))

return Is real:K8:4

//┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅
: (Match regex:C1019("(?m-si)\\"+$t+":=(?:"+Command name:C538(214)+"|"+Command name:C538(215)+")(?=$|\\(|(?:\\s*"+kCommentMark+")"+\
"|(?:\\s*/\\*))"; $line; 1))
Expand Down
58 changes: 53 additions & 5 deletions Project/Sources/Classes/macro.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ property _ouput : Collection:=[]

property decimalSeparator : Text

property isProject : Boolean:=Bool:C1537(Get database parameter:C643(Is host database a project:K37:99))

// MARK: Delegate
property rgx : cs:C1710.regex:=cs:C1710.regex.new()

Expand Down Expand Up @@ -76,7 +78,7 @@ Class constructor()
This:C1470.decimalSeparator:=$t

// <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <==
Function get macroCall() : Boolean
Function get isMacroProcess() : Boolean

return Process info:C1843(Current process:C322).name="Macro_Call"

Expand Down Expand Up @@ -319,7 +321,15 @@ Function PasteColor()
/// Compiler Directives for local variables
Function Declarations()

_o_DECLARATION
If (This:C1470.isProject)

cs:C1710.declaration.new()

Else

_o_DECLARATION

End if

// === === === === === === === === === === === === === === === === === === === === === === === === === ===
Function Beautifier()
Expand Down Expand Up @@ -478,7 +488,7 @@ Function convert_decimal()

If (This:C1470.highlighted="0x@")

This:C1470.paste(String:C10(str_gLon_Hex_To_Long(This:C1470.highlighted))+kCaret)
This:C1470.paste(String:C10(This:C1470._hex2long(This:C1470.highlighted))+kCaret)

Else

Expand Down Expand Up @@ -646,7 +656,8 @@ Function duplicateAndComment()

End if

// === === === === === === === === === === === === === === === === === === === === === === === === === ===
// MARK:-
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Function _comment() : Text

var $c : Collection
Expand Down Expand Up @@ -684,4 +695,41 @@ Function _comment() : Text
return "/*\r"+$c.join("\r")+"\r*/"+("\r"*Num:C11(v1=v2))

End if


// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Function _hex2long($hex : Text) : Integer

var $num : Real
var $charCode; $i; $length : Integer

$hex:=Uppercase:C13($hex)
$length:=Length:C16($hex)

For ($i; $length; 1; -1)

$charCode:=Character code:C91($hex[[$i]])

Case of

// ……………………………………………………………
: (($charCode>47)\
&& ($charCode<58)) // 0..9

$num+=(($charCode-48)*(16^($length-$i)))

// ……………………………………………………………
: (($charCode>64)\
&& ($charCode<71)) // A..F

$num+=(($charCode-55)*(16^($length-$i)))

// ……………………………………………………………
Else // "x" of Ox or other gizmo...

break

// ……………………………………………………………
End case
End for

return Int:C8($num)
2 changes: 0 additions & 2 deletions Project/Sources/Classes/preferences.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ Function loadPreferences()->$settingFile : 4D:C1709.File

Use (Storage:C1525.macros.preferences)

//Storage.macros.preferences.file:=$settingFile

Storage:C1525.macros.preferences.platformPath:=$settingFile.platformPath

$o:=_o_xml_fileToObject($settingFile.platformPath)
Expand Down
Loading

0 comments on commit ed5d80a

Please sign in to comment.