X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=generate-command-parser.pl;h=a7687c7bc480ab91d9e63c0cc13c2c94bec434ae;hb=da72a5be91ba9a64b368541a9af9f07d5de38df5;hp=f40bb390100b1ff3c26a748e4c84473a54e0317d;hpb=b1974a469f2dec2af753ea4735f1b1c5d37161da;p=i3%2Fi3 diff --git a/generate-command-parser.pl b/generate-command-parser.pl index f40bb390..a7687c7b 100755 --- a/generate-command-parser.pl +++ b/generate-command-parser.pl @@ -65,7 +65,7 @@ for my $line (@raw_lines) { my $current_state; for my $line (@lines) { - if (my ($state) = ($line =~ /^state ([A-Z_]+):$/)) { + if (my ($state) = ($line =~ /^state ([A-Z0-9_]+):$/)) { #say "got a new state: $state"; $current_state = $state; } else { @@ -109,10 +109,10 @@ for my $line (@lines) { # Second step: Generate the enum values for all states. # It is important to keep the order the same, so we store the keys once. -# We sort descendingly by length to be able to replace occurences of the state +# We sort descendingly by length to be able to replace occurrences of the state # name even when one state’s name is included in another one’s (like FOR_WINDOW # is in FOR_WINDOW_COMMAND). -my @keys = sort { length($b) <=> length($a) } keys %states; +my @keys = sort { (length($b) <=> length($a)) or ($a cmp $b) } keys %states; open(my $enumfh, '>', "GENERATED_${prefix}_enums.h"); @@ -155,12 +155,20 @@ for my $state (@keys) { # to generate a format string. The format uses %d for s, # literal numbers or state IDs and %s for NULL, s and literal # strings. + + # remove the function name temporarily, so that the following + # replacements only apply to the arguments. + my ($funcname) = ($fmt =~ /^(.+)\(/); + $fmt =~ s/^$funcname//; + $fmt =~ s/$_/%d/g for @keys; $fmt =~ s/\$([a-z_]+)/%s/g; $fmt =~ s/\&([a-z_]+)/%ld/g; $fmt =~ s/"([a-z0-9_]+)"/%s/g; $fmt =~ s/(?:-?|\b)[0-9]+\b/%d/g; + $fmt = $funcname . $fmt; + say $callfh " case $call_id:"; say $callfh " result->next_state = $next_state;"; say $callfh '#ifndef TEST_PARSER';