Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GemSpec: parse %q string #4077

Merged
merged 4 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 11 additions & 6 deletions Units/parser-gemspec.r/simple-gemspec.d/expected.tags
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ rspec-support input.gemspec /^ s.add_runtime_dependency "rspec-support", "= #
rspec-support input.gemspec /^ s.add_runtime_dependency "rspec-support", "~> #{RSpec::Core::Version::STRING.split('.')[0..1/;" g roles:runtimeDep
cucumber input.gemspec /^ s.add_development_dependency "cucumber", "~> 1.3"$/;" g roles:develDep
minitest input.gemspec /^ s.add_development_dependency "minitest", "~> 5.3"$/;" g roles:develDep
aruba input.gemspec /^ s.add_development_dependency "aruba", "~> 0.14.9"$/;" g roles:develDep
coderay input.gemspec /^ s.add_development_dependency "coderay", "~> 1.1.1"$/;" g roles:develDep
mocha input.gemspec /^ s.add_development_dependency "mocha", "~> 0.13.0"$/;" g roles:develDep
rr input.gemspec /^ s.add_development_dependency "rr", "~> 1.0.4"$/;" g roles:develDep
flexmock input.gemspec /^ s.add_development_dependency "flexmock", "~> 0.9.0"$/;" g roles:develDep
thread_order input.gemspec /^ s.add_development_dependency "thread_order", "~> 1.1.0"$/;" g roles:develDep
aruba input.gemspec /^ s.add_development_dependency %q{aruba}, "~> 0.14.9"$/;" g roles:develDep
coderay input.gemspec /^ s.add_development_dependency %q[coderay], "~> 1.1.1"$/;" g roles:develDep
mocha input.gemspec /^ s.add_development_dependency %q(mocha), "~> 0.13.0"$/;" g roles:develDep
rr input.gemspec /^ s.add_development_dependency %q<rr>, "~> 1.0.4"$/;" g roles:develDep
flexmock input.gemspec /^ s.add_development_dependency %q flexmock , "~> 0.9.0"$/;" g roles:develDep
thread_order input.gemspec /^ s.add_development_dependency %q!thread_order!, "~> 1.1.0"$/;" g roles:develDep
strange{name}(just){-}<for>{-}{testing} input.gemspec /^ s.add_runtime_dependency %q{strange{name}(just){-}<for>{-}{testing}}.freeze, [">= 1.2.4".freez/;" g roles:runtimeDep
net-ssh input.gemspec /^ s.add_runtime_dependency("net-ssh", ">= 1.0.1")$/;" g roles:runtimeDep
ed25519 input.gemspec /^ s.add_runtime_dependency(%q<ed25519>.freeze, [">= 1.2.4".freeze, "< 1.4".freeze])$/;" g roles:runtimeDep
strange<name>just-for-testing input.gemspec /^ s.add_runtime_dependency(%q<strange<name>just-for-testing>.freeze, [">= 1.2.4".freeze, "< 1.4"/;" g roles:runtimeDep
katello/version input-0.gemspec /^require "katello\/version"$/;" L roles:required
katello input-0.gemspec /^ gem.name = "katello"$/;" g roles:def
rails input-0.gemspec /^ gem.add_dependency "rails"$/;" g roles:runtimeDep
G1 input-1.gemspec /^ gem.name = %q!G1!$/;" g roles:def
4 changes: 4 additions & 0 deletions Units/parser-gemspec.r/simple-gemspec.d/input-1.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Gem::Specification.new do |gem|
gem.name = %q!G1!
# ...
end
17 changes: 11 additions & 6 deletions Units/parser-gemspec.r/simple-gemspec.d/input.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,17 @@ Gem::Specification.new do |s|

s.add_development_dependency "cucumber", "~> 1.3"
s.add_development_dependency "minitest", "~> 5.3"
s.add_development_dependency "aruba", "~> 0.14.9"
s.add_development_dependency %q{aruba}, "~> 0.14.9"

s.add_development_dependency "coderay", "~> 1.1.1"
s.add_development_dependency %q[coderay], "~> 1.1.1"

s.add_development_dependency "mocha", "~> 0.13.0"
s.add_development_dependency "rr", "~> 1.0.4"
s.add_development_dependency "flexmock", "~> 0.9.0"
s.add_development_dependency "thread_order", "~> 1.1.0"
s.add_development_dependency %q(mocha), "~> 0.13.0"
s.add_development_dependency %q<rr>, "~> 1.0.4"
s.add_development_dependency %q flexmock , "~> 0.9.0"
s.add_development_dependency %q!thread_order!, "~> 1.1.0"
s.add_development_dependency %qadonttagmea, "~> 1.1.0"
s.add_runtime_dependency %q{strange{name}(just){-}<for>{-}{testing}}.freeze, [">= 1.2.4".freeze, "< 1.4".freeze]
s.add_runtime_dependency("net-ssh", ">= 1.0.1")
s.add_runtime_dependency(%q<ed25519>.freeze, [">= 1.2.4".freeze, "< 1.4".freeze])
s.add_runtime_dependency(%q<strange<name>just-for-testing>.freeze, [">= 1.2.4".freeze, "< 1.4".freeze])
end
17 changes: 15 additions & 2 deletions parsers/gemspec.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ static int lineNotify (rubySubparser *s, const unsigned char **cp)
if (p)
{
rubySkipWhitespace (&p);
if ((!is_attr) || *p == '=')
if (is_attr == false || *p == '=')
{
if (is_attr)
if (*p == '(' || *p == '=')
{
p++;
rubySkipWhitespace (&p);
Expand All @@ -138,6 +138,19 @@ static int lineNotify (rubySubparser *s, const unsigned char **cp)
}
vStringDelete (gem);
}
else if (p [0] == '%')
{
vString *gem = vStringNew ();
p++;
if (rubyParsePercentString(&p, gem))
{
if (role == ROLE_DEFINITION_INDEX)
makeSimpleTag (gem, kind);
else
makeSimpleRefTag (gem, kind, role);
}
vStringDelete (gem);
}
}
}
}
Expand Down
72 changes: 72 additions & 0 deletions parsers/ruby.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ extern bool rubySkipWhitespace (const unsigned char** cp)
return r;
}

