3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-30 07:59:42 +01:00

CGrammar: Fix #elif and function prototypes

This commit is contained in:
Pragmatic Software 2014-06-10 21:12:09 +00:00
parent 27dd491fe6
commit d8703faf0e
2 changed files with 17 additions and 23 deletions

View File

@ -13,7 +13,7 @@ use warnings;
# These are set automatically by the build/commit script # These are set automatically by the build/commit script
use constant { use constant {
BUILD_NAME => "PBot", BUILD_NAME => "PBot",
BUILD_REVISION => 627, BUILD_REVISION => 628,
BUILD_DATE => "2014-06-10", BUILD_DATE => "2014-06-10",
}; };

View File

@ -25,11 +25,11 @@ startrule:
startrule(?) startrule(?)
translation_unit: translation_unit:
(comment comment
| external_declaration | external_declaration
| function_definition | function_definition
| function_prototype | function_prototype
| preproc[matchrule => 'translation_unit']) | preproc[matchrule => 'translation_unit']
preproc: preproc:
definition definition
@ -39,7 +39,6 @@ preproc:
| error | error
| pragma | pragma
| preproc_conditional[matchrule => $arg{matchrule}] | preproc_conditional[matchrule => $arg{matchrule}]
{ $return = $item[-1]; }
definition: definition:
macro_definition macro_definition
@ -117,25 +116,21 @@ preproc_conditional:
if_line: if_line:
'#' 'ifdef' identifier <skip: '[ \t]*'> "\n" '#' 'ifdef' identifier <skip: '[ \t]*'> "\n"
{ $return .= "If the macro $item{identifier} is defined, then ^L"; } { $return .= "If the macro $item{identifier} is defined, then ^L"; }
| '#' 'ifndef' identifier /\n+/ | '#' 'ifndef' identifier <skip: '[ \t]*'> "\n"
{ $return .= "If the macro $item{identifier} is not defined, then ^L"; } { $return .= "If the macro $item{identifier} is not defined, then ^L"; }
| '#' 'if' constant_expression "\n" | '#' 'if' constant_expression <skip: '[ \t]*'> "\n"
{ $return .= "If the preprocessor condition^L $item{constant_expression} is true, then ^L"; } { $return .= "If the preprocessor condition^L $item{constant_expression} is true, then ^L"; }
elif_parts: elif_parts:
('#' 'elif' constant_expression ('#' 'elif' constant_expression
{ { $return .= "Otherwise, if the preprocessor condition $item{constant_expression} is true, then ^L"; }
$return = "\nNote: we interrupt the current context again.\n";
$return .= "Instead of the previous precondition, we include ";
$return .= "the following text based on this condition: \"$item{constant_expression}\".";
# $rule_name = $arg{matchrule};
}
(<matchrule: $rule_name> )[matchrule => $arg{matchrule}](s?) (<matchrule: $rule_name> )[matchrule => $arg{matchrule}](s?)
{ $return .= join('',@{$item[-1]}); } { $return .= join('',@{$item[-1]}); }
)(s) )(s)
{ $return = join('', @{$item[-1]}); }
else_parts: else_parts:
(/\n+/)(?) '#' 'else' '#' 'else'
{ $rule_name = $arg{matchrule}; } { $rule_name = $arg{matchrule}; }
(<matchrule: $rule_name>)[matchrule => $arg{matchrule}](s?) (<matchrule: $rule_name>)[matchrule => $arg{matchrule}](s?)
{ $return = "Otherwise, ^L" . join('',@{$item[-1]}); } { $return = "Otherwise, ^L" . join('',@{$item[-1]}); }
@ -204,18 +199,17 @@ function_prototype:
my $parameter_list = join('', @{$item{'parameter_type_list(?)'}}); my $parameter_list = join('', @{$item{'parameter_type_list(?)'}});
my $return_type = $item{declarator}; my $return_type = $item{declarator};
my $name = $item{declarator} ; my $name = $item{declarator};
$name =~ s/^.*?'/'/; $name =~ s/\|.*$//;
$return_type =~ s/\'.*\'//; $return_type =~ s/`.*`\|?//;
if ($return_type =~ /\w/ ) { if($return_type) {
$return_type .= "to a "; $return_type .= ' ';
$return_type .= $declaration_specifiers;
} else {
$return_type = $declaration_specifiers;
} }
$return_type .= $declaration_specifiers;
$return = "Let $name be a function prototype"; $return = "Let $name be a function prototype";
if ($parameter_list) { if ($parameter_list) {
@ -719,7 +713,7 @@ declaration:
$initializer =~ s/^initialized to //; $initializer =~ s/^initialized to //;
$return .= "$and$identifier to $initializer"; $return .= "$and$identifier to $initializer";
if($i < @initializers - 2) { if($i < @initializers - 2) {
$and = ', '; $and = $comma = ', ';
} else { } else {
$and = ' and '; $and = ' and ';
} }