Skip to content

Commit

Permalink
#DECLARE & var - part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
vdelachaux committed Sep 23, 2024
1 parent ec0fdae commit 843c7af
Show file tree
Hide file tree
Showing 10 changed files with 248 additions and 499 deletions.
41 changes: 0 additions & 41 deletions Project/Sources/Methods/COMPILER_xml.4dm

This file was deleted.

150 changes: 62 additions & 88 deletions Project/Sources/Methods/xmlColoredSyntax.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -7,122 +7,96 @@
// Description:
// Return colored XML to display in a Multi-style text object
// ----------------------------------------------------
// Declarations
C_TEXT:C284($0)
C_TEXT:C284($1)
#DECLARE($xml : Text) : Text

C_LONGINT:C283($Lon_error; $Lon_parameters)
C_TEXT:C284($Txt_attributeFontWeight; $Txt_attributeNameColor; $Txt_attributeValueColor; $Txt_commentColor; $Txt_commentFontWeight; $Txt_defaultColor)
C_TEXT:C284($Txt_defaultFontWeight; $Txt_doctypeColor; $Txt_doctypeFontWeight; $Txt_elementColor; $Txt_elementFontWeight; $Txt_entityColor)
C_TEXT:C284($Txt_entityFontWeight; $Txt_pattern; $Txt_processingColor; $Txt_processingFontWeight; $Txt_styleAttribute; $Txt_styleComment)
C_TEXT:C284($Txt_styleDoctype; $Txt_styleElement; $Txt_styleEntity; $Txt_styleProcessing; $Txt_xml)
var $Txt_attributeFontWeight; $Txt_attributeNameColor; $Txt_attributeValueColor; $Txt_commentColor; $Txt_commentFontWeight; $Txt_defaultColor : Text
var $Txt_defaultFontWeight; $Txt_doctypeColor; $Txt_doctypeFontWeight; $Txt_elementColor; $Txt_elementFontWeight; $Txt_entityColor : Text
var $Txt_entityFontWeight; $Txt_pattern; $Txt_processingColor; $Txt_processingFontWeight; $Txt_styleAttribute; $Txt_styleComment : Text
var $Txt_styleDoctype; $Txt_styleElement; $Txt_styleEntity; $Txt_styleProcessing : Text
var $Lon_error : Integer

If (False:C215)
C_TEXT:C284(xmlColoredSyntax; $0)
C_TEXT:C284(xmlColoredSyntax; $1)
End if
$Txt_defaultColor:=Get Application color scheme:C1763="dark" ? "white" : "black"
$Txt_defaultFontWeight:="normal"

// ----------------------------------------------------
// Initialisations
$Lon_parameters:=Count parameters:C259

If (Asserted:C1132($Lon_parameters>=1; Get localized string:C991("error_missingParameter")))

$Txt_xml:=$1

$Txt_defaultColor:=Get Application color scheme:C1763="dark" ? "white" : "black"
$Txt_defaultFontWeight:="normal"

$Txt_elementColor:="#2a2aa7"
$Txt_elementFontWeight:="normal"

$Txt_attributeFontWeight:="normal"
$Txt_attributeNameColor:="#f58953"
$Txt_attributeValueColor:="#9d3d0a"

$Txt_commentColor:="green"
$Txt_commentFontWeight:="normal"

$Txt_processingColor:="#8526C2"
$Txt_processingFontWeight:="normal"

$Txt_doctypeColor:="blue"
$Txt_doctypeFontWeight:="normal"

$Txt_entityColor:="#94961C"
$Txt_entityFontWeight:="normal"

$Txt_styleElement:="<span style=\"color:"+$Txt_elementColor\
+";font-weight:"+$Txt_elementFontWeight+";\">\\1</span>"

$Txt_styleAttribute:="<span style=\"color:"+$Txt_attributeNameColor\
+";font-weight:"+$Txt_attributeFontWeight\
+";\">\\1</span><span style=\"color:"+$Txt_defaultColor\
+";font-weight:"+$Txt_defaultFontWeight\
+";\">=\"<span style=\"color:"+$Txt_attributeValueColor\
+";font-weight:"+$Txt_attributeFontWeight\
+";\">\\2</span>\"</span>"

$Txt_styleComment:="<span style=\"color:"+$Txt_commentColor\
+";font-weight:"+$Txt_commentFontWeight+";\">\\1</span>"

$Txt_styleProcessing:="<span style=\"color:"+$Txt_processingColor\
+";font-weight:"+$Txt_processingFontWeight+";\">\\1</span>"

$Txt_styleDoctype:="<span style=\"color:"+$Txt_doctypeColor\
+";font-weight:"+$Txt_doctypeFontWeight+";\">\\1</span>"

$Txt_styleEntity:="<span style=\"color:"+$Txt_entityColor\
+";font-weight:"+$Txt_entityFontWeight+";\">\\1</span>"

Else

