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.

[[ Bug 16941 ]] Implement escaped literals #5781

Open
wants to merge 2 commits into
base: develop
Choose a base branch
Loading
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[[ 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.
  • Loading branch information
montegoulding committed Aug 13, 2017
commit 7664b39db9ed5327d3464d0fe87203f9e18121a2
55 changes: 45 additions & 10 deletions 55 engine/src/ide.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -849,8 +849,9 @@ static void tokenize(const unsigned char *p_text, uint4 p_length, uint4 p_in_nes
}
else
{
switch(type_table[t_char])
{
uint8_t t_current_type = type_table[t_char];
switch(t_current_type)
{
case ST_SPC:
t_class = COLOURIZE_CLASS_WHITESPACE;
while(t_index < p_length && type_table[(t_char = next_valid_char(p_text, t_index))] == ST_SPC)
Expand Down Expand Up @@ -992,17 +993,33 @@ static void tokenize(const unsigned char *p_text, uint4 p_length, uint4 p_in_nes
break;

case ST_LIT:
t_char = next_valid_char(p_text, t_index);
while(t_index < p_length && type_table[t_char] != ST_EOL && (type_table[t_char] != ST_LIT))
case ST_ESCLIT:
{
uint8_t t_previous_type = t_current_type;
t_char = next_valid_char(p_text, t_index);
bool t_escaping = false;
while(t_index < p_length &&
type_table[t_char] != ST_EOL &&
((t_current_type == ST_ESCLIT && t_escaping) ||
(type_table[t_char] != t_current_type)))
{
t_previous_type = type_table[t_char];
if (t_previous_type == ST_ESC && !t_escaping)
t_escaping = true;
else if (t_escaping)
t_escaping = false;
t_char = next_valid_char(p_text, t_index);
if (t_index < p_length && type_table[t_char] == ST_LIT)
}

if (t_index < p_length && type_table[t_char] == t_current_type)
{
t_char = next_valid_char(p_text, t_index);
t_class = COLOURIZE_CLASS_STRING;
}
else
t_class = COLOURIZE_CLASS_ERROR;
t_end = t_index;
}
break;

case ST_NUM:
Expand Down Expand Up @@ -1215,7 +1232,8 @@ static void tokenize_stringref(MCStringRef p_string, uint4 p_in_nesting, uint4&
}
else
{
switch(get_codepoint_type(t_char))
uint8_t t_current_type = get_codepoint_type(t_char);
switch(t_current_type)
{
case ST_SPC:
t_class = COLOURIZE_CLASS_WHITESPACE;
Expand Down Expand Up @@ -1367,17 +1385,34 @@ static void tokenize_stringref(MCStringRef p_string, uint4 p_in_nesting, uint4&
break;

case ST_LIT:
t_char = next_valid_unichar(p_string, t_index);
while(t_index < t_length && get_codepoint_type(t_char) != ST_EOL && get_codepoint_type(t_char) != ST_LIT)
t_char = next_valid_unichar(p_string, t_index);
if (t_index < t_length && get_codepoint_type(t_char) == ST_LIT)
case ST_ESCLIT:
{
uint8_t t_previous_type = t_current_type;
t_char = next_valid_unichar(p_string, t_index);
bool t_escaping = false;

while(t_index < t_length &&
get_codepoint_type(t_char) != ST_EOL &&
((t_current_type == ST_ESCLIT && t_escaping) ||
(get_codepoint_type(t_char) != t_current_type)))
{
t_previous_type = get_codepoint_type(t_char);
if (t_previous_type == ST_ESC && !t_escaping)
t_escaping = true;
else if (t_escaping)
t_escaping = false;
t_char = next_valid_unichar(p_string, t_index);
}

if (t_index < t_length && get_codepoint_type(t_char) == t_current_type)
{
t_char = next_valid_unichar(p_string, t_index);
t_class = COLOURIZE_CLASS_STRING;
}
else
t_class = COLOURIZE_CLASS_ERROR;
t_end = t_index;
}
break;

case ST_NUM:
Expand Down
2 changes: 1 addition & 1 deletion 2 engine/src/keywords.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ Parse_stat MCLocaltoken::parse(MCScriptPoint &sp)

// MW-2014-11-06: [[ Bug 3680 ]] If now, explicitvariables is on and we don't have a literal or
// a number, its an error.
if (MCexplicitvariables && type != ST_LIT && type != ST_NUM)
if (MCexplicitvariables && type != ST_LIT && type != ST_ESCLIT && type != ST_NUM)
{
if (constant)
MCperror->add(PE_CONSTANT_BADINIT, sp);
Expand Down
4 changes: 2 additions & 2 deletions 4 engine/src/lextable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ uint8_t type_table[256] =
ST_ID, ST_ID, ST_ID, ST_ID, // ^X ^Y ^Z ^[
ST_ID, ST_ID, ST_ID, ST_ID, // ^\ ^] ^^ ^_
ST_SPC, ST_OP, ST_LIT, ST_COM, // ! " #
ST_ID, ST_OP, ST_OP, ST_ID, // $ % & '
ST_ID, ST_OP, ST_OP, ST_ESCLIT, // $ % & '
ST_LP, ST_RP, ST_OP, ST_OP, // ( ) * +
ST_SEP, ST_MIN, ST_NUM, ST_OP, // , - . /
ST_NUM, ST_NUM, ST_NUM, ST_NUM, // 0 1 2 3
Expand Down Expand Up @@ -114,7 +114,7 @@ uint8_t unicode_type_table[256] =
ST_ID, ST_ID, ST_ID, ST_ID, // ^X ^Y ^Z ^[
ST_ID, ST_ID, ST_ID, ST_ID, // ^\ ^] ^^ ^_
ST_SPC, ST_OP, ST_LIT, ST_COM, // ! " #
ST_ID, ST_OP, ST_OP, ST_ID, // $ % & '
ST_ID, ST_OP, ST_OP, ST_ESCLIT, // $ % & '
ST_LP, ST_RP, ST_OP, ST_OP, // ( ) * +
ST_SEP, ST_MIN, ST_NUM, ST_OP, // , - . /
ST_NUM, ST_NUM, ST_NUM, ST_NUM, // 0 1 2 3
Expand Down
1 change: 1 addition & 0 deletions 1 engine/src/parsedef.h
Original file line number Diff line number Diff line change
Expand Up @@ -2155,6 +2155,7 @@ enum {
ST_ID,
ST_ESC,
ST_LIT,
ST_ESCLIT,
ST_LC,
ST_RC,

Expand Down
3 changes: 3 additions & 0 deletions 3 engine/src/parseerrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -1792,6 +1792,9 @@ enum Parse_errors

// {PE-0582} send: can't send script in time
PE_SEND_SCRIPTINTIME,

// {PE-0583} Script: error parsing escape sequences in literal
PE_PARSE_BADLIT_ESCAPE,
};

extern const char *MCparsingerrors;
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.