Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: Parser.pm
- ===================================================================
- --- Parser.pm (revision 8776)
- +++ Parser.pm (working copy)
- @@ -34,7 +34,8 @@
- my %block;
- my $inBlock = 0;
- - my $countBlockIf = 0;
- + my $macroCountBlockIf = 0;
- + my $macroCountBlockSwitch = 0;
- my ($macro_subs, @perl_lines);
- open my $fp, "<:utf8", $file or return 0;
- while (<$fp>) {
- @@ -64,22 +65,33 @@
- if (%block && $block{type} eq "macro") {
- if ($_ eq "}") {
- - if ($countBlockIf) { # If the '}' is being used to terminate a block of commands from 'if'
- + if ($macroCountBlockIf || $macroCountBlockSwitch) { # If the '}' is being used to terminate a block of commands from 'if'
- push(@{$macro{$block{name}}}, '}');
- - $countBlockIf--;
- +
- + if ($macroCountBlockIf) {
- + $macroCountBlockIf--;
- + } else {
- + $macroCountBlockSwitch--;
- + }
- } else {
- undef %block
- }
- } else {
- if ($_ =~ /^if.*{$/) {
- - $countBlockIf++;
- - } elsif (!$countBlockIf && ($_ =~ /^}\s*else\s*{$/ || $_ =~ /}\s*elsif\s*\(.*\)\s*{$/)) {
- + $macroCountBlockIf++;
- + } elsif ($_ =~ /^switch.*{$/ || ($macroCountBlockSwitch && $_ =~ /^case.*{$/ || $_ =~ /^else.*{$/)) {
- + $macroCountBlockSwitch++;
- + } elsif (!$macroCountBlockIf && ($_ =~ /^}\s*else\s*{$/ || $_ =~ /}\s*elsif\s*\(.*\)\s*{$/)) {
- warning "$file: ignoring '$_' in line $. (munch, munch, not found the 'if')\n";
- next
- + } elsif (!$macroCountBlockSwitch && ($_ =~ /^case.*{$/ || $_ =~ /^else*{$/)) {
- + warning "$file: ignoring '$_' in line $. (munch, munch, not found the 'switch')\n";
- + next
- }
- push(@{$macro{$block{name}}}, $_);
- }
- +
- next
- }
- @@ -86,9 +98,13 @@
- if (%block && $block{type} eq "auto") {
- if ($_ eq "}") {
- if ($block{loadmacro}) {
- - if ($countBlockIf) {
- + if ($macroCountBlockIf || $macroCountBlockSwitch) {
- push(@{$macro{$block{loadmacro_name}}}, '}');
- - $countBlockIf--;
- + if ($macroCountBlockIf) {
- + $macroCountBlockIf--;
- + } else {
- + $macroCountBlockSwitch--;
- + }
- } else {
- undef $block{loadmacro}
- }
- @@ -102,10 +118,15 @@
- $macro{$block{loadmacro_name}} = []
- } elsif ($block{loadmacro}) {
- if ($_ =~ /^if.*{$/) {
- - $countBlockIf++;
- - } elsif (!$countBlockIf && ($_ =~ /^}\s*else\s*{$/ || $_ =~ /}\s*elsif\s*\(.*\)\s*{$/)) {
- + $macroCountBlockIf++;
- + } elsif ($_ =~ /^switch.*{$/ || ($macroCountBlockSwitch && $_ =~ /^case.*{$/ || $_ =~ /^else.*{$/)) {
- + $macroCountBlockSwitch++;
- + } elsif (!$macroCountBlockIf && ($_ =~ /^}\s*else\s*{$/ || $_ =~ /}\s*elsif\s*\(.*\)\s*{$/)) {
- warning "$file: ignoring '$_' in line $. (munch, munch, not found the 'if')\n";
- next
- + } elsif (!$macroCountBlockSwitch && ($_ =~ /^case.*{$/ || $_ =~ /^else*{$/)) {
- + warning "$file: ignoring '$_' in line $. (munch, munch, not found the 'switch')\n";
- + next
- }
- push(@{$macro{$block{loadmacro_name}}}, $_);
- @@ -123,6 +144,7 @@
- warning "$file: ignoring '$_' in line $. (munch, munch, unknown automacro keyword)\n"
- }
- }
- +
- next
- }
- Index: Script.pm
- ===================================================================
- --- Script.pm (revision 8776)
- +++ Script.pm (working copy)
- @@ -256,7 +256,7 @@
- if (multi($savetxt, $self, $errtpl)) {
- newThen($then, $self, $errtpl);
- if (defined $self->{error}) {$self->{error} = "$errtpl: $self->{error}"; return}
- - } elsif ($then eq "{") { # If the condition is false and are using block of commands, will be skipped
- + } elsif ($then eq "{") { # If the condition is false because "if" this is not using the command block
- my $countBlockIf = 1;
- while ($countBlockIf) {
- $self->{line}++;
- @@ -282,26 +282,67 @@
- $self->{timeout} = 0
- ##########################################
- - # If arriving at a line 'else' or 'elsif', it should be skipped -
- - # it will never be activated if coming from a false 'if'
- - } elsif ($line =~ /^}\s*else\s*{/ || $line =~ /^}\s*elsif\s*\(.*\)\s*{$/) {
- - my $countBlockIf = 1;
- - while ($countBlockIf) {
- - $self->{line}++;
- - my $searchEnd = ${$macro{$self->{name}}}[$self->{line}];
- -
- - if ($searchEnd =~ /^if.*{$/) {
- - $countBlockIf++;
- - } elsif (($searchEnd eq '}') ||
- - ($countBlockIf == 1 && ($searchEnd =~ /^}\s*else\s*{/ || $searchEnd =~ /^}\s*elsif\s*\(.*\)\s*{$/))) {
- - $countBlockIf--;
- - }
- + # If arriving at a line 'else', 'elsif' or 'case', it should be skipped -
- + # it will never be activated if coming from a false 'if' or a previous 'case' has not been called
- + } elsif ($line =~ /^}\s*else\s*{/ || $line =~ /^}\s*elsif\s*\(.*\)\s*{$/ || $line =~ /^case/ || $line =~ /^else/) {
- + my $countBlockIf = 1;
- + while ($countBlockIf) {
- + $self->{line}++;
- + my $searchEnd = ${$macro{$self->{name}}}[$self->{line}];
- +
- + if ($searchEnd =~ /^if.*{$/ || $searchEnd =~ /^switch.*{$/ || $searchEnd =~ /^case.*{$/ || $searchEnd =~ /^else\s*{$/) {
- + $countBlockIf++;
- + } elsif (($searchEnd eq '}') ||
- + ($countBlockIf == 1 && ($searchEnd =~ /^}\s*else\s*{/ || $searchEnd =~ /^}\s*elsif\s*\(.*\)\s*{$/))) {
- + $countBlockIf--;
- }
- + }
- $self->{timeout} = 0
- ##########################################
- - # end block of if
- + # switch statement:
- + } elsif ($line =~ /^switch.*{$/) {
- + my ($firstPartCondition) = $line =~ /^switch\s*\(\s*(.*)\s*\)\s*{$/;
- +
- + my $countBlocks = 1;
- + while ($countBlocks) {
- + $self->{line}++;
- + my $searchNextCase = ${$macro{$self->{name}}}[$self->{line}];
- +
- + $countBlocks++ if ($searchNextCase =~ /^case.*{$/ || $searchNextCase =~ /^switch.*{$/ || $searchNextCase =~ /^}\s*else\s*{$/ || $searchNextCase =~ /}\s*elsif\s*{$/ || $searchNextCase =~ /\s*else\s*{$/);
- + if ($searchNextCase =~ /^}$/) {
- + last if ($countBlocks == 1);
- + $countBlocks-- if ($countBlocks > 1);
- + }
- + next if ($countBlocks > 2);
- +
- + if ($searchNextCase =~ /^else/) {
- + my ($then) = $searchNextCase =~ /^else\s*(.*)/;
- + newThen($then, $self, $errtpl);
- + if (defined $self->{error}) {$self->{error} = "$errtpl: $self->{error}"; return}
- + last;
- + }
- +
- + my ($secondPartCondition, $then) = $searchNextCase =~ /^case\s*\(\s*(.*)\s*\)\s*(.*)/;
- + next if (!$secondPartCondition);
- +
- + my $completCondition = $firstPartCondition . ' ' . $secondPartCondition;
- + my $text = parseCmd($completCondition, $self);
- + if (defined $self->{error}) {$self->{error} = "$errtpl: $self->{error}"; return}
- + my $savetxt = particle($text, $self, $errtpl);
- + if (multi($savetxt, $self, $errtpl)) {
- + newThen($then, $self, $errtpl);
- + if (defined $self->{error}) {$self->{error} = "$errtpl: $self->{error}"; return}
- + last;
- + }
- + }
- +
- + $self->{line}++;
- + $self->{timeout} = 0
- +
- + ##########################################
- + # end block of "if" or "switch"
- } elsif ($line eq '}') {
- $self->{line}++;
- $self->{timeout} = 0
- Index: Wx/Debugger.pm
- ===================================================================
- --- Wx/Debugger.pm (revision 8776)
- +++ Wx/Debugger.pm (working copy)
- @@ -140,10 +140,11 @@
- my $indentation = 0;
- for ($i = 0; $i < @{$macro{$name}}; $i++) {
- if (${$macro{$name}}[$i - 1] =~ /^if.*{$/ || ${$macro{$name}}[$i - 1] =~ /^}\s*else\s*{$/ ||
- - ${$macro{$name}}[$i - 1] =~ /^}\s*elsif\s*\(.*\)\s*{$/) {
- + ${$macro{$name}}[$i - 1] =~ /^}\s*elsif\s*\(.*\)\s*{$/ || ${$macro{$name}}[$i - 1] =~ /^switch.*{$/ ||
- + ${$macro{$name}}[$i - 1] =~ /^case.*{$/ || ${$macro{$name}}[$i - 1] =~ /^else\s*{$/) {
- $indentation++;
- - } elsif (${$macro{$name}}[$i] eq '}' || ${$macro{$name}}[$i] =~ /^}\s*else\s*{$/ ||
- - ${$macro{$name}}[$i] =~ /^}\s*elsif\s*\(.*\)\s*{$/) {
- + } elsif (${$macro{$name}}[$i] eq '}' || ${$macro{$name}}[$i] =~ /^}\s*else\s*{/ ||
- + ${$macro{$name}}[$i] =~ /^}\s*elsif\s*\(.*\)\s*{$/) {
- $indentation--;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement