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

Match (some) onigmo syntax errors #2869

Merged
merged 12 commits into from
Jun 5, 2024
18 changes: 8 additions & 10 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ source "https://rubygems.org"

gemspec

gem "benchmark-ips"
gem "rake"
gem "rake-compiler"
gem "test-unit"

# Some gems we don't want to install on JRuby or TruffleRuby.
platforms = %i[mri mswin mingw x64_mingw]

gem "ffi", platform: platforms
gem "parser", platform: platforms
gem "ruby_parser", platform: platforms
gem "benchmark-ips"
platforms :mri, :mswin, :mingw, :x64_mingw do
gem "ffi"
gem "parser"
gem "ruby_memcheck"
gem "ruby_parser"
end

group :memcheck do
gem "ruby_memcheck", platform: platforms
end
gem "onigmo", platforms: :ruby
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ GEM
nokogiri (1.16.5)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
onigmo (0.1.0)
parser (3.3.1.0)
ast (~> 2.4.1)
racc
Expand All @@ -36,6 +37,7 @@ PLATFORMS
DEPENDENCIES
benchmark-ips
ffi
onigmo
parser
prism!
rake
Expand Down
3 changes: 2 additions & 1 deletion config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ errors:
- PARAMETER_SPLAT_MULTI
- PARAMETER_STAR
- PARAMETER_UNEXPECTED_FWD
- PARAMETER_WILD_LOOSE_COMMA
- PARAMETER_UNEXPECTED_NO_KW
- PARAMETER_WILD_LOOSE_COMMA
- PATTERN_CAPTURE_DUPLICATE
- PATTERN_EXPRESSION_AFTER_BRACKET
- PATTERN_EXPRESSION_AFTER_COMMA
Expand Down Expand Up @@ -236,6 +236,7 @@ errors:
- REGEXP_INCOMPAT_CHAR_ENCODING
- REGEXP_INVALID_UNICODE_RANGE
- REGEXP_NON_ESCAPED_MBC
- REGEXP_PARSE_ERROR
- REGEXP_TERM
- REGEXP_UNKNOWN_OPTIONS
- REGEXP_UTF8_CHAR_NON_UTF8_REGEXP
Expand Down
2 changes: 1 addition & 1 deletion docs/fuzzing.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fuzz
There are currently three fuzzing targets

- `pm_serialize_parse` (parse)
- `pm_regexp_named_capture_group_names` (regexp)
- `pm_regexp_parse` (regexp)

Respectively, fuzzing can be performed with

Expand Down
19 changes: 16 additions & 3 deletions fuzz/regexp.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
#include <prism.h>

void
regexp_name_callback(const pm_string_t *name, void *data) {
// Do nothing
}

void
regexp_error_callback(const uint8_t *start, const uint8_t *end, const char *message, void *data) {
// Do nothing
}

void
harness(const uint8_t *input, size_t size) {
pm_string_list_t capture_list = { 0 };
pm_regexp_named_capture_group_names(input, size, &capture_list, false, PM_ENCODING_UTF_8_ENTRY);
pm_string_list_free(&capture_list);
pm_parser_t parser;
pm_parser_init(&parser, input, size, NULL);

pm_regexp_parse(&parser, input, size, regexp_name_callback, NULL, regexp_error_callback, NULL);

pm_parser_free(&parser);
}
3 changes: 2 additions & 1 deletion gemfiles/2.7/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ ruby "~> 2.7.0"
gemspec path: "../.."

gem "ffi"
gem "onigmo", platforms: :ruby
gem "parser"
gem "rake"
gem "rake-compiler"
gem "rake"
gem "rbs"
gem "test-unit"
2 changes: 2 additions & 0 deletions gemfiles/2.7/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ GEM
specs:
ast (2.4.2)
ffi (1.16.3)
onigmo (0.1.0)
parser (3.3.2.0)
ast (~> 2.4.1)
racc
Expand All @@ -25,6 +26,7 @@ PLATFORMS

DEPENDENCIES
ffi
onigmo
parser
prism!
rake
Expand Down
3 changes: 2 additions & 1 deletion gemfiles/3.0/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ ruby "~> 3.0.0"
gemspec path: "../.."

gem "ffi"
gem "onigmo", platforms: :ruby
gem "parser"
gem "rake"
gem "rake-compiler"
gem "rake"
gem "rbs"
gem "ruby_memcheck"
gem "test-unit"
2 changes: 2 additions & 0 deletions gemfiles/3.0/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ GEM
nokogiri (1.16.5)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
onigmo (0.1.0)
parser (3.3.2.0)
ast (~> 2.4.1)
racc
Expand All @@ -33,6 +34,7 @@ PLATFORMS

DEPENDENCIES
ffi
onigmo
parser
prism!
rake
Expand Down
3 changes: 2 additions & 1 deletion gemfiles/3.1/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ ruby "~> 3.1.0"
gemspec path: "../.."

gem "ffi"
gem "onigmo", platforms: :ruby
gem "parser"
gem "rake"
gem "rake-compiler"
gem "rake"
gem "rbs"
gem "ruby_memcheck"
gem "test-unit"
2 changes: 2 additions & 0 deletions gemfiles/3.1/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ GEM
nokogiri (1.16.5)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
onigmo (0.1.0)
parser (3.3.2.0)
ast (~> 2.4.1)
racc
Expand All @@ -33,6 +34,7 @@ PLATFORMS

