From 7c77bd90e487a5e68a8f1d44c232a6d605490504 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sat, 5 Nov 2016 19:31:27 +0000 Subject: [PATCH] Fix parsing of ASCII special characters --- src/common.c | 3 +++ test/parse/literal.vhd | 2 ++ test/test_parse.c | 11 ++++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/common.c b/src/common.c index 537c3cd8..2379015e 100644 --- a/src/common.c +++ b/src/common.c @@ -721,6 +721,9 @@ tree_t str_to_literal(const char *start, const char *end, type_t type) } for (const char *p = start; *p != '\0' && p != end; p++) { + if (*(const unsigned char *)p == 0x81) + continue; // Allow UTF-8 encoded ASCII characters + const char ch[] = { '\'', *p, '\'', '\0' }; ident_t id = ident_new(ch); tree_t ref = tree_new(T_REF); diff --git a/test/parse/literal.vhd b/test/parse/literal.vhd index 337a645b..df85ac89 100644 --- a/test/parse/literal.vhd +++ b/test/parse/literal.vhd @@ -1,3 +1,4 @@ +-- -*- coding: latin-1 -*- ARCHITECTURE a OF e IS SIGNAL pos : INTEGER := 64; SIGNAL neg : INTEGER := -265; @@ -22,6 +23,7 @@ ARCHITECTURE a OF e IS CONSTANT s : STRING := % %; CONSTANT t : STRING := %A%; CONSTANT u : STRING := %%%%; + constant v : string := "©"; BEGIN END ARCHITECTURE; diff --git a/test/test_parse.c b/test/test_parse.c index 45d7f821..931b3c5a 100644 --- a/test/test_parse.c +++ b/test/test_parse.c @@ -776,7 +776,7 @@ START_TEST(test_literal) a = parse(); fail_if(a == NULL); fail_unless(tree_kind(a) == T_ARCH); - fail_unless(tree_decls(a) == 23); + fail_unless(tree_decls(a) == 24); d = tree_decl(a, 0); fail_unless(tree_ident(d) == ident_new("POS")); @@ -1018,6 +1018,15 @@ START_TEST(test_literal) fail_unless(tree_chars(v) == 1); fail_unless(tree_ident(tree_char(v, 0)) == ident_new("'%'")); + d = tree_decl(a, 23); + fail_unless(tree_kind(d) == T_CONST_DECL); + fail_unless(tree_ident(d) == ident_new("V")); + v = tree_value(d); + fail_unless(tree_kind(v) == T_LITERAL); + fail_unless(tree_subkind(v) == L_STRING); + fail_unless(tree_chars(v) == 1); + fail_unless(ident_char(tree_ident(tree_char(v, 0)), 1) == (char)0xa9); + a = parse(); fail_unless(a == NULL); -- 2.39.2