Treat __name the same as __node (#494)

* Treat __name the same as __node

This modifies the lexer so that it will accept __name and treat it
exactly the same as __node.  __node still works in order to preserve
backwards compatibility.

Fixes #258

Distribution Statement A; OPSEC #2893

Signed-off-by: P. J. Reed <preed@swri.org>

* Update dot graph for lexer

Distribution Statement A; OPSEC #2893

Signed-off-by: P. J. Reed <preed@swri.org>
This commit is contained in:
P. J. Reed 2019-11-22 07:23:51 -06:00 committed by Michel Hidalgo
parent 9034c406c2
commit 8af6f174e3
4 changed files with 175 additions and 149 deletions

View file

@ -42,7 +42,7 @@ typedef enum rcl_lexeme_t
RCL_LEXEME_URL_TOPIC = 4, RCL_LEXEME_URL_TOPIC = 4,
/// : /// :
RCL_LEXEME_COLON = 5, RCL_LEXEME_COLON = 5,
/// __node /// __node or __name
RCL_LEXEME_NODE = 6, RCL_LEXEME_NODE = 6,
/// __ns /// __ns
RCL_LEXEME_NS = 7, RCL_LEXEME_NS = 7,

View file

@ -1557,7 +1557,7 @@ _rcl_parse_remap_namespace_replacement(
return RCL_RET_OK; return RCL_RET_OK;
} }
/// Parse a nodename replacement rule (ex: `__node:=new_name`). /// Parse a nodename replacement rule (ex: `__node:=new_name` or `__name:=new_name`).
/** /**
* \sa _rcl_parse_remap_begin_remap_rule() * \sa _rcl_parse_remap_begin_remap_rule()
*/ */

View file