/* TODO: handle double quote if boundary == '"' */
static void parseString (const unsigned char** cp, unsigned char boundary, vString* vstr)
{
while (**cp != 0 && **cp != boundary)
Expand All @@ -431,6 +432,77 @@ extern bool rubyParseString (const unsigned char** cp, unsigned char boundary, v
return (p != *cp);
}

static bool rubyParsePercent_q (const unsigned char** cp, vString* vstr)
{
const unsigned char *p = *cp;
bool recursive;
unsigned char boundary[2];

if (*p == '\0' || isalnum (*p))
return false;

boundary[0] = *p;
boundary[1] = *p;
recursive = false;
switch (*p)
{
case '{':
boundary[1] = '}';
recursive = true;
break;
case '[':
boundary[1] = ']';
recursive = true;
break;
case '(':
boundary[1] = ')';
recursive = true;
break;
case '<':
boundary[1] = '>';
recursive = true;
break;
}
p++;

unsigned int depth = 1;
while (*p != '\0')
{
if (*p == boundary[1])
{
depth--;
if (depth == 0)
{
*cp = p;
return true;
}
}
else if (recursive && boundary[0] == *p)
depth++;
vStringPut (vstr, *p);
p++;
}
return false;
}

extern bool rubyParsePercentString (const unsigned char** cp, vString* vstr)
{
const unsigned char *p = *cp;

switch (*p)
{
case 'q':
++p;
if (rubyParsePercent_q(&p, vstr))
{
*cp = p;
return true;
}
break;
}
return false;
}

/* If the current scope is A.B, and the name is B.C, B is overlapped.
* In that case, the function returns true. Else false.
*/
Expand Down
1 change: 1 addition & 0 deletions parsers/x-ruby.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ extern bool rubyCanMatchKeyword (const unsigned char** s, const char* literal);
extern bool rubyCanMatchKeywordWithAssign (const unsigned char** s, const char* literal);

extern bool rubyParseString (const unsigned char** cp, unsigned char boundary, vString* vstr);
extern bool rubyParsePercentString (const unsigned char** cp, vString* vstr);
extern bool rubyParseMethodName (const unsigned char **cp, vString* vstr);
extern bool rubyParseModuleName (const unsigned char **cp, vString* vstr);

Expand Down
Loading