mirror of
https://github.com/pragma-/pbot.git
synced 2025-01-23 10:34:52 +01:00
CGrammar: support prefixes for character constants and string literals
This commit is contained in:
parent
022f86c3e1
commit
6ce05f5a05
@ -377,6 +377,7 @@ if(not $force and $ret != 0) {
|
|||||||
$output =~ s/\s*note: use option -std=c99 or -std=gnu99 to compile your code//g;
|
$output =~ s/\s*note: use option -std=c99 or -std=gnu99 to compile your code//g;
|
||||||
$output =~ s/\s*\(declared at .*?\)//g;
|
$output =~ s/\s*\(declared at .*?\)//g;
|
||||||
$output =~ s/, note: declared here//g;
|
$output =~ s/, note: declared here//g;
|
||||||
|
$output =~ s#/usr/include/.*?.h:\d+:\d+:/##g;
|
||||||
|
|
||||||
# don't error about undeclared objects
|
# don't error about undeclared objects
|
||||||
$output =~ s/error: '[^']+' undeclared\s*//g;
|
$output =~ s/error: '[^']+' undeclared\s*//g;
|
||||||
|
@ -1881,30 +1881,37 @@ constant:
|
|||||||
$return .= "long " while $item[-1] =~ s/[Ll]//;
|
$return .= "long " while $item[-1] =~ s/[Ll]//;
|
||||||
$return .= $item[-1];
|
$return .= $item[-1];
|
||||||
}
|
}
|
||||||
| /(?:\'((?:\\\'|(?!\').)*)\')/ # character constant
|
| /[LuU]?(?:\'(?:\\\'|(?!\').)*\')/ # character constant
|
||||||
{
|
{
|
||||||
my $constant = $item[1];
|
my $constant = $item[1];
|
||||||
|
my $modifier = "";
|
||||||
|
|
||||||
|
$modifier = 'wide character ' if $constant =~ s/^L//;
|
||||||
|
$modifier = '16-bit character ' if $constant =~ s/^u//;
|
||||||
|
$modifier = '32-bit character ' if $constant =~ s/^U//;
|
||||||
|
|
||||||
if ($constant eq q('\n')) {
|
if ($constant eq q('\n')) {
|
||||||
$return = 'a newline';
|
$return = "a $modifier" . 'newline';
|
||||||
} elsif ($constant eq q('\f')) {
|
} elsif ($constant eq q('\f')) {
|
||||||
$return = 'a form-feed character';
|
$return = "a $modifier" . 'form-feed character';
|
||||||
} elsif ($constant eq q('\t')) {
|
} elsif ($constant eq q('\t')) {
|
||||||
$return = 'a tab';
|
$return = "a $modifier" . 'tab';
|
||||||
} elsif ($constant eq q('\v')) {
|
} elsif ($constant eq q('\v')) {
|
||||||
$return = 'a vertical tab';
|
$return = "a $modifier" . 'vertical tab';
|
||||||
} elsif ($constant eq q('\b')) {
|
} elsif ($constant eq q('\b')) {
|
||||||
$return = 'an alert character';
|
$return = 'an alert character' if not length $modifier;
|
||||||
|
$return = "a $modifier" . 'alert character' if length $modifier;
|
||||||
} elsif ($constant eq q('\r')) {
|
} elsif ($constant eq q('\r')) {
|
||||||
$return = 'a carriage-return';
|
$return = "a $modifier" . 'carriage-return';
|
||||||
} elsif ($constant eq q('\b')) {
|
} elsif ($constant eq q('\b')) {
|
||||||
$return = 'a backspace character';
|
$return = "a $modifier" . 'backspace character';
|
||||||
} elsif ($constant eq q('\'')) {
|
} elsif ($constant eq q('\'')) {
|
||||||
$return = 'a single-quote';
|
$return = "a $modifier" . 'single-quote';
|
||||||
} elsif ($constant eq q(' ')) {
|
} elsif ($constant eq q(' ')) {
|
||||||
$return = 'a space';
|
$return = "a $modifier" . 'space';
|
||||||
} else {
|
} else {
|
||||||
$return = $constant;
|
$return = $constant if not length $modifier;
|
||||||
|
$return = "a $modifier$constant" if length $modifier;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1913,19 +1920,26 @@ identifier_word:
|
|||||||
{ $return = "`$item[-1]`"; }
|
{ $return = "`$item[-1]`"; }
|
||||||
|
|
||||||
string:
|
string:
|
||||||
(/(?:\"(?:\\\"|(?!\").)*\")/)(s)
|
(/(u8|u|U|L)?(?:\"(?:\\\"|(?!\").)*\")/)(s)
|
||||||
{
|
{
|
||||||
if (@{$item[-1]} == 1) {
|
my $final_string = "";
|
||||||
$return = @{$item[-1]}[0];
|
foreach my $string (@{$item[-1]}) {
|
||||||
} else {
|
if (not length $final_string) {
|
||||||
$return = '"';
|
my $modifier = "";
|
||||||
foreach my $string (@{$item[-1]}) {
|
$modifier = 'an UTF-8 string ' if $string =~ s/^u8//;
|
||||||
$string =~ s/^"//;
|
$modifier = 'a wide character string ' if $string =~ s/^L//;
|
||||||
$string =~ s/"$//;
|
$modifier = 'a 16-bit character string ' if $string =~ s/^u//;
|
||||||
$return .= $string;
|
$modifier = 'a 32-bit character string ' if $string =~ s/^U//;
|
||||||
|
$final_string = $modifier;
|
||||||
|
$final_string .= '"';
|
||||||
}
|
}
|
||||||
$return .= '"';
|
|
||||||
|
$string =~ s/^"//;
|
||||||
|
$string =~ s/"$//;
|
||||||
|
$final_string .= $string;
|
||||||
}
|
}
|
||||||
|
$final_string .= '"';
|
||||||
|
$return = $final_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
reserved:
|
reserved:
|
||||||
|
Loading…
Reference in New Issue
Block a user