Skip to content

Commit

Permalink
Ruby,refactor: handle symbols in parseIdentifier
Browse files Browse the repository at this point in the history
parseIdentifier() handled symbols, ':' prefixed identifiers partially.
However, it was not perfect. So callers handled ':' in their side.

This change moves the resposiblity handling ':' from the callers to
parseIdentifier(). The complexity about reading identifiers
represented in various ways: name, :name, :'name', and :"name" can
be handled in one place, parseIdentifier().

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
  • Loading branch information
masatake committed Sep 4, 2022
1 parent 1e2e351 commit aaa391f
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions parsers/ruby.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,18 +463,23 @@ static rubyKind parseIdentifier (
}

/* Copy the identifier into 'name'. */
if (**cp == ':' && (*((*cp) + 1) == '"' || *((*cp) + 1) == '\''))
if (**cp == ':')
{
/* The symbol is defined with string literal like:
----
:"[]"
:"[]="
----
*/
unsigned char b = *(++*cp);
if (*((*cp) + 1) == '"' || *((*cp) + 1) == '\'')
{
/* The symbol is defined with string literal like:
----
:"[]"
:"[]="
----
*/
unsigned char b = *(++*cp);
++*cp;
parseString (cp, b, name);
return kind;
}
/* May be symbol like :name. Skip the first character. */
++*cp;
parseString (cp, b, name);
return kind;
}

while (**cp != 0 && (**cp == ':' || isIdentChar (**cp) || charIsIn (**cp, also_ok)))
Expand Down Expand Up @@ -810,7 +815,6 @@ static void readAttrsAndEmitTags (const unsigned char **cp, bool reader, bool wr
skipWhitespace (cp);
if (**cp == ':')
{
++*cp;
if (K_METHOD == parseIdentifier (cp, a, K_METHOD))
{
emitRubyAccessorTags (a, reader, writer);
Expand Down Expand Up @@ -854,7 +858,6 @@ static int readAliasMethodAndEmitTags (const unsigned char **cp)
skipWhitespace (cp);
if (**cp == ':')
{
++*cp;
if (K_METHOD != parseIdentifier (cp, a, K_METHOD))
vStringClear (a);
}
Expand Down

0 comments on commit aaa391f

Please sign in to comment.