Skip to content

Commit

Permalink
update declaration
Browse files Browse the repository at this point in the history
correctly processes '() : type' and '() -> $var : type'
  • Loading branch information
vdelachaux committed Mar 18, 2022
1 parent 67b5947 commit 6ea1a6e
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 64 deletions.
Binary file modified Build/Components/4DPop Macros.4dbase/4DPop Macros.4DZ
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Build/Components/4DPop Macros.4dbase/Info.plist
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?><!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>229</string> <key>NSHumanReadableCopyright</key> <string>©4D SAS 2009-2021</string> <key>CFBundleGetInfoString</key> <string>4DPop Macros</string> <key>CFBundleLongVersionString</key> <string>19R5</string> <key>CFBundleShortVersionString</key> <string>19R5</string> <key>CFBundleDisplayName</key> <string>4DPop Macros</string> </dict></plist>
<?xml version="1.0" encoding="UTF-8" standalone="no" ?><!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>230</string> <key>NSHumanReadableCopyright</key> <string>©4D SAS 2009-2021</string> <key>CFBundleGetInfoString</key> <string>4DPop Macros</string> <key>CFBundleLongVersionString</key> <string>19R5</string> <key>CFBundleShortVersionString</key> <string>19R5</string> <key>CFBundleDisplayName</key> <string>4DPop Macros</string> </dict></plist>
Expand Down
Binary file modified Build/Components/4DPop Macros.4dbase/Libraries/lib4d-arm64.dylib
Binary file not shown.
Binary file modified Build/Components/4DPop Macros.4dbase/Resources/InfoPlist.strings
Binary file not shown.
Binary file added Documentation/duplicate.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Info.plist
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?><!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>229</string> <key>NSHumanReadableCopyright</key> <string>©4D SAS 2009-2021</string> <key>CFBundleGetInfoString</key> <string>4DPop Macros</string> <key>CFBundleLongVersionString</key> <string>19R5</string> <key>CFBundleShortVersionString</key> <string>19R5</string> <key>CFBundleDisplayName</key> <string>4DPop Macros</string> </dict></plist>
<?xml version="1.0" encoding="UTF-8" standalone="no" ?><!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>230</string> <key>NSHumanReadableCopyright</key> <string>©4D SAS 2009-2021</string> <key>CFBundleGetInfoString</key> <string>4DPop Macros</string> <key>CFBundleLongVersionString</key> <string>19R5</string> <key>CFBundleShortVersionString</key> <string>19R5</string> <key>CFBundleDisplayName</key> <string>4DPop Macros</string> </dict></plist>
Expand Down
Binary file modified Libraries/lib4d-arm64.dylib
Binary file not shown.
102 changes: 49 additions & 53 deletions Project/Sources/Classes/declaration.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,15 @@ Function init()
This:C1470.loadGramSyntax()

//==============================================================
Function split()->$this : cs:C1710.declaration
Function split() : cs:C1710.declaration

Super:C1706.split(This:C1470.withSelection)

return (This:C1470)

//==============================================================
// Parses the code to extract parameters and local variables
Function parse()->$this : cs:C1710.declaration
Function parse() : cs:C1710.declaration

var $comment; $t; $text : Text
var $static : Boolean
Expand Down Expand Up @@ -399,14 +401,11 @@ declaration macro must omit the parameters of a formula

$var.type:=Is object:K8:27

//OB REMOVE($line; "type")

Else

$var.type:=This:C1470.getTypeFromDeclaration($text)

End if

End if
End for each
End if
Expand All @@ -424,7 +423,6 @@ declaration macro must omit the parameters of a formula
End if

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

$var:=This:C1470.locales.query("value=:1"; $t).pop()

If ($var=Null:C1517)
Expand Down Expand Up @@ -582,7 +580,7 @@ declaration macro must omit the parameters of a formula
//------------------------------------
: (False:C215)

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

//------------------------------------
Else
Expand Down Expand Up @@ -639,7 +637,7 @@ declaration macro must omit the parameters of a formula
// Finally do a flat list
This:C1470.variables:=This:C1470.parameters.combine(This:C1470.locales)

$this:=This:C1470
return (This:C1470)

//==============================================================
Function parseParameters($line : Object)
Expand All @@ -659,12 +657,12 @@ Function parseParameters($line : Object)
//______________________________________________________
: ($line.type="Function")

