From e0a30d2efcac5a66b892df23eb21f70d3d5a4edb Mon Sep 17 00:00:00 2001 From: m11o Date: Mon, 16 Oct 2023 00:57:36 +0900 Subject: [PATCH 1/2] Add types for Regexp::Parser#parse in regexp_parser gem Add RBS file for regexp_parser@v2.8 ref: https://github.com/ammar/regexp_parsers --- .gitmodules | 3 +++ gems/regexp_parser/2.8/_scripts/test | 21 +++++++++++++++++++++ gems/regexp_parser/2.8/_src | 1 + gems/regexp_parser/2.8/_test/Steepfile | 11 +++++++++++ gems/regexp_parser/2.8/_test/test.rb | 13 +++++++++++++ gems/regexp_parser/2.8/regexp_parser.rbs | 17 +++++++++++++++++ 6 files changed, 66 insertions(+) create mode 100755 gems/regexp_parser/2.8/_scripts/test create mode 160000 gems/regexp_parser/2.8/_src create mode 100644 gems/regexp_parser/2.8/_test/Steepfile create mode 100644 gems/regexp_parser/2.8/_test/test.rb create mode 100644 gems/regexp_parser/2.8/regexp_parser.rbs diff --git a/.gitmodules b/.gitmodules index 7952d1f2..9170faf5 100644 --- a/.gitmodules +++ b/.gitmodules @@ -202,3 +202,6 @@ [submodule "gems/recaptcha/5.15/_src"] path = gems/recaptcha/5.15/_src url = https://github.com/ambethia/recaptcha.git +[submodule "gems/regexp_parser/2.8/_src"] + path = gems/regexp_parser/2.8/_src + url = https://github.com/ammar/regexp_parser.git diff --git a/gems/regexp_parser/2.8/_scripts/test b/gems/regexp_parser/2.8/_scripts/test new file mode 100755 index 00000000..9b6f8a77 --- /dev/null +++ b/gems/regexp_parser/2.8/_scripts/test @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +# Exit command with non-zero status code, Output logs of every command executed, Treat unset variables as an error when substituting. +set -eou pipefail +# Internal Field Separator - Linux shell variable +IFS=$'\n\t' +# Print shell input lines +set -v + +# Set RBS_DIR variable to change directory to execute type checks using `steep check` +RBS_DIR=$(cd $(dirname $0)/..; pwd) +# Set REPO_DIR variable to validate RBS files added to the corresponding folder +REPO_DIR=$(cd $(dirname $0)/../../..; pwd) +# Validate RBS files, using the bundler environment present +bundle exec rbs --repo $REPO_DIR -r regexp_parser:2.8 validate --silent + +cd ${RBS_DIR}/_test +# Run type checks +bundle exec steep check + +$(git rev-parse --show-toplevel)/bin/check-untyped-call.rb diff --git a/gems/regexp_parser/2.8/_src b/gems/regexp_parser/2.8/_src new file mode 160000 index 00000000..69a7f050 --- /dev/null +++ b/gems/regexp_parser/2.8/_src @@ -0,0 +1 @@ +Subproject commit 69a7f050249f679ce33421a99b55c22427019d5d diff --git a/gems/regexp_parser/2.8/_test/Steepfile b/gems/regexp_parser/2.8/_test/Steepfile new file mode 100644 index 00000000..11a6300e --- /dev/null +++ b/gems/regexp_parser/2.8/_test/Steepfile @@ -0,0 +1,11 @@ +D = Steep::Diagnostic + +target :test do + check "." + signature "." + + repo_path "../../../" + library "regexp_parser" + + configure_code_diagnostics(D::Ruby.all_error) +end diff --git a/gems/regexp_parser/2.8/_test/test.rb b/gems/regexp_parser/2.8/_test/test.rb new file mode 100644 index 00000000..75f7cd78 --- /dev/null +++ b/gems/regexp_parser/2.8/_test/test.rb @@ -0,0 +1,13 @@ +# Write Ruby code to test the RBS. +# It is type checked by `steep check` command. + +require "regexp_parser" + +regex = /a?(b+(c)d)*(?[0-9]+)/i +Regexp::Parser.parse(regex, 'ruby/2.1') do |token| + puts token.inspect +end +Regexp::Parser.parse( + 'a+ # Recognizes a and A...', + options: ::Regexp::EXTENDED | ::Regexp::IGNORECASE +) diff --git a/gems/regexp_parser/2.8/regexp_parser.rbs b/gems/regexp_parser/2.8/regexp_parser.rbs new file mode 100644 index 00000000..a99b0c40 --- /dev/null +++ b/gems/regexp_parser/2.8/regexp_parser.rbs @@ -0,0 +1,17 @@ +class Regexp::Parser + def parse: (Regexp | String input, ?String? syntax, ?options: Integer?) { (Regexp::Expression::Root) -> untyped } -> untyped + | (Regexp | String input, ?String? syntax, ?options: Integer?) -> Regexp::Expression::Root + def self.parse: (Regexp | String input, ?String? syntax, ?options: Integer?) { (Regexp::Expression::Root) -> untyped } -> untyped + | (Regexp | String input, ?String? syntax, ?options: Integer?) -> Regexp::Expression::Root +end + +module Regexp::Expression + class Root < Subexpression + end + + class Subexpression < Base + end + + class Base + end +end From eb667d0cec74a1740a9035159d5c6999656b7de4 Mon Sep 17 00:00:00 2001 From: m11o Date: Mon, 16 Oct 2023 14:27:26 +0900 Subject: [PATCH 2/2] fix format --- gems/regexp_parser/2.8/regexp_parser.rbs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gems/regexp_parser/2.8/regexp_parser.rbs b/gems/regexp_parser/2.8/regexp_parser.rbs index a99b0c40..ad75bffc 100644 --- a/gems/regexp_parser/2.8/regexp_parser.rbs +++ b/gems/regexp_parser/2.8/regexp_parser.rbs @@ -1,8 +1,8 @@ class Regexp::Parser def parse: (Regexp | String input, ?String? syntax, ?options: Integer?) { (Regexp::Expression::Root) -> untyped } -> untyped - | (Regexp | String input, ?String? syntax, ?options: Integer?) -> Regexp::Expression::Root + | (Regexp | String input, ?String? syntax, ?options: Integer?) -> Regexp::Expression::Root def self.parse: (Regexp | String input, ?String? syntax, ?options: Integer?) { (Regexp::Expression::Root) -> untyped } -> untyped - | (Regexp | String input, ?String? syntax, ?options: Integer?) -> Regexp::Expression::Root + | (Regexp | String input, ?String? syntax, ?options: Integer?) -> Regexp::Expression::Root end module Regexp::Expression