Skip to content

Commit 27d7357

Browse files
committed
Ada: handle char literal
The test case is taken from #2914 submitted by @koenmeersman. Signed-off-by: Masatake YAMATO <[email protected]>
1 parent f54a841 commit 27d7357

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
input.adb,158
3+
package body System.Val_Util isSystem.Val_Util/b4,69
4+
procedure Bad_Value (S : String) isBad_Value/p6,102
5+
procedure Not_Tagged isNot_Tagged/p11,236
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--- file: s-valuti.adb
2+
with System.Case_Util; use System.Case_Util;
3+
4+
package body System.Val_Util is
5+
6+
procedure Bad_Value (S : String) is
7+
begin
8+
raise Constraint_Error with "bad input for 'Value: """ & S & '"';
9+
end Bad_Value;
10+
11+
procedure Not_Tagged is
12+
begin
13+
null;
14+
end Not_Tagged;
15+
end System.Val_Util;

parsers/ada.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,10 @@ static void movePos(int amount)
642642
strncasecmp(&(buf)[(pos)], "--", strlen("--")) == 0)
643643
#define isAdaStringLiteral(buf, pos, len) \
644644
(((pos) < (len)) && ((buf)[(pos)] == '"'))
645+
#define isAdaCharLiteral(buf, pos, len) \
646+
(((pos) < (len - 2)) && ((buf)[(pos)] == '\'') \
647+
&& ((buf)[(pos + 2)] == '\''))
648+
645649

646650
static bool cmp(const char *buf, int len, const char *match)
647651
{
@@ -789,8 +793,8 @@ static void skipComments(void)
789793
}
790794
}
791795

792-
/* Return true if skipped over a string literal.
793-
* Return false if no string literal is found. */
796+
/* Return true if skipped over a string literal (or char literal).
797+
* Return false if no string literal (nor char literal) is found. */
794798
static bool skipStringLiteral(void)
795799
{
796800
if (exception != EXCEPTION_EOF && isAdaStringLiteral(line, pos, lineLen))
@@ -802,6 +806,9 @@ static bool skipStringLiteral(void)
802806
/* Go to the next char of " */
803807
movePos(1);
804808

809+
return true;
810+
} else if (exception != EXCEPTION_EOF && isAdaCharLiteral(line, pos, lineLen)) {
811+
movePos(3);
805812
return true;
806813
}
807814
return false;

0 commit comments

Comments
 (0)