$pattern:="(?m-si)^(?!//)(.*)"+$line.type+"\\s([^(]*)(?:\\s*\\(([^)]*)\\))?(?:\\s*->\\s*([^/]*))?\\s*(//[^$]*)?$"
$pattern:="(?m-si)^(?!//)(.*)"+$line.type+"\\s([^(]*)(?:\\s*\\(([^)]*)\\))?(?:\\s*(?:->\\s*)?([^/]*))?\\s*(//[^$]*)?$"

//______________________________________________________
: ($line.type="#DECLARE")

$pattern:="(?m-si)^(?!//)()"+$line.type+"()(?:\\s*\\(([^)]*)\\))?(?:\\s*->\\s*([^/]*))?\\s*(//[^$]*)?$"
$pattern:="(?m-si)^(?!//)()"+$line.type+"()(?:\\s*\\(([^)]*)\\))?(?:\\s*(?:->\\s*)?([^/]*))?\\s*(//[^$]*)?$"

//______________________________________________________
End case
Expand Down Expand Up @@ -748,7 +746,7 @@ Function parseParameters($line : Object)
End if
End if

$parameter.label:="→ "+$parameter.value
$parameter.label:="→ "+(Length:C16($parameter.value)>0 ? $parameter.value : "return()")

This:C1470.parameters.push($parameter)

Expand Down Expand Up @@ -908,7 +906,7 @@ Function apply()
var $options : Object
$options:=This:C1470.settings.options

// PARAMETERS
// MARK:PARAMETERS
$c:=This:C1470.variables.query("parameter=true")
$o:=This:C1470.lines.query("type = :1 OR type = :2"; "Function"; "Class constructor").pop()

Expand All @@ -925,21 +923,14 @@ Function apply()

For each ($o; $c.query("order > 0"))

If (This:C1470.types[$o.type].value=Is variant:K8:33)

$method:=$method+(";"*Num:C11($o.order>1))+$o.value

Else

