aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-12-09 13:51:05 +0100
committerMattias Andrée <maandree@operamail.com>2014-12-09 13:51:05 +0100
commit47e8b2a4f88b7ac0d09f61bb8491a738f67edd12 (patch)
tree8da52a55d5c4646124cd6f911ed36c9c962980d9
parentmerge track-errors and resolve conflict (diff)
downloadmds-47e8b2a4f88b7ac0d09f61bb8491a738f67edd12.tar.gz
mds-47e8b2a4f88b7ac0d09f61bb8491a738f67edd12.tar.bz2
mds-47e8b2a4f88b7ac0d09f61bb8491a738f67edd12.tar.xz
mds-kbdc: m + compile-layout: bug fixes and test cases
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--doc/info/mds.texinfo4
-rw-r--r--src/mds-kbdc/compile-layout.c32
-rw-r--r--test-files/mds-kbdc/compile-layout/invalid/invalid_escapes8
-rw-r--r--test-files/mds-kbdc/compile-layout/invalid/invalid_keys5
-rw-r--r--test-files/mds-kbdc/compile-layout/invalid/invalid_strings11
5 files changed, 44 insertions, 16 deletions
diff --git a/doc/info/mds.texinfo b/doc/info/mds.texinfo
index 891c936..6f30a39 100644
--- a/doc/info/mds.texinfo
+++ b/doc/info/mds.texinfo
@@ -5895,7 +5895,9 @@ characters by their code point, for example if you want
an `æ' you can write @code{"\u00E6"} or @code{"\uE6"},
instead of @code{"æ"}. You can also write @code{"\0346"},
the difference between `\0' and `\u' is that `\0' uses
-octal whereas `\u' uses hexadecimal.
+octal whereas `\u' uses hexadecimal. A noteworthy
+side-effect of this is that function names cannot start
+with a lower case `u'.
`\' can also be used to access variables and parameters.
For example `\1' in
diff --git a/src/mds-kbdc/compile-layout.c b/src/mds-kbdc/compile-layout.c
index 8e005c0..1e537d5 100644
--- a/src/mds-kbdc/compile-layout.c
+++ b/src/mds-kbdc/compile-layout.c
@@ -414,7 +414,7 @@ static char32_t* parse_function_call(mds_kbdc_tree_t* restrict tree, const char*
int r, saved_errno = 0;
/* Find the opening bracket associated with the function call and validate the escape. */
- for (; (c = *bracket); bracket++)
+ for (; c = *bracket, 1; bracket++)
if ((c == '_') || R('0', '9') || R('a', 'z') || R('A', 'Z'));
else if (c == '(')
break;
@@ -422,7 +422,7 @@ static char32_t* parse_function_call(mds_kbdc_tree_t* restrict tree, const char*
{
*end = bracket;
if (tree->processed != PROCESS_LEVEL)
- NEW_ERROR(tree, ERROR, "invalid escape");/* TODO test */
+ NEW_ERROR(tree, ERROR, "invalid escape");
goto error;
}
@@ -665,7 +665,7 @@ static char32_t* parse_escape(mds_kbdc_tree_t* restrict tree, const char* restri
/* Function call. */
*escape = 100;
else
- RETURN_ERROR(tree, ERROR, "invalid escape");/* TODO test */
+ RETURN_ERROR(tree, ERROR, "invalid escape");
/* Read escape. */
@@ -683,8 +683,10 @@ static char32_t* parse_escape(mds_kbdc_tree_t* restrict tree, const char* restri
else if (CR(16, 'A', 'F')) numbuf = 16 * numbuf + (c & 15) + 9;
else if (CR(10, '0', '9')) numbuf = 10 * numbuf + (c & 15);
else break;
+ if (c == '.')
+ raw++;
if (have == 0)
- RETURN_ERROR(tree, ERROR, "invalid escape");/* TODO test */
+ RETURN_ERROR(tree, ERROR, "invalid escape");
/* Evaluate escape. */
@@ -794,7 +796,7 @@ static char32_t* parse_quoted_string(mds_kbdc_tree_t* restrict tree, const char*
/* Close or open quote, of it got closed, convert the buffered UTF-8 text to UTF-32. */
if (quote ^= 1) continue;
if ((quote == 1) && (raw != raw_ + 1))
- CHAR_ERROR(tree, WARNING, "strings should either be unquoted or unclosed in one large quoted");/* TODO test */
+ CHAR_ERROR(tree, WARNING, "strings should either be unquoted or unclosed in one large quoted");
STORE;
}
else if (c == '\\')
@@ -807,9 +809,9 @@ static char32_t* parse_quoted_string(mds_kbdc_tree_t* restrict tree, const char*
{
/* Only escapes may be used without quotes, if the string contains quotes. */
if (*raw_ == '"')
- CHAR_ERROR(tree, ERROR, "only escapes may be outside quotes in quoted strings");/* TODO test */
+ CHAR_ERROR(tree, ERROR, "only escapes may be outside quotes in quoted strings");
else
- CHAR_ERROR(tree, ERROR, "mixing numericals and escapes is not allowed");/* TODO test */
+ CHAR_ERROR(tree, ERROR, "mixing numericals and escapes is not allowed");
tree->processed = PROCESS_LEVEL;
}
else
@@ -822,7 +824,7 @@ static char32_t* parse_quoted_string(mds_kbdc_tree_t* restrict tree, const char*
/* Check that no escape is incomplete. */
if (escape && (tree->processed != PROCESS_LEVEL))
{
- NEW_ERROR(tree, ERROR, "incomplete escape");/* TODO test */
+ NEW_ERROR(tree, ERROR, "incomplete escape");
error->start = escoff;
error->end = lineoff + strlen(raw_);
tree->processed = PROCESS_LEVEL;
@@ -831,7 +833,7 @@ static char32_t* parse_quoted_string(mds_kbdc_tree_t* restrict tree, const char*
/* Check that the quote is complete. */
if (quote && (tree->processed != PROCESS_LEVEL))
{
- NEW_ERROR(tree, ERROR, "quote is not closed");/* TODO test */
+ NEW_ERROR(tree, ERROR, "quote is not closed");
error->start = lineoff;
error->end = lineoff + strlen(raw_);
tree->processed = PROCESS_LEVEL;
@@ -887,9 +889,9 @@ static char32_t* parse_unquoted_string(mds_kbdc_tree_t* restrict tree, const cha
while ((c = *raw++))
if (R('0', '9')) buf = 10 * buf + (c & 15);
- else if (c == '\\') CHAR_ERROR(tree, ERROR, "mixing numericals and escapes is not allowed");/* TODO test */
- else if (c == '"') CHAR_ERROR(tree, ERROR, "mixing numericals and quotes is not allowed");/* TODO test */
- else CHAR_ERROR(tree, ERROR, "stray ‘%c’", c);/* TODO test */
+ else if (c == '\\') CHAR_ERROR(tree, ERROR, "mixing numericals and escapes is not allowed");
+ else if (c == '"') CHAR_ERROR(tree, ERROR, "mixing numericals and quotes is not allowed");
+ else CHAR_ERROR(tree, ERROR, "stray ‘%c’", c);
done:
fail_if (rc = malloc(2 * sizeof(char32_t)), rc == NULL);
@@ -970,7 +972,7 @@ static char32_t* parse_keys(mds_kbdc_tree_t* restrict tree, const char* restrict
int saved_errno;
/* Parse the string. */
- while (c = *raw++, *raw)
+ while (c = *raw++, c && *raw)
if (escape && strchr("()[]{}<>\"\\,", c))
{
/* Buffer UTF-8 text for convertion to UTF-32. */
@@ -1014,7 +1016,7 @@ static char32_t* parse_keys(mds_kbdc_tree_t* restrict tree, const char* restrict
/* Check that no escape is incomplete. */
if (escape && (tree->processed != PROCESS_LEVEL))
{
- NEW_ERROR(tree, ERROR, "incomplete escape");/* TODO test */
+ NEW_ERROR(tree, ERROR, "incomplete escape");
error->start = lineoff + (size_t)(strrchr(raw_, '\\') - raw_);
error->end = lineoff + strlen(raw_);
tree->processed = PROCESS_LEVEL;
@@ -1023,7 +1025,7 @@ static char32_t* parse_keys(mds_kbdc_tree_t* restrict tree, const char* restrict
/* Check that key-combination is complete. */
if ((c != '>') && (tree->processed != PROCESS_LEVEL))
{
- NEW_ERROR(tree, ERROR, "key-combination is not closed");/* TODO test */
+ NEW_ERROR(tree, ERROR, "key-combination is not closed");
error->start = lineoff;
error->end = lineoff + strlen(raw_);
tree->processed = PROCESS_LEVEL;
diff --git a/test-files/mds-kbdc/compile-layout/invalid/invalid_escapes b/test-files/mds-kbdc/compile-layout/invalid/invalid_escapes
new file mode 100644
index 0000000..a5420b7
--- /dev/null
+++ b/test-files/mds-kbdc/compile-layout/invalid/invalid_escapes
@@ -0,0 +1,8 @@
+\f~
+\~
+\u()
+\u
+\x00
+\undefinable_function() # no good, cannot startwith u because of the special \u-syntax
+\.
+
diff --git a/test-files/mds-kbdc/compile-layout/invalid/invalid_keys b/test-files/mds-kbdc/compile-layout/invalid/invalid_keys
new file mode 100644
index 0000000..edbac9e
--- /dev/null
+++ b/test-files/mds-kbdc/compile-layout/invalid/invalid_keys
@@ -0,0 +1,5 @@
+"" : <
+"" : <\>
+"" : <\f
+"" : <\
+
diff --git a/test-files/mds-kbdc/compile-layout/invalid/invalid_strings b/test-files/mds-kbdc/compile-layout/invalid/invalid_strings
new file mode 100644
index 0000000..93b58e1
--- /dev/null
+++ b/test-files/mds-kbdc/compile-layout/invalid/invalid_strings
@@ -0,0 +1,11 @@
+0a
+0\0
+0"hello"
+"hello"_
+\0.0
+"
+"
+\
+\
+\\
+