DEPENDENCIES
ffi
onigmo
parser
prism!
rake
Expand Down
3 changes: 2 additions & 1 deletion gemfiles/3.2/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ ruby "~> 3.2.0"
gemspec path: "../.."

gem "ffi"
gem "onigmo", platforms: :ruby
gem "parser"
gem "rake"
gem "rake-compiler"
gem "rake"
gem "rbs"
gem "ruby_memcheck"
gem "test-unit"
2 changes: 2 additions & 0 deletions gemfiles/3.2/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ GEM
nokogiri (1.16.5)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
onigmo (0.1.0)
parser (3.3.2.0)
ast (~> 2.4.1)
racc
Expand All @@ -33,6 +34,7 @@ PLATFORMS

DEPENDENCIES
ffi
onigmo
parser
prism!
rake
Expand Down
3 changes: 2 additions & 1 deletion gemfiles/3.3/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ ruby "~> 3.3.0"
gemspec path: "../.."

gem "ffi"
gem "onigmo", platforms: :ruby
gem "parser"
gem "rake"
gem "rake-compiler"
gem "rake"
gem "rbs"
gem "ruby_memcheck"
gem "test-unit"
2 changes: 2 additions & 0 deletions gemfiles/3.3/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ GEM
nokogiri (1.16.5)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
onigmo (0.1.0)
parser (3.3.2.0)
ast (~> 2.4.1)
racc
Expand All @@ -33,6 +34,7 @@ PLATFORMS

DEPENDENCIES
ffi
onigmo
parser
prism!
rake
Expand Down
3 changes: 2 additions & 1 deletion gemfiles/3.4/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ ruby "~> 3.4.0.dev"
gemspec path: "../.."

gem "ffi"
gem "onigmo", platforms: :ruby
gem "parser"
gem "rake"
gem "rake-compiler"
gem "rake"
gem "rbs"
gem "ruby_memcheck"
gem "test-unit"
2 changes: 2 additions & 0 deletions gemfiles/3.4/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ GEM
nokogiri (1.16.5)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
onigmo (0.1.0)
parser (3.3.2.0)
ast (~> 2.4.1)
racc
Expand All @@ -33,6 +34,7 @@ PLATFORMS

DEPENDENCIES
ffi
onigmo
parser
prism!
rake
Expand Down
25 changes: 17 additions & 8 deletions include/prism/regexp.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,33 @@
#include "prism/parser.h"
#include "prism/encoding.h"
#include "prism/util/pm_memchr.h"
#include "prism/util/pm_string_list.h"
#include "prism/util/pm_string.h"

#include <stdbool.h>
#include <stddef.h>
#include <string.h>

/**
* Parse a regular expression and extract the names of all of the named capture
* groups.
* This callback is called when a named capture group is found.
*/
typedef void (*pm_regexp_name_callback_t)(const pm_string_t *name, void *data);

/**
* This callback is called when a parse error is found.
*/
typedef void (*pm_regexp_error_callback_t)(const uint8_t *start, const uint8_t *end, const char *message, void *data);

/**
* Parse a regular expression.
*
* @param parser The parser that is currently being used.
* @param source The source code to parse.
* @param size The size of the source code.
* @param named_captures The list to add the names of the named capture groups.
* @param encoding_changed Whether or not the encoding changed from the default.
* @param encoding The encoding of the source code.
* @return Whether or not the parsing was successful.
* @param name_callback The optional callback to call when a named capture group is found.
* @param name_data The optional data to pass to the name callback.
* @param error_callback The callback to call when a parse error is found.
* @param error_data The data to pass to the error callback.
*/
PRISM_EXPORTED_FUNCTION bool pm_regexp_named_capture_group_names(const uint8_t *source, size_t size, pm_string_list_t *named_captures, bool encoding_changed, const pm_encoding_t *encoding);
PRISM_EXPORTED_FUNCTION void pm_regexp_parse(pm_parser_t *parser, const uint8_t *source, size_t size, pm_regexp_name_callback_t name_callback, void *name_data, pm_regexp_error_callback_t error_callback, void *error_data);

#endif
44 changes: 0 additions & 44 deletions include/prism/util/pm_string_list.h

This file was deleted.

2 changes: 0 additions & 2 deletions prism.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ Gem::Specification.new do |spec|
"include/prism/util/pm_newline_list.h",
"include/prism/util/pm_strncasecmp.h",
"include/prism/util/pm_string.h",
"include/prism/util/pm_string_list.h",
"include/prism/util/pm_strpbrk.h",
"include/prism/version.h",
"lib/prism.rb",
Expand Down Expand Up @@ -148,7 +147,6 @@ Gem::Specification.new do |spec|
"src/util/pm_list.c",
"src/util/pm_memchr.c",
"src/util/pm_newline_list.c",
"src/util/pm_string_list.c",
"src/util/pm_string.c",
"src/util/pm_strncasecmp.c",
"src/util/pm_strpbrk.c"
Expand Down
Loading
Loading