$method:=$method+(";"*Num:C11($o.order>1))+$o.value+":"\
+Choose:C955($o.class#Null:C1517; String:C10($o.class); This:C1470.types[$o.type].name)

End if
$method+=(Num:C11($o.order)>1 ? ";" : "")+$o.value
$method+=(This:C1470.types[$o.type].value#Is variant:K8:33) ? ":"+(($o.class#Null:C1517) ? String:C10($o.class) : This:C1470.types[$o.type].name) : ""

End for each

$method:=$method+")"

// *RETURN OF THE METHOD
// * RETURN OF THE METHOD
$o:=$c.query("order = 0").pop()

If ($o#Null:C1517)
Expand All @@ -949,11 +940,11 @@ Function apply()
If ($o.code="C_@")\
| ($o.code="var @")

$method:=$method+"\rvar "+$o.value
$method+="\rvar "+$o.value

Else

$method:=$method+"->"+$o.value
$method+=(Length:C16($o.value)>0 ? "->"+$o.value : "")

End if

Expand All @@ -962,19 +953,19 @@ Function apply()
If ($o.code="C_@")\
| ($o.code="var @")

$method:=$method+"\rvar "+$o.value+":"+This:C1470.types[$o.type].name
$method+="\rvar "+$o.value+":"+This:C1470.types[$o.type].name

Else

$method:=$method+"->"+$o.value+":"\
+Choose:C955($o.class#Null:C1517; String:C10($o.class); This:C1470.types[$o.type].name)
$method+=(Length:C16($o.value)>0 ? "->"+$o.value : "")+":"\
+($o.class#Null:C1517 ? String:C10($o.class) : This:C1470.types[$o.type].name)

End if
End if
End if

$method:=$method+String:C10(This:C1470.lines.query("type = :1 OR type = :2"; "Function"; "Class constructor").pop().comment)
$method:=$method+"\r"
$method+=String:C10(This:C1470.lines.query("type = :1 OR type = :2"; "Function"; "Class constructor").pop().comment)
$method+="\r"

End if

Expand All @@ -987,13 +978,13 @@ Function apply()

If ($o.class#Null:C1517)

$method:=$method+"var "+$o.value+":"+$o.class+"\r"
$compilerDirectives:=$compilerDirectives+"C_OBJECT:C1216("+This:C1470.name+";"+$o.value+")\r"
$method+="var "+$o.value+":"+$o.class+"\r"
$compilerDirectives+="C_OBJECT:C1216("+This:C1470.name+";"+$o.value+")\r"

Else

$method:=$method+"var "+$o.value+":"+This:C1470.types[$o.type].name+"\r"
$compilerDirectives:=$compilerDirectives+"4d:C"+String:C10(This:C1470.types[$o.type].directive)+"("+This:C1470.name+";"+$o.value+")\r"
$method+="var "+$o.value+":"+This:C1470.types[$o.type].name+"\r"
$compilerDirectives+="4d:C"+String:C10(This:C1470.types[$o.type].directive)+"("+This:C1470.name+";"+$o.value+")\r"

End if
End for each
Expand All @@ -1006,59 +997,64 @@ Function apply()

For each ($o; $c.query("order > 0"))

$method:=$method+(";"*Num:C11($o.order>1))+$o.value+":"
$method+=(";"*Num:C11($o.order>1))+$o.value

If ($o.class#Null:C1517)

$method:=$method+$o.class
$compilerDirectives:=$compilerDirectives+"C_OBJECT:C1216("+This:C1470.name+";$"+String:C10($o.order)+")\r"
$method+=":"+$o.class
$compilerDirectives+="C_OBJECT:C1216("+This:C1470.name+";$"+String:C10($o.order)+")\r"

Else

$method:=$method+This:C1470.types[$o.type].name
$compilerDirectives:=$compilerDirectives+"4d:C"+String:C10(This:C1470.types[$o.type].directive)+"("+This:C1470.name+";$"+String:C10($o.order)+")\r"
If ($o.type#Is variant:K8:33)

$method+=":"+This:C1470.types[$o.type].name

End if

$compilerDirectives+="4d:C"+String:C10(This:C1470.types[$o.type].directive)+"("+This:C1470.name+";$"+String:C10($o.order)+")\r"

End if
End for each

$method:=$method+")"
$method+=")"

// *RETURN OF THE METHOD
// * RETURN OF THE METHOD
$o:=$c.query("order = 0").pop()

If ($o#Null:C1517)

If ($o.code="C_@")

$method:=$method+"\rvar "+$o.value+":"+This:C1470.types[$o.type].name+"\r"
$method+="\rvar "+$o.value+":"+This:C1470.types[$o.type].name+"\r"

Else

$method:=$method+"->"+$o.value+":"
$method+=(Length:C16($o.value)>0) ? "->"+$o.value+":" : ":"

If ($o.class#Null:C1517)

$method:=$method+$o.class
$compilerDirectives:=$compilerDirectives+"C_OBJECT:C1216("+This:C1470.name+";$0)\r"
$method+=$o.class
$compilerDirectives+="C_OBJECT:C1216("+This:C1470.name+";$0)\r"

Else

$method:=$method+This:C1470.types[$o.type].name
$compilerDirectives:=$compilerDirectives+"4d:C"+String:C10(This:C1470.types[$o.type].directive)+"("+This:C1470.name+";$0)\r"
$method+=This:C1470.types[$o.type].name
$compilerDirectives+="4d:C"+String:C10(This:C1470.types[$o.type].directive)+"("+This:C1470.name+";$0)\r"

End if
End if
End if

$method:=$method+String:C10(This:C1470.lines.query("type = :1"; "#DECLARE").pop().comment)
$method+=String:C10(This:C1470.lines.query("type = :1"; "#DECLARE").pop().comment)

End if

// *COMPILER DIRECTIVES
// * COMPILER DIRECTIVES
If (This:C1470.projectMethod)\
& (Bool:C1537($options.methodDeclaration))

$method:=$method+"\r\r"+This:C1470.localized("If")+"(:C215)\r"\
$method+="\r\r"+This:C1470.localized("If")+"(:C215)\r"\
+Delete string:C232($compilerDirectives; Length:C16($compilerDirectives); 1)+"\r"\
+This:C1470.localized("End if")

Expand All @@ -1068,7 +1064,7 @@ Function apply()

$method:=This:C1470.addNewLine($method)

// LOCAL VARIABLES WITH SIMPLE TYPE
// MARK:LOCAL VARIABLES WITH SIMPLE TYPE
$c:=This:C1470.variables.query("parameter=null & array=null & count>0 & class=null")

If ($c.length>0)
Expand Down Expand Up @@ -1147,7 +1143,7 @@ Function apply()
End for each
End if

// LOCAL VARIABLES LINKED TO A CLASSE
// MARK:LOCAL VARIABLES LINKED TO A CLASSE
$c:=This:C1470.variables.query("parameter=null & array=null & count>0 & class!=null")

If ($c.length>0)
Expand All @@ -1162,7 +1158,7 @@ Function apply()

$method:=This:C1470.addNewLine($method)

// ARRAYS
// MARK:ARRAYS
$c:=This:C1470.variables.query("array=true & count>0 & static=false")

If ($c.length>0)
Expand Down
11 changes: 11 additions & 0 deletions Project/Sources/Classes/test_.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ Function thermometer($a : Text)->$this : Object

$this:=This:C1470

Function return($a) : Object

var $x : Blob
var $o; $this : Object

$o:=New object:C1471
SET BLOB SIZE:C606($x; 0)

$this:=This:C1470

Function formObject($a : Text)->$this : Object
$this:=This:C1470

Expand Down Expand Up @@ -85,6 +95,7 @@ Function init()
//%W-550.4
Function remove($node : Text)->$this : cs:C1710.xml
//%W+550.4

//%W-550.2
If (This:C1470._requiredParams(Count parameters:C259; 1))

Expand Down
4 changes: 2 additions & 2 deletions Project/Sources/Methods/00_TESTS.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Else
//C_LONGINT($indx)
//$indx:=Form.rule.indexOf(Form.ruleSelected[0])

var $o : 4D:C1709.File
$o:=4D:C1709.File.new()
var $file : 4D:C1709.File
$file:=4D:C1709.File.new()

End if
9 changes: 5 additions & 4 deletions Project/Sources/Methods/DECLARE.4dm
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//%attributes = {}
//C_TEXT($1)
//C_VARIANT($2)
//C_LONGINT($0)
#DECLARE($t : Text; $v : Variant)->$o : Object //comments
//C_LONGINT($0)//comments
#DECLARE($t : Text; $v) : Object

If (False:C215)
C_TEXT:C284(DECLARE; $1)
Expand All @@ -12,12 +12,13 @@ End if

var $text : Text
var $i : Integer

var $o : Object

$text:=$t
//$variant:=$v
$i:=20

$o:=New object:C1471
$o.text:=$text+String:C10($i)
$o.count:=$i
$o.count:=$i
return ($o)
4 changes: 2 additions & 2 deletions Project/Sources/settings.4DSettings
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?><preferences stamp="19">
<?xml version="1.0" encoding="UTF-8"?><preferences stamp="20">
<com.4d>
<interface>
<misc/>
Expand Down Expand Up @@ -47,7 +47,7 @@
<configuration allow_ssl="false" automatic_session_management="false" ip_address="0"/>
<webservices>
<server allow_requests="false"/> </webservices> </remote> </web>
<general execute_host_database_event="true">
<general component_classStore_name="" execute_host_database_event="true">
<mover always_display_dialog="2"/>
</general>
<deployment>
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ That's why they have an associated shortcut 😉
| [Beautifier…](#beautifier) |A code formatter|✔︎||⌘ §|
| [Copy and replace](#copyReplace) |Swaps the selection with the contents of the clipboard|✔︎||⌘ ⌥ c|
| [Special paste…](#specialPaste) |Paste the text contained in the clipboard by applying transformations|✔︎|_p|⌘ ⌥ v|
| Duplicate and comment |The selected text is saved as a comment immediately before the selection. This allows you to preserve a piece of code before editing it.|✔︎||⌘ ⌥ d|
| [Duplicate and comment](#duplicate)|The selected text is saved as a comment immediately before the selection.|✔︎||⌘ ⌥ d|
| Replay last macro |Replays the last macro used for the method being edited|✔︎||⌘ +|

\*Shortcuts may be displayed incorrectly in the macro menu because they are interpreted. e.g. `⌘ ⌥ c` will be displayed `⌘ ©`
Expand Down Expand Up @@ -128,6 +128,12 @@ To do this, select the line(s) of code in the method editor that cause this warn
<p align="center"><img src="./Documentation/disablingWarning.png" width="300">
## <a name="duplicate">Duplicate & comment</a>
I use it when I want to preserve a piece of code before editing it, but an image is better than text ;-)
<p align="center"><img src="./Documentation/duplicate.gif">
## <a name="copyToken">🆕 Copy with tokens</a>
As the name suggests, the selected code is copied with the tokens.
Expand Down
Binary file modified Resources/InfoPlist.strings
Binary file not shown.

0 comments on commit 6ea1a6e

Please sign in to comment.