Index: trunk/extensions/Wikidata/OmegaWiki/small/ra3.pl |
— | — | @@ -40,47 +40,67 @@ |
41 | 41 | # trying to _cut down_ on the number of errors, we don't |
42 | 42 | # eliminate them entirely, since we're just running this |
43 | 43 | # script once, after all |
44 | | - if (/\{/) { |
| 44 | + if (/\{/) { # Block start |
45 | 45 | $block_num++; |
46 | 46 | unshift(@block_stack, $block_num); |
47 | 47 | } |
48 | 48 | |
49 | | - if (/\}/) { |
| 49 | + if (/\}/) { #Block end |
50 | 50 | my $end=shift(@block_stack); |
51 | 51 | } |
52 | 52 | |
53 | | - if (/\;/) { |
54 | | - my @matches=[]; |
55 | | - $statement=~/^(\s*).*/; |
56 | | - my $indent=$1; |
57 | | - if ($global) { |
58 | | - @matches=($statement=~/\$(\w+)(Attributes?|Structure)/g); |
59 | | - if (@matches) { |
60 | | - $globals{$block_stack[0]}=joinpairs(@matches); |
61 | | - $statement=~s/\$(\w+)(Attributes?|Structure)\;/;/g; |
62 | | - $statement=~s/\$(\w+)(Attributes?|Structure)\W//gm; |
63 | | - #$statement=~s/;/ ,;/ if $statement=~/global.*\$\w*(.*);/gs; # if there are still params left, we need a comma |
64 | | - $statement=~s/;/;\n$indent\$o=OmegaWikiAttributes::getInstance();/g; |
| 53 | + if (/\;/) { #found a statement terminator. |
| 54 | + if (not $statement=~/^\s*\/\// or $statement=~/^\s*\#/) { |
| 55 | + my @matches=[]; |
| 56 | + $statement=~/^(\s*).*/; |
| 57 | + my $indent=$1; |
| 58 | + if ($global) { |
| 59 | + @matches=($statement=~/\$(\w+)(Attributes?|Structure)/g); |
| 60 | + if (@matches) { |
| 61 | + $globals{$block_stack[0]}=joinpairs(@matches); |
| 62 | + $statement=~s/\$(\w+)(Attributes?|Structure)\;/;/g; |
| 63 | + $statement=~s/\$(\w+)(Attributes?|Structure)\W//gm; |
| 64 | + #$statement=~s/;/ ,;/ if $statement=~/global.*\$\w*(.*);/gs; # if there are still params left, we need a comma |
| 65 | + print "\n${indent}\$o=OmegaWikiAttributes::getInstance();\n"; |
| 66 | + #my $target=";\n${indent}\$o=OmegaWikiAttributes::getInstance();"; |
| 67 | + #$statement=~s/;/$target/g; |
| 68 | + |
| 69 | + } |
| 70 | + $statement=~s/,\s*;/;/gm; # remove redundant trailing commas |
| 71 | + $statement=~s/.*global\s*;\s*//gs; # perhaps the global statement is entirely redundant? |
| 72 | + $statement=~s/^\s*$//gm; # remove empty lines (redundant now?) |
| 73 | + $global=0; # end of global statement |
65 | 74 | } |
66 | | - $statement=~s/,\s*;/;/gm; # remove redundant trailing commas |
67 | | - $statement=~s/.*global\s*;\s*//gs; # perhaps the global statement is entirely redundant? |
68 | | - $statement=~s/^\s*$//gm; # remove empty lines (redundant now?) |
69 | | - $global=0; # end of global statement |
| 75 | + #$statement=~s/\$o\s*=\s*\$omegaWikiAttributes;/\$o=OmegaWikiAttributes::getInstance();/g; |
| 76 | + |
| 77 | + my @tomatch; #matching only those vars found in the global statement |
| 78 | + foreach my $block (@block_stack){ |
| 79 | + #print "$block\n"; |
| 80 | + if ($globals{$block}) { |
| 81 | + my $items=$globals{$block}; |
| 82 | + push(@tomatch, @$items); |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + foreach my $item (@tomatch) { |
| 87 | + #print ">".@$item[0].",".@$item[1]."\n"; |
| 88 | + my $name=@$item[0]; |
| 89 | + my $type=@$item[1]; |
| 90 | + my $ending=$type unless $type=="Attribute"; |
| 91 | + $statement=~s/\$($name)$type(\W)/\$o\-\>${name}${ending}$2/gm; |
| 92 | + } |
| 93 | + $statement=~s/->getAttributeValue\(\s*\$o->(\w+)\s*\)/->$1/g; |
| 94 | + $statement=~s/\-\>setAttributeValue\(\s*\$o->(\w+)\s*,\s*(.*)\s*\)/->$1 = $2/g; |
| 95 | + #print $block_stack[0].": ".$statement; # and peek too |
| 96 | + #print "[".join(", ",@block_stack)."]\n"; |
70 | 97 | } |
71 | | - #$statement=~s/\$o\s*=\s*\$omegaWikiAttributes;/\$o=OmegaWikiAttributes::getInstance();/g; |
72 | | - #$tomatch=$globals{$block_stack[0]} |
73 | | - $statement=~s/\$(\w+)Attribute(\W)/\$o\-\>$1$2/g; |
74 | | - $statement=~s/\$(\w+)Attributes(\W)/\$o\-\>$1Attributes$2/g; |
75 | | - $statement=~s/\$(\w+)Structure(\W)/\$o\-\>$1Structure$2/g; |
76 | | - $statement=~s/->getAttributeValue\(\s*\$o->(\$\w+)\s*\);/->$1;/g; |
77 | | - $statement=~s/->setAttributeValue\(\s*\$o->(\$\w+)\s*,\s*(.*)\s*\);/->$1 = $2;/g; |
78 | | - #print $block_stack[0].": ".$statement; # and peek too |
79 | | - #print "[".join(", ",@block_stack)."]\n"; |
80 | | - $statement=""; |
| 98 | + print $statement; # Write out this statement |
| 99 | + |
| 100 | + $statement=""; # and start on a new one. |
81 | 101 | |
82 | 102 | } |
83 | | - print $block_stack[0].": ".$_; |
| 103 | + #print $block_stack[0].": ".$_; |
84 | 104 | } |
85 | 105 | print $statement; # flush out any remaining lines |
86 | 106 | |
87 | | -print Dumper(%globals); |
| 107 | +#print Dumper(%globals); |
Index: trunk/extensions/Wikidata/OmegaWiki/small/autoreplace.sh |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | #!/bin/bash |
3 | 3 | export myfile=$1; |
4 | 4 | |
5 | | -small/raO.pl $myfile > $myfile.new && |
| 5 | +small/ra3.pl $myfile > $myfile.new && |
6 | 6 | mv $myfile.new $myfile |