ABORT:C156

End if
$Txt_elementColor:="#2a2aa7"
$Txt_elementFontWeight:="normal"

// ----------------------------------------------------
$Txt_attributeFontWeight:="normal"
$Txt_attributeNameColor:="#f58953"
$Txt_attributeValueColor:="#9d3d0a"

$Txt_commentColor:="green"
$Txt_commentFontWeight:="normal"

$Txt_processingColor:="#8526C2"
$Txt_processingFontWeight:="normal"

$Txt_doctypeColor:="blue"
$Txt_doctypeFontWeight:="normal"

$Txt_entityColor:="#94961C"
$Txt_entityFontWeight:="normal"

$Txt_styleElement:="<span style=\"color:"+$Txt_elementColor\
+";font-weight:"+$Txt_elementFontWeight+";\">\\1</span>"

$Txt_styleAttribute:="<span style=\"color:"+$Txt_attributeNameColor\
+";font-weight:"+$Txt_attributeFontWeight\
+";\">\\1</span><span style=\"color:"+$Txt_defaultColor\
+";font-weight:"+$Txt_defaultFontWeight\
+";\">=\"<span style=\"color:"+$Txt_attributeValueColor\
+";font-weight:"+$Txt_attributeFontWeight\
+";\">\\2</span>\"</span>"

$Txt_styleComment:="<span style=\"color:"+$Txt_commentColor\
+";font-weight:"+$Txt_commentFontWeight+";\">\\1</span>"

$Txt_styleProcessing:="<span style=\"color:"+$Txt_processingColor\
+";font-weight:"+$Txt_processingFontWeight+";\">\\1</span>"

$Txt_styleDoctype:="<span style=\"color:"+$Txt_doctypeColor\
+";font-weight:"+$Txt_doctypeFontWeight+";\">\\1</span>"

$Txt_styleEntity:="<span style=\"color:"+$Txt_entityColor\
+";font-weight:"+$Txt_entityFontWeight+";\">\\1</span>"

// Replace < and > caracteres
$Txt_xml:=Replace string:C233($Txt_xml; "<"; "_§§")
$Txt_xml:=Replace string:C233($Txt_xml; ">"; "_¿¿")
$xml:=Replace string:C233($xml; "<"; "_§§")
$xml:=Replace string:C233($xml; ">"; "_¿¿")

// #ACI0098253
$Txt_xml:=Replace string:C233($Txt_xml; "&"; "&amp;")
$xml:=Replace string:C233($xml; "&"; "&amp;")

// Processing instruction
$Txt_pattern:="(_\\?[^_¿¿]*\\?_¿¿)"
$Lon_error:=Rgx_SubstituteText($Txt_pattern; $Txt_styleProcessing; ->$Txt_xml)
$Lon_error:=Rgx_SubstituteText($Txt_pattern; $Txt_styleProcessing; ->$xml)

// Attributes
$Txt_pattern:="(\\s+[^= ]*)=\"([^\"]*)\"(?!.*\\?_¿¿)"
$Lon_error:=Rgx_SubstituteText($Txt_pattern; $Txt_styleAttribute; ->$Txt_xml)
$Lon_error:=Rgx_SubstituteText($Txt_pattern; $Txt_styleAttribute; ->$xml)

// Elements
$Txt_pattern:="(_\\[^?_¿¿]*_¿¿)"
$Lon_error:=Rgx_SubstituteText($Txt_pattern; $Txt_styleElement; ->$Txt_xml)
$Lon_error:=Rgx_SubstituteText($Txt_pattern; $Txt_styleElement; ->$xml)

// Comments
$Txt_pattern:="(_\\!--.*?--_¿¿)"
$Lon_error:=Rgx_SubstituteText($Txt_pattern; $Txt_styleComment; ->$Txt_xml)
$Lon_error:=Rgx_SubstituteText($Txt_pattern; $Txt_styleComment; ->$xml)

// Default
$Txt_xml:="<span style=\"color:"+$Txt_defaultColor\
+";font-weight:"+$Txt_defaultFontWeight+";\">"+$Txt_xml+"</span>"
$xml:="<span style=\"color:"+$Txt_defaultColor\
+";font-weight:"+$Txt_defaultFontWeight+";\">"+$xml+"</span>"

// Doctype
$Txt_pattern:="(_\\\\![^-][^_¿¿]*_¿¿)"
$Lon_error:=Rgx_SubstituteText($Txt_pattern; $Txt_styleDoctype; ->$Txt_xml)
$Lon_error:=Rgx_SubstituteText($Txt_pattern; $Txt_styleDoctype; ->$xml)

// Entities
$Txt_pattern:="(&amp;[^;]*;)"
$Lon_error:=Rgx_SubstituteText($Txt_pattern; $Txt_styleEntity; ->$Txt_xml)
$Lon_error:=Rgx_SubstituteText($Txt_pattern; $Txt_styleEntity; ->$xml)

