]> lifelog.hopto.org Git - PerlCNF.git/commitdiff
Priority by default to be higher then for other instructions.
authorWill Budic <redacted>
Fri, 21 Mar 2025 02:13:38 +0000 (13:13 +1100)
committerWill Budic <redacted>
Fri, 21 Mar 2025 02:13:38 +0000 (13:13 +1100)
system/modules/CNFMeta.pm
system/modules/CNFParser.pm
system/modules/MarkdownPlugin.pm
tests/testTreeToHTML.pl

index 532dfbe20f005435b2076547e01ddad90225ce8c..bf9283893207396216b4fc3a45034c3c3cfb5e76 100644 (file)
@@ -51,11 +51,12 @@ sub import {
     {
          # TREE instuction meta.
          *{"${caller}::meta_has_priority"}   = sub {return _meta("HAS_PROCESSING_PRIORITY")};
-         # Schedule to process before the rest in synchronous line of instructions.
+         # Schedule to process before the rest in synchronous line of instructions.  The lower the priority number,
+         # the higher, no priority is set to 0 same as the sequential scripted order of appearance.
          *{"${caller}::meta_priority"}       = \&PRIORITY;
          #Postpone to evaluate on demand.
          *{"${caller}::meta_on_demand"}      = sub {return _meta("ON_DEMAND")};
-         # Process or load last (includes0.
+         # Process or load last (includes get priority 1, tree type will get priority 4).
          *{"${caller}::meta_process_last"}   = sub {return _meta("PROCESS_LAST")};
          *{"${caller}::meta_const"}          = sub {return _meta("CONST")};
          ###
index 1f736d2cede261ca96b83232151189df8e35086e..548f7d2fbee227f85bf84cf49a1ddc0573208d68 100644 (file)
@@ -175,7 +175,14 @@ package InstructedDataItem {
     our %counters;
 
     sub new { my ($class, $ele, $ins, $val, $aid) = @_;
-        my $priority = ($val =~ s/$meta_has_priority/""/sexi)?2:($val =~ s/$meta_process_last/""/sexi)?5:3;
+        my $priority;
+           if($val =~ s/$meta_has_priority/""/sexi){
+                $priority = 2
+           }elsif($val =~ s/$meta_process_last/""/sexi){
+                $priority = 3
+           }else{
+                $priority = 5;
+           }
            $val =~ s/$meta_priority/""/sexi;
            $priority = $2 if $2;
         my $dataItemCounter;
@@ -216,7 +223,7 @@ package PropertyValueStyle {
                     if(!$p){
                         $p = $itm;
                     }else{
-                        $itm =~ s/^\s*(['"])(.*)\g{1}$/$2/g if $itm;
+                        $itm =~ s/^\s*(['"])(.*)\g{1}$/$2/g if $itm;  $itm =~ s/\s*$//;                        
                         $self->{$p}=$itm;
                         undef $p;
                     }
@@ -511,7 +518,7 @@ sub doInstruction { my ($self,$e,$t,$v) = @_;
         }
         $includes[@includes] = {script=>$v,local=>$CUR_SCRIPT,loaded=>0, prc_last=>$prc_last};
     }elsif($t eq 'TREE'){
-        my  $tree = 0;
+        my  $tree = 0; 
         if( !$v ){
              $v = $e;
              $e = CNFMeta::ANN();
@@ -605,7 +612,7 @@ sub doInstruction { my ($self,$e,$t,$v) = @_;
         }
     }
     elsif($t eq 'MACRO'){
-        $instructs{$e}=$v;
+        $instructs{$e}= "$v"; #Forcing into an string type by purpose.
     }
     elsif($t eq APP_STS){
         $self->instructPlugin(InstructedDataItem -> new($e, APP_STS, $v));
@@ -1024,7 +1031,7 @@ sub parse {  my ($self, $cnf_file, $content, $del_keys) = @_;
                 $struct  = $$struct;
                 $type    =  ref($struct);
             }
-            if($type eq 'String'){
+            if($type eq 'String'||$type eq ''){
                 my $v   = $struct;
                 my @arr = ($v =~ m/(\$\$\$.+?\$\$\$)/gm);
                 foreach my $find(@arr) {# <- MACRO TAG translate. ->
@@ -1044,15 +1051,15 @@ sub parse {  my ($self, $cnf_file, $content, $del_keys) = @_;
         }
 
         @items =  sort {$a->{'^'} <=> $b->{'^'}} @items; #sort by priority;
-
-        for my $idx(0..$#items-1) {
+        my @splice;
+        for my $idx(0..$#items) {
             my $struct = $items[$idx];
             my $type =  ref($struct);
             if(not $type){
                 CNFParserException->throw("Illegal struct encountered->$struct") if $struct
             }else{
                 my $priority = $struct-> {'^'};
-                if($type eq 'CNFNode' && $priority > 0){
+                if($type eq 'CNFNode' && $priority > 0 && $priority < 5){
                 $struct->validate() if $self->{ENABLE_WARNINGS};
                 if($struct->name() eq CNFMeta::ANN()){
                     my $anode = $struct->process($self, $struct->script());
@@ -1063,16 +1070,19 @@ sub parse {  my ($self, $cnf_file, $content, $del_keys) = @_;
                     $anechoic ->{$struct->name()} = $struct->process($self, $struct->script());
                     $self->log("Processed -> ".$struct->name()) if $self->{DEBUG}
                 }
-                splice @items, $idx, 1
+                    $splice[@splice] = $idx - @splice; 
                 }elsif($type eq 'InstructedDataItem' && $priority > 0 && $priority < 5){
                     my $t = $struct->{ins};
                     if($t eq 'PLUGIN'){
-                        instructPlugin($self, $struct);
-                        splice @items, $idx, 1
+                       instructPlugin($self, $struct);
+                       $splice[@splice] = $idx - @splice;                      
                     }
                 }
             }
         }
+        
+        foreach my $i(@splice){ splice(@items, $i, 1) }
+
         #Now only what is left instructed data items or plugins, and nodes that have assigned last priority, if any.
         for my $idx(0..$#items) {
             my $struct = $items[$idx];
@@ -1645,14 +1655,14 @@ __END__
    1. Reserved words relate to instructions, that are specially treated, and interpreted by the parser to perform extra or specifically processing on the current value.
    2. Reserved instructions can't be used for future custom ones, and also not recommended tag or property names.
    3. Current Reserved words list is.
-       - CONST    - Concentrated list of constances, or individaly tagged name and its value.
-       - VARIABLE - Concentrated list of anons, or individaly tagged name and its value.
+       - CONST    - Concentrated list of constances, or individally tagged name and its value.
+       - VARIABLE - Concentrated list of anons, or individually tagged name and its value.
        - DATA     - CNF scripted delimited data property, having uniform table data rows.
        - DATE     - Translate PerlCNF date representation to DateTime object. Returns now() on empty property value.
        - FILE     - CNF scripted delimited data property is in a separate file.
        - %LOG     - Log settings property, i.e. enabled=>1, console=>1.
        - TABLE    - SQL related.
-       - TREE     - Property is a CNFNode tree containing multiple debth nested children nodes.
+       - TREE     - Property is a CNFNode tree containing multiple depth nested children nodes.
        - INCLUDE  - Include properties from another file to this repository.
        - INDEX    - SQL related.
        - INSTRUCT - Provides custom new anonymous instruction.
@@ -1666,7 +1676,7 @@ __END__
           2. Parsing abruptly stops if this abstract property specified is not found.
           3. Macro format specifications, have been aforementioned in this document. However make sure that your macro an constant also including the *$* signifier if desired.
        - APP_SETTINGS - Provides external expected application settings defaults to the configuration.
-           1. These are added and processed in place as they appear sequentionaly in the script.
+           1. These are added and processed in place as they appear sequentially in the script.
               1. It can be made possible in the future, to meta instruct to run  APP_SETTING at the processing or post processing stages of CNF parsing.
            2. These can be externally added constance type CNF items if are found missing or not specified in current cnf file or from includes.
            3. An application usually obtains its settings object as an CNF property. Decoupling the CNF from handling this, making it abstract to the parser.
index f35c1aa24216bf01c4948f43824d790829e97d0d..b32acc6c69319bd53513524cc40d538f74b807d5 100644 (file)
@@ -68,7 +68,9 @@ try{
     }
     my $macro_instructions = $self -> {instructions};
     if($macro_instructions){       
-       my $tree  = $parser->anon($macro_instructions); 
+       my $tree  = $parser->anon($macro_instructions);  
+       MarkdownPluginException->throw(qq("Tree for instructions not visible or missing for: 
+                                      $macro_instructions in -> $parser->{CNF_CONTENT})) if not $tree;
        my $links = $tree->node('links');
        foreach my $link($links->nodes()){
           my $tag = $link->name();          
@@ -76,13 +78,22 @@ try{
           $script =~ s/\[\$\$\$\[\s*$tag\s*\]\$\$\$\]/$rep/gex
        }
 
-       my $images = $tree->node('links');
+       my $images = $tree->node('images');
        foreach my $img($images->nodes()){
           my $tag = $img->name();          
           my $rep = "![".$img->{desc}."](".$img->{url}.")";
           $script =~ s/\[\$\$\$\[\s*$tag\s*\]\$\$\$\]/$rep/gex
        }
 
+       my $particulars = $tree->node('particulars');
+       foreach my $item(@{$particulars->list()}){
+          my $tag = $item->{tag};        
+          MarkdownPluginException->throw(qq("Instructions particular not visible or missing for: 
+                                      $item->name() in ->  $parser->{CNF_CONTENT})) if not $tag;
+          my $rep = $parser->collections()->{$tag}; $rep = $$rep->val();
+          $script =~ s/\[\$\$\$\[\s*$tag\s*\]\$\$\$\]/$rep/gex
+       }
+
 
        my $val = $tree->val();
        if($val){
index addb5628ad94868f7a9743b148e7f80c2c45c2b2..47e7ddf856f003915d5fdbe892eafce7d0a43f78 100644 (file)
@@ -3,7 +3,7 @@ use warnings; use strict;
 use Syntax::Keyword::Try;
 
 use lib "tests";
-use lib "system/modules";
+use lib "/home/will/dev_new/PerlCNF/system/modules";
 
 
 require TestManager;