Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 2fda159

Browse filesBrowse files
committed
[[ Bug 16941 ]] Implement escaped literals
This patch implements escaped literals wrapped in single quotes. For example: put 'foo\n"bar"' Equals: foo "bar" This patch has the side effect that `'` is no longer an acceptable char in an identifier.
1 parent 1f7e568 commit 2fda159
Copy full SHA for 2fda159

File tree

6 files changed

+224
-43
lines changed
Filter options

6 files changed

+224
-43
lines changed

‎engine/src/ide.cpp

Copy file name to clipboardExpand all lines: engine/src/ide.cpp
+45-10Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -849,8 +849,9 @@ static void tokenize(const unsigned char *p_text, uint4 p_length, uint4 p_in_nes
849849
}
850850
else
851851
{
852-
switch(type_table[t_char])
853-
{
852+
uint8_t t_current_type = type_table[t_char];
853+
switch(t_current_type)
854+
{
854855
case ST_SPC:
855856
t_class = COLOURIZE_CLASS_WHITESPACE;
856857
while(t_index < p_length && type_table[(t_char = next_valid_char(p_text, t_index))] == ST_SPC)
@@ -992,17 +993,33 @@ static void tokenize(const unsigned char *p_text, uint4 p_length, uint4 p_in_nes
992993
break;
993994

994995
case ST_LIT:
995-
t_char = next_valid_char(p_text, t_index);
996-
while(t_index < p_length && type_table[t_char] != ST_EOL && (type_table[t_char] != ST_LIT))
996+
case ST_ESCLIT:
997+
{
998+
uint8_t t_previous_type = t_current_type;
999+
t_char = next_valid_char(p_text, t_index);
1000+
bool t_escaping = false;
1001+
while(t_index < p_length &&
1002+
type_table[t_char] != ST_EOL &&
1003+
((t_current_type == ST_ESCLIT && t_escaping) ||
1004+
(type_table[t_char] != t_current_type)))
1005+
{
1006+
t_previous_type = type_table[t_char];
1007+
if (t_previous_type == ST_ESC && !t_escaping)
1008+
t_escaping = true;
1009+
else if (t_escaping)
1010+
t_escaping = false;
9971011
t_char = next_valid_char(p_text, t_index);
998-
if (t_index < p_length && type_table[t_char] == ST_LIT)
1012+
}
1013+
1014+
if (t_index < p_length && type_table[t_char] == t_current_type)
9991015
{
10001016
t_char = next_valid_char(p_text, t_index);
10011017
t_class = COLOURIZE_CLASS_STRING;
10021018
}
10031019
else
10041020
t_class = COLOURIZE_CLASS_ERROR;
10051021
t_end = t_index;
1022+
}
10061023
break;
10071024

10081025
case ST_NUM:
@@ -1215,7 +1232,8 @@ static void tokenize_stringref(MCStringRef p_string, uint4 p_in_nesting, uint4&
12151232
}
12161233
else
12171234
{
1218-
switch(get_codepoint_type(t_char))
1235+
uint8_t t_current_type = get_codepoint_type(t_char);
1236+
switch(t_current_type)
12191237
{
12201238
case ST_SPC:
12211239
t_class = COLOURIZE_CLASS_WHITESPACE;
@@ -1367,17 +1385,34 @@ static void tokenize_stringref(MCStringRef p_string, uint4 p_in_nesting, uint4&
13671385
break;
13681386

13691387
case ST_LIT:
1370-
t_char = next_valid_unichar(p_string, t_index);
1371-
while(t_index < t_length && get_codepoint_type(t_char) != ST_EOL && get_codepoint_type(t_char) != ST_LIT)
1372-
t_char = next_valid_unichar(p_string, t_index);
1373-
if (t_index < t_length && get_codepoint_type(t_char) == ST_LIT)
1388+
case ST_ESCLIT:
1389+
{
1390+
uint8_t t_previous_type = t_current_type;
1391+
t_char = next_valid_unichar(p_string, t_index);
1392+
bool t_escaping = false;
1393+
1394+
while(t_index < t_length &&
1395+
get_codepoint_type(t_char) != ST_EOL &&
1396+
((t_current_type == ST_ESCLIT && t_escaping) ||
1397+
(get_codepoint_type(t_char) != t_current_type)))
1398+
{
1399+
t_previous_type = get_codepoint_type(t_char);
1400+
if (t_previous_type == ST_ESC && !t_escaping)
1401+
t_escaping = true;
1402+
else if (t_escaping)
1403+
t_escaping = false;
1404+
t_char = next_valid_unichar(p_string, t_index);
1405+
}
1406+
1407+
if (t_index < t_length && get_codepoint_type(t_char) == t_current_type)
13741408
{
13751409
t_char = next_valid_unichar(p_string, t_index);
13761410
t_class = COLOURIZE_CLASS_STRING;
13771411
}
13781412
else
13791413
t_class = COLOURIZE_CLASS_ERROR;
13801414
t_end = t_index;
1415+
}
13811416
break;
13821417

13831418
case ST_NUM:

‎engine/src/keywords.cpp

Copy file name to clipboardExpand all lines: engine/src/keywords.cpp
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ Parse_stat MCLocaltoken::parse(MCScriptPoint &sp)
216216

217217
// MW-2014-11-06: [[ Bug 3680 ]] If now, explicitvariables is on and we don't have a literal or
218218
// a number, its an error.
219-
if (MCexplicitvariables && type != ST_LIT && type != ST_NUM)
219+
if (MCexplicitvariables && type != ST_LIT && type != ST_ESCLIT && type != ST_NUM)
220220
{
221221
if (constant)
222222
MCperror->add(PE_CONSTANT_BADINIT, sp);

‎engine/src/lextable.cpp

Copy file name to clipboardExpand all lines: engine/src/lextable.cpp
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ uint8_t type_table[256] =
4646
ST_ID, ST_ID, ST_ID, ST_ID, // ^X ^Y ^Z ^[
4747
ST_ID, ST_ID, ST_ID, ST_ID, // ^\ ^] ^^ ^_
4848
ST_SPC, ST_OP, ST_LIT, ST_COM, // ! " #
49-
ST_ID, ST_OP, ST_OP, ST_ID, // $ % & '
49+
ST_ID, ST_OP, ST_OP, ST_ESCLIT, // $ % & '
5050
ST_LP, ST_RP, ST_OP, ST_OP, // ( ) * +
5151
ST_SEP, ST_MIN, ST_NUM, ST_OP, // , - . /
5252
ST_NUM, ST_NUM, ST_NUM, ST_NUM, // 0 1 2 3
@@ -114,7 +114,7 @@ uint8_t unicode_type_table[256] =
114114
ST_ID, ST_ID, ST_ID, ST_ID, // ^X ^Y ^Z ^[
115115
ST_ID, ST_ID, ST_ID, ST_ID, // ^\ ^] ^^ ^_
116116
ST_SPC, ST_OP, ST_LIT, ST_COM, // ! " #
117-
ST_ID, ST_OP, ST_OP, ST_ID, // $ % & '
117+
ST_ID, ST_OP, ST_OP, ST_ESCLIT, // $ % & '
118118
ST_LP, ST_RP, ST_OP, ST_OP, // ( ) * +
119119
ST_SEP, ST_MIN, ST_NUM, ST_OP, // , - . /
120120
ST_NUM, ST_NUM, ST_NUM, ST_NUM, // 0 1 2 3

‎engine/src/parsedef.h

Copy file name to clipboardExpand all lines: engine/src/parsedef.h
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2155,6 +2155,7 @@ enum {
21552155
ST_ID,
21562156
ST_ESC,
21572157
ST_LIT,
2158+
ST_ESCLIT,
21582159
ST_LC,
21592160
ST_RC,
21602161

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.