X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=generate-command-parser.pl;h=6208945dc87558f0ee88cd5cfdbfcd9a9bd68e69;hb=ad7dec31d5785ce9006bbb8498529bead652d19c;hp=f69f715e569594f479d1458493f5d935cbaebfcf;hpb=85018de433fc5d59659298f9d337e155eeca9259;p=i3%2Fi3 diff --git a/generate-command-parser.pl b/generate-command-parser.pl index f69f715e..6208945d 100755 --- a/generate-command-parser.pl +++ b/generate-command-parser.pl @@ -2,7 +2,7 @@ # vim:ts=4:sw=4:expandtab # # i3 - an improved dynamic tiling window manager -# © 2009-2012 Michael Stapelberg and contributors (see also: LICENSE) +# © 2009 Michael Stapelberg and contributors (see also: LICENSE) # # generate-command-parser.pl: script to generate parts of the command parser # from its specification file parser-specs/commands.spec. @@ -84,14 +84,14 @@ for my $line (@lines) { # Cleanup the identifier (if any). $identifier =~ s/^\s*(\S+)\s*=\s*$/$1/g; - # Cleanup the tokens (remove whitespace). - $tokens =~ s/\s*//g; - # The default action is to stay in the current state. $action = $current_state if length($action) == 0; #say "identifier = *$identifier*, token = *$tokens*, action = *$action*"; for my $token (split(',', $tokens)) { + # Cleanup trailing/leading whitespace. + $token =~ s/^\s*//g; + $token =~ s/\s*$//g; my $store_token = { token => $token, identifier => $identifier, @@ -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"); @@ -131,7 +131,7 @@ close($enumfh); # Third step: Generate the call function. open(my $callfh, '>', "GENERATED_${prefix}_call.h"); -my $resultname = uc(substr($prefix, 0, 1)) . substr($prefix, 1) . 'Result'; +my $resultname = uc(substr($prefix, 0, 1)) . substr($prefix, 1) . 'ResultIR'; say $callfh "static void GENERATED_call(const int call_identifier, struct $resultname *result) {"; say $callfh ' switch (call_identifier) {'; my $call_id = 0; @@ -158,7 +158,6 @@ for my $state (@keys) { $fmt =~ s/$_/%d/g for @keys; $fmt =~ s/\$([a-z_]+)/%s/g; $fmt =~ s/\&([a-z_]+)/%ld/g; - $fmt =~ s/NULL/%s/g; $fmt =~ s/"([a-z0-9_]+)"/%s/g; $fmt =~ s/(?:-?|\b)[0-9]+\b/%d/g; @@ -177,6 +176,7 @@ for my $state (@keys) { $cmd =~ s/[^(]+\(//; $cmd =~ s/\)$//; $cmd = ", $cmd" if length($cmd) > 0; + $cmd =~ s/, NULL//g; say $callfh qq| fprintf(stderr, "$fmt\\n"$cmd);|; # The cfg_criteria functions have side-effects which are important for # testing. They are implemented as stubs in the test parser code. @@ -193,7 +193,6 @@ say $callfh ' default:'; say $callfh ' printf("BUG in the parser. state = %d\n", call_identifier);'; say $callfh ' assert(false);'; say $callfh ' }'; -say $callfh ' state = result->next_state;'; say $callfh '}'; close($callfh);