// Restore < and > caracteres
$Txt_xml:=Replace string:C233($Txt_xml; "_§§"; "&lt;")
$Txt_xml:=Replace string:C233($Txt_xml; "_¿¿"; "&gt;")

// ----------------------------------------------------
// End
$xml:=Replace string:C233($xml; "_§§"; "&lt;")
$xml:=Replace string:C233($xml; "_¿¿"; "&gt;")

$0:=$Txt_xml
return $xml
127 changes: 61 additions & 66 deletions Project/Sources/Methods/xml_COPY_ELEMENT.4dm
Original file line number Diff line number Diff line change
@@ -1,83 +1,78 @@
//%attributes = {"invisible":true}
// ----------------------------------------------------
// Method : xml_COPY_ELEMENT
// Created 08/09/08 by Vincent de Lachaux
// ----------------------------------------------------
// Description
//
// ----------------------------------------------------
C_TEXT:C284($1)
C_TEXT:C284($2)
// ----------------------------------------------------
// Method : xml_COPY_ELEMENT
// Created 08/09/08 by Vincent de Lachaux
// ----------------------------------------------------
#DECLARE($src : Text; $tgt : Text)

C_BOOLEAN:C305($Boo_OK;$Boo_stop)
C_LONGINT:C283($Lon_i)
C_TEXT:C284($Txt_Name;$Txt_nameBuffer;$Txt_Ref;$Txt_sourceRef;$Txt_target;$Txt_targetRef)
C_TEXT:C284($Txt_Value;$Txt_valueBuffer)
var $name; $node; $ref; $srcName; $srcValue; $value : Text
var $success : Boolean
var $i : Integer

If (False:C215)
C_TEXT:C284(xml_COPY_ELEMENT ;$1)
C_TEXT:C284(xml_COPY_ELEMENT ;$2)
End if

$Txt_sourceRef:=$1
$Txt_targetRef:=$2

If (Asserted:C1132(xml_referenceValid ($Txt_sourceRef) & xml_referenceValid ($Txt_targetRef);Get localized string:C991("error_badReference")))
If (Asserted:C1132(xml_referenceValid($src) & xml_referenceValid($tgt); Localized string:C991("error_badReference")))

$Txt_Ref:=DOM Get first child XML element:C723($Txt_sourceRef;$Txt_Name;$Txt_Value)
$ref:=DOM Get first child XML element:C723($src; $srcName; $srcValue)

If (OK=1)
If (OK=0)

return

End if

Repeat

$node:=DOM Create XML element:C865($tgt; $srcName)

Repeat
If (Not:C34(Bool:C1537(OK)))

$Txt_target:=DOM Create XML element:C865($Txt_targetRef;$Txt_Name)
$Boo_OK:=(OK=1)
break

If ($Boo_OK)

If (Length:C16($Txt_Value)>0)

DOM SET XML ELEMENT VALUE:C868($Txt_target;$Txt_Value)
$Boo_OK:=(OK=1)

End if

If ($Boo_OK)

For ($Lon_i;1;DOM Count XML attributes:C727($Txt_Ref);1)

DOM GET XML ATTRIBUTE BY INDEX:C729($Txt_Ref;$Lon_i;$Txt_nameBuffer;$Txt_valueBuffer)
$Boo_OK:=(OK=1)

If ($Boo_OK)

DOM SET XML ATTRIBUTE:C866($Txt_target;\
$Txt_nameBuffer;$Txt_valueBuffer)

Else

$Lon_i:=MAXLONG:K35:2-1

End if
End for
End if
End if
End if

$success:=Bool:C1537(OK)

If (Length:C16($srcValue)>0)

DOM SET XML ELEMENT VALUE:C868($node; $srcValue)

If ($Boo_OK)
If (Not:C34(Bool:C1537(OK)))

xml_COPY_ELEMENT ($Txt_Ref;$Txt_target)
break

End if
End if

For ($i; 1; DOM Count XML attributes:C727($ref); 1)

If ($Boo_OK)
$Txt_Ref:=DOM Get next sibling XML element:C724($Txt_Ref;$Txt_Name;$Txt_Value)
DOM GET XML ATTRIBUTE BY INDEX:C729($ref; $i; $name; $value)

If (Not:C34(Bool:C1537(OK)))

$Boo_stop:=(OK=0)
OK:=1
break

End if
Until (Not:C34($Boo_OK))\
| ($Boo_stop)
End if

DOM SET XML ATTRIBUTE:C866($node; \
$name; $value)

End for

If (Not:C34(Bool:C1537(OK)))

break

End if

xml_COPY_ELEMENT($ref; $node)

$ref:=DOM Get next sibling XML element:C724($ref; $srcName; $srcValue)

If (Not:C34(Bool:C1537(OK)))

OK:=1

break

End if
Until (False:C215)
End if
Loading

0 comments on commit 843c7af

Please sign in to comment.