@ -64,10 +64,10 @@ digraph remapping_lexer {
S0 -> S1 [ label = "\\"]; S0 -> S1 [ label = "\\"];
S0 -> S2 [ label = "~"]; S0 -> S2 [ label = "~"];
S0 -> S3 [ label = "_" ]; S0 -> S3 [ label = "_" ];
S0 -> S8 [ label = "a-qs-zA-Z"]; S0 -> S9 [ label = "a-qs-zA-Z"];
S0 -> S10 [ label = "r"]; S0 -> S11 [ label = "r"];
S0 -> S29 [ label = "*"]; S0 -> S30 [ label = "*"];
S0 -> S30 [ label = ":"]; S0 -> S31 [ label = ":"];
S1 -> T_BR1 [ label = "1"]; S1 -> T_BR1 [ label = "1"];
S1 -> T_BR2 [ label = "2"]; S1 -> T_BR2 [ label = "2"];
S1 -> T_BR3 [ label = "3"]; S1 -> T_BR3 [ label = "3"];
@ -79,60 +79,62 @@ digraph remapping_lexer {
S1 -> T_BR9 [ label = "9"]; S1 -> T_BR9 [ label = "9"];
S2 -> T_TILDE_SLASH [ label ="/" ]; S2 -> T_TILDE_SLASH [ label ="/" ];
S3 -> S4 [ label = "_" ]; S3 -> S4 [ label = "_" ];
S3 -> S9 [ label = "<else,1>", color = crimson, fontcolor = crimson]; S3 -> S10 [ label = "<else,1>", color = crimson, fontcolor = crimson];
S4 -> S5 [ label = "n" ]; S4 -> S5 [ label = "n" ];
S5 -> T_NS [ label = "s"]; S5 -> T_NS [ label = "s"];
S5 -> S6 [ label = "o" ]; S5 -> S6 [ label = "o" ];
S6 -> S7 [ label = "d" ]; S6 -> S8 [ label = "d" ];
S7 -> T_NODE [ label = "e"]; S5 -> S7 [ label = "a" ];
S8 -> T_TOKEN [ label = "<else,1>", color=crimson, fontcolor=crimson]; S7 -> S8 [ label = "m" ];
S8 -> S8 [ label = "a-zA-Z0-9"]; S8 -> T_NODE [ label = "e"];
S8 -> S9 [ label = "_"];
S9 -> T_TOKEN [ label = "<else,1>", color=crimson, fontcolor=crimson]; S9 -> T_TOKEN [ label = "<else,1>", color=crimson, fontcolor=crimson];
S9 -> S8 [ label = "a-zA-Z0-9"]; S9 -> S9 [ label = "a-zA-Z0-9"];
S10 -> S8 [ label = "<else,1>", color=crimson, fontcolor=crimson]; S9 -> S10 [ label = "_"];
S10 -> S11 [ label = "o"]; S10 -> T_TOKEN [ label = "<else,1>", color=crimson, fontcolor=crimson];
S11 -> S8 [ label = "<else,1>", color=crimson, fontcolor=crimson]; S10 -> S9 [ label = "a-zA-Z0-9"];
S11 -> S12 [ label = "s"]; S11 -> S9 [ label = "<else,1>", color=crimson, fontcolor=crimson];
S12 -> S8 [ label = "<else,1>", color=crimson, fontcolor=crimson]; S11 -> S12 [ label = "o"];
S12 -> S13 [ label = "t"]; S12 -> S9 [ label = "<else,1>", color=crimson, fontcolor=crimson];
S12 -> S20 [ label = "s"]; S12 -> S13 [ label = "s"];
S13 -> S8 [ label = "<else,1>", color=crimson, fontcolor=crimson]; S13 -> S9 [ label = "<else,1>", color=crimson, fontcolor=crimson];
S13 -> S14 [ label = "o"]; S13 -> S14 [ label = "t"];
S14 -> S8 [ label = "<else,1>", color=crimson, fontcolor=crimson]; S13 -> S21 [ label = "s"];
S14 -> S15 [ label = "p"]; S14 -> S9 [ label = "<else,1>", color=crimson, fontcolor=crimson];
S15 -> S8 [ label = "<else,1>", color=crimson, fontcolor=crimson]; S14 -> S15 [ label = "o"];
S15 -> S16 [ label = "i"]; S15 -> S9 [ label = "<else,1>", color=crimson, fontcolor=crimson];
S16 -> S8 [ label = "<else,1>", color=crimson, fontcolor=crimson]; S15 -> S16 [ label = "p"];
S16 -> S17 [ label = "c"]; S16 -> S9 [ label = "<else,1>", color=crimson, fontcolor=crimson];
S17 -> S8 [ label = "<else,1>", color=crimson, fontcolor=crimson]; S16 -> S17 [ label = "i"];
S17 -> S18 [ label = ":"]; S17 -> S9 [ label = "<else,1>", color=crimson, fontcolor=crimson];
S18 -> S19 [ label = "/"]; S17 -> S18 [ label = "c"];
S18 -> S8 [ label = "<else,2>", color=crimson, fontcolor=crimson]; S18 -> S9 [ label = "<else,1>", color=crimson, fontcolor=crimson];
S19 -> T_URL_TOPIC [ label = "/"]; S18 -> S19 [ label = ":"];
S19 -> S8 [ label = "<else,3>", color=crimson, fontcolor=crimson]; S19 -> S20 [ label = "/"];
S20 -> S8 [ label = "<else,1>", color=crimson, fontcolor=crimson]; S19 -> S9 [ label = "<else,2>", color=crimson, fontcolor=crimson];
S20 -> S21 [ label = "e"]; S20 -> T_URL_TOPIC [ label = "/"];
S21 -> S8 [ label = "<else,1>", color=crimson, fontcolor=crimson]; S20 -> S9 [ label = "<else,3>", color=crimson, fontcolor=crimson];
S21 -> S22 [ label = "r"]; S21 -> S9 [ label = "<else,1>", color=crimson, fontcolor=crimson];
S22 -> S8 [ label = "<else,1>", color=crimson, fontcolor=crimson]; S21 -> S22 [ label = "e"];
S22 -> S23 [ label = "v"]; S22 -> S9 [ label = "<else,1>", color=crimson, fontcolor=crimson];
S23 -> S8 [ label = "<else,1>", color=crimson, fontcolor=crimson]; S22 -> S23 [ label = "r"];
S23 -> S24 [ label = "i"]; S23 -> S9 [ label = "<else,1>", color=crimson, fontcolor=crimson];
S24 -> S8 [ label = "<else,1>", color=crimson, fontcolor=crimson]; S23 -> S24 [ label = "v"];
S24 -> S25 [ label = "c"]; S24 -> S9 [ label = "<else,1>", color=crimson, fontcolor=crimson];
S25 -> S8 [ label = "<else,1>", color=crimson, fontcolor=crimson]; S24 -> S25 [ label = "i"];
S25 -> S26 [ label = "e"]; S25 -> S9 [ label = "<else,1>", color=crimson, fontcolor=crimson];
S26 -> S27 [ label = ":"]; S25 -> S26 [ label = "c"];
S26 -> S8 [ label = "<else,1>", color=crimson, fontcolor=crimson]; S26 -> S9 [ label = "<else,1>", color=crimson, fontcolor=crimson];
S27 -> S28 [ label = "/"]; S26 -> S27 [ label = "e"];
S27 -> S8 [ label = "<else,2>", color=crimson, fontcolor=crimson]; S27 -> S28 [ label = ":"];
S28 -> T_URL_SERVICE [ label = "/"]; S27 -> S9 [ label = "<else,1>", color=crimson, fontcolor=crimson];
S28 -> S8 [ label = "<else,3>", color=crimson, fontcolor=crimson]; S28 -> S29 [ label = "/"];
S29 -> T_WILD_MULTI[ label = "*"]; S28 -> S9 [ label = "<else,2>", color=crimson, fontcolor=crimson];
S29 -> T_WILD_ONE [ label = "<else,1>", color=crimson, fontcolor=crimson]; S29 -> T_URL_SERVICE [ label = "/"];
S30 -> T_SEPARATOR [ label = "="]; S29 -> S9 [ label = "<else,3>", color=crimson, fontcolor=crimson];
S30 -> T_COLON [ label = "<else,1>", color=crimson, fontcolor=crimson]; S30 -> T_WILD_MULTI[ label = "*"];
S30 -> T_WILD_ONE [ label = "<else,1>", color=crimson, fontcolor=crimson];
S31 -> T_SEPARATOR [ label = "="];
S31 -> T_COLON [ label = "<else,1>", color=crimson, fontcolor=crimson];
} }
*/ */
@ -191,31 +193,32 @@ typedef struct rcl_lexer_state_t
#define S28 28u #define S28 28u
#define S29 29u #define S29 29u
#define S30 30u #define S30 30u
#define LAST_STATE S30 #define S31 31u
#define LAST_STATE S31
#define T_TILDE_SLASH 31u #define T_TILDE_SLASH 32u
#define T_URL_SERVICE 32u #define T_URL_SERVICE 33u
#define T_URL_TOPIC 33u #define T_URL_TOPIC 34u
#define T_COLON 34u #define T_COLON 35u
#define T_NODE 35u #define T_NODE 36u
#define T_NS 36u #define T_NS 37u
#define T_SEPARATOR 37u #define T_SEPARATOR 38u
#define T_BR1 38u #define T_BR1 39u
#define T_BR2 39u #define T_BR2 40u
#define T_BR3 40u #define T_BR3 41u
#define T_BR4 41u #define T_BR4 42u
#define T_BR5 42u #define T_BR5 43u
#define T_BR6 43u #define T_BR6 44u
#define T_BR7 44u #define T_BR7 45u
#define T_BR8 45u #define T_BR8 46u
#define T_BR9 46u #define T_BR9 47u
#define T_TOKEN 47u #define T_TOKEN 48u
#define T_FORWARD_SLASH 48u #define T_FORWARD_SLASH 49u
#define T_WILD_ONE 49u #define T_WILD_ONE 50u
#define T_WILD_MULTI 50u #define T_WILD_MULTI 51u
#define T_EOF 51u #define T_EOF 52u
#define T_NONE 52u #define T_NONE 53u
#define T_DOT 53u #define T_DOT 54u
// used to figure out if a state is terminal or not // used to figure out if a state is terminal or not
#define FIRST_TERMINAL T_TILDE_SLASH #define FIRST_TERMINAL T_TILDE_SLASH
@ -236,12 +239,12 @@ static const rcl_lexer_state_t g_states[LAST_STATE + 1] =
{S1, '\\', '\\'}, {S1, '\\', '\\'},
{S2, '~', '~'}, {S2, '~', '~'},
{S3, '_', '_'}, {S3, '_', '_'},
{S8, 'a', 'q'}, {S9, 'a', 'q'},
{S8, 's', 'z'}, {S9, 's', 'z'},
{S8, 'A', 'Z'}, {S9, 'A', 'Z'},
{S10, 'r', 'r'}, {S11, 'r', 'r'},
{S29, '*', '*'}, {S30, '*', '*'},
{S30, ':', ':'}, {S31, ':', ':'},
END_TRANSITIONS END_TRANSITIONS
} }
}, },
@ -273,7 +276,7 @@ static const rcl_lexer_state_t g_states[LAST_STATE + 1] =
}, },
// S3 // S3
{ {
S9, S10,
1u, 1u,
{ {
{S4, '_', '_'}, {S4, '_', '_'},
@ -296,6 +299,7 @@ static const rcl_lexer_state_t g_states[LAST_STATE + 1] =
{ {
{T_NS, 's', 's'}, {T_NS, 's', 's'},
{S6, 'o', 'o'}, {S6, 'o', 'o'},
{S7, 'a', 'a'},
END_TRANSITIONS END_TRANSITIONS
} }
}, },
@ -304,7 +308,7 @@ static const rcl_lexer_state_t g_states[LAST_STATE + 1] =
T_NONE, T_NONE,
0u, 0u,
{ {
{S7, 'd', 'd'}, {S8, 'd', 'd'},
END_TRANSITIONS END_TRANSITIONS
} }
}, },
@ -313,19 +317,16 @@ static const rcl_lexer_state_t g_states[LAST_STATE + 1] =
T_NONE, T_NONE,
0u, 0u,
{ {
{T_NODE, 'e', 'e'}, {S8, 'm', 'm'},
END_TRANSITIONS END_TRANSITIONS
} }
}, },
// S8 // S8
{ {
T_TOKEN, T_NONE,
1u, 0u,
{ {
{S8, 'a', 'z'}, {T_NODE, 'e', 'e'},
{S8, 'A', 'Z'},
{S8, '0', '9'},
{S9, '_', '_'},
END_TRANSITIONS END_TRANSITIONS
} }
}, },
@ -334,185 +335,197 @@ static const rcl_lexer_state_t g_states[LAST_STATE + 1] =
T_TOKEN, T_TOKEN,
1u, 1u,
{ {
{S8, 'a', 'z'}, {S9, 'a', 'z'},
{S8, 'A', 'Z'}, {S9, 'A', 'Z'},
{S8, '0', '9'}, {S9, '0', '9'},
{S10, '_', '_'},
END_TRANSITIONS END_TRANSITIONS
} }
}, },
// S10 // S10
{ {
S8, T_TOKEN,
1u, 1u,
{ {
{S11, 'o', 'o'}, {S9, 'a', 'z'},
{S9, 'A', 'Z'},
{S9, '0', '9'},
END_TRANSITIONS END_TRANSITIONS
} }
}, },
// S11 // S11
{ {
S8, S9,
1u, 1u,
{ {
{S12, 's', 's'}, {S12, 'o', 'o'},
END_TRANSITIONS END_TRANSITIONS
} }
}, },
// S12 // S12
{ {
S8, S9,
1u, 1u,
{ {
{S13, 't', 't'}, {S13, 's', 's'},
{S20, 's', 's'},
END_TRANSITIONS END_TRANSITIONS
} }
}, },
// S13 // S13
{ {
S8, S9,
1u, 1u,
{ {
{S14, 'o', 'o'}, {S14, 't', 't'},
{S21, 's', 's'},
END_TRANSITIONS END_TRANSITIONS
} }
}, },
// S14 // S14
{ {
S8, S9,
1u, 1u,
{ {
{S15, 'p', 'p'}, {S15, 'o', 'o'},
END_TRANSITIONS END_TRANSITIONS
} }
}, },
// S15 // S15
{ {
S8, S9,
1u, 1u,
{ {
{S16, 'i', 'i'}, {S16, 'p', 'p'},
END_TRANSITIONS END_TRANSITIONS
} }
}, },
// S16 // S16
{ {
S8, S9,
1u, 1u,
{ {
{S17, 'c', 'c'}, {S17, 'i', 'i'},
END_TRANSITIONS END_TRANSITIONS
} }
}, },
// S17 // S17
{ {
S8, S9,
1u, 1u,
{ {
{S18, ':', ':'}, {S18, 'c', 'c'},
END_TRANSITIONS END_TRANSITIONS
} }
}, },
// S18 // S18
{ {
S8, S9,
2u, 1u,
{ {
{S19, '/', '/'}, {S19, ':', ':'},
END_TRANSITIONS END_TRANSITIONS
} }
}, },
// S19 // S19
{ {
S8, S9,
2u,
{
{S20, '/', '/'},
END_TRANSITIONS
}
},
// S20
{
S9,
3u, 3u,
{ {
{T_URL_TOPIC, '/', '/'}, {T_URL_TOPIC, '/', '/'},
END_TRANSITIONS END_TRANSITIONS
} }
}, },
// S20 // S21
{ {
S8, S9,
1u, 1u,
{ {
{S21, 'e', 'e'}, {S22, 'e', 'e'},
END_TRANSITIONS END_TRANSITIONS
} }
}, },
// S21 // S21
{ {
S8, S9,
1u, 1u,
{ {
{S22, 'r', 'r'}, {S23, 'r', 'r'},
END_TRANSITIONS
}
},
// S22
{
S8,
1u,
{
{S23, 'v', 'v'},
END_TRANSITIONS END_TRANSITIONS
} }
}, },
// S23 // S23
{ {
S8, S9,
1u, 1u,
{ {
{S24, 'i', 'i'}, {S24, 'v', 'v'},
END_TRANSITIONS END_TRANSITIONS
} }
}, },
// S24 // S24
{ {
S8, S9,
1u, 1u,
{ {
{S25, 'c', 'c'}, {S25, 'i', 'i'},
END_TRANSITIONS END_TRANSITIONS
} }
}, },
// S25 // S25
{ {
S8, S9,
1u, 1u,
{ {
{S26, 'e', 'e'}, {S26, 'c', 'c'},
END_TRANSITIONS END_TRANSITIONS
} }
}, },
// S26 // S26
{ {
S8, S9,
1u, 1u,
{ {
{S27, ':', ':'}, {S27, 'e', 'e'},
END_TRANSITIONS END_TRANSITIONS
} }
}, },
// S27 // S27
{ {
S8, S9,
2u, 1u,
{ {
{S28, '/', '/'}, {S28, ':', ':'},
END_TRANSITIONS END_TRANSITIONS
} }
}, },
// S28 // S28
{ {
S8, S9,
2u,
{
{S29, '/', '/'},
END_TRANSITIONS
}
},
// S29
{
S9,
3u, 3u,
{ {
{T_URL_SERVICE, '/', '/'}, {T_URL_SERVICE, '/', '/'},
END_TRANSITIONS END_TRANSITIONS
} }
}, },
// S29 // S30
{ {
T_WILD_ONE, T_WILD_ONE,
1u, 1u,
@ -521,7 +534,7 @@ static const rcl_lexer_state_t g_states[LAST_STATE + 1] =
END_TRANSITIONS END_TRANSITIONS
} }
}, },
// S30 // S31
{ {
T_COLON, T_COLON,
1u, 1u,
@ -529,7 +542,7 @@ static const rcl_lexer_state_t g_states[LAST_STATE + 1] =
{T_SEPARATOR, '=', '='}, {T_SEPARATOR, '=', '='},
END_TRANSITIONS END_TRANSITIONS
} }
}, }
}; };
static const rcl_lexeme_t g_terminals[LAST_TERMINAL + 1] = { static const rcl_lexeme_t g_terminals[LAST_TERMINAL + 1] = {

View file

@ -324,6 +324,19 @@ TEST_F(CLASSNAME(TestLexerFixture, RMW_IMPLEMENTATION), test_ns)
EXPECT_LEX(RCL_LEXEME_NONE, "__n!", "__n!"); EXPECT_LEX(RCL_LEXEME_NONE, "__n!", "__n!");
} }
TEST_F(CLASSNAME(TestLexerFixture, RMW_IMPLEMENTATION), test_name)
{
// Has __name
EXPECT_LEX(RCL_LEXEME_NODE, "__name", "__name");
EXPECT_LEX(RCL_LEXEME_NODE, "__name", "__namessss");
// Things that are almost __name
EXPECT_LEX(RCL_LEXEME_NONE, "__na", "__na");
EXPECT_LEX(RCL_LEXEME_NONE, "__naa", "__naa");
EXPECT_LEX(RCL_LEXEME_NONE, "__nam", "__nam");
EXPECT_LEX(RCL_LEXEME_NONE, "__nama", "__nama");
}
TEST_F(CLASSNAME(TestLexerFixture, RMW_IMPLEMENTATION), test_node) TEST_F(CLASSNAME(TestLexerFixture, RMW_IMPLEMENTATION), test_node)
{ {
// Has __node // Has __node
@ -333,7 +346,7 @@ TEST_F(CLASSNAME(TestLexerFixture, RMW_IMPLEMENTATION), test_node)
// Things that are almost __node // Things that are almost __node
EXPECT_LEX(RCL_LEXEME_NONE, "__", "__"); EXPECT_LEX(RCL_LEXEME_NONE, "__", "__");
EXPECT_LEX(RCL_LEXEME_NONE, "__n", "__n"); EXPECT_LEX(RCL_LEXEME_NONE, "__n", "__n");
EXPECT_LEX(RCL_LEXEME_NONE, "__na", "__na"); EXPECT_LEX(RCL_LEXEME_NONE, "__ne", "__ne");
EXPECT_LEX(RCL_LEXEME_NONE, "__no", "__no"); EXPECT_LEX(RCL_LEXEME_NONE, "__no", "__no");
EXPECT_LEX(RCL_LEXEME_NONE, "__noa", "__noa"); EXPECT_LEX(RCL_LEXEME_NONE, "__noa", "__noa");
EXPECT_LEX(RCL_LEXEME_NONE, "__nod", "__nod"); EXPECT_LEX(RCL_LEXEME_NONE, "__nod", "__nod");