rbs 3.10.0 → 4.0.0.dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/comments.yml +3 -3
- data/.github/workflows/ruby.yml +24 -35
- data/.github/workflows/typecheck.yml +3 -1
- data/.github/workflows/windows.yml +2 -2
- data/.gitignore +0 -4
- data/CHANGELOG.md +0 -88
- data/README.md +1 -38
- data/Rakefile +20 -142
- data/Steepfile +1 -0
- data/config.yml +43 -1
- data/core/array.rbs +46 -100
- data/core/complex.rbs +21 -32
- data/core/dir.rbs +2 -2
- data/core/encoding.rbs +9 -6
- data/core/enumerable.rbs +3 -90
- data/core/enumerator.rbs +1 -18
- data/core/errno.rbs +0 -8
- data/core/errors.rbs +1 -28
- data/core/exception.rbs +2 -2
- data/core/fiber.rbs +4 -5
- data/core/file.rbs +12 -27
- data/core/file_test.rbs +1 -1
- data/core/float.rbs +22 -209
- data/core/gc.rbs +281 -417
- data/core/hash.rbs +727 -1024
- data/core/integer.rbs +38 -78
- data/core/io/buffer.rbs +7 -18
- data/core/io/wait.rbs +33 -11
- data/core/io.rbs +12 -14
- data/core/kernel.rbs +51 -57
- data/core/marshal.rbs +1 -1
- data/core/match_data.rbs +1 -1
- data/core/math.rbs +3 -42
- data/core/method.rbs +6 -14
- data/core/module.rbs +17 -88
- data/core/nil_class.rbs +3 -3
- data/core/numeric.rbs +16 -16
- data/core/object.rbs +3 -3
- data/core/object_space.rbs +15 -21
- data/core/proc.rbs +8 -15
- data/core/process.rbs +2 -2
- data/core/ractor.rbs +437 -278
- data/core/range.rbs +8 -7
- data/core/rational.rbs +24 -37
- data/core/rbs/unnamed/argf.rbs +2 -2
- data/core/rbs/unnamed/env_class.rbs +1 -1
- data/core/rbs/unnamed/random.rbs +2 -4
- data/core/regexp.rbs +20 -25
- data/core/ruby_vm.rbs +4 -6
- data/core/rubygems/errors.rbs +70 -3
- data/core/rubygems/rubygems.rbs +79 -11
- data/core/rubygems/version.rbs +3 -2
- data/core/set.rbs +359 -488
- data/core/string.rbs +1228 -3153
- data/core/struct.rbs +1 -1
- data/core/symbol.rbs +4 -4
- data/core/thread.rbs +29 -92
- data/core/time.rbs +9 -35
- data/core/trace_point.rbs +4 -7
- data/core/unbound_method.rbs +6 -14
- data/docs/collection.md +2 -2
- data/docs/gem.md +1 -0
- data/docs/sigs.md +3 -3
- data/ext/rbs_extension/ast_translation.c +1077 -944
- data/ext/rbs_extension/ast_translation.h +0 -7
- data/ext/rbs_extension/class_constants.c +83 -71
- data/ext/rbs_extension/class_constants.h +7 -4
- data/ext/rbs_extension/extconf.rb +2 -24
- data/ext/rbs_extension/legacy_location.c +172 -173
- data/ext/rbs_extension/legacy_location.h +3 -8
- data/ext/rbs_extension/main.c +289 -239
- data/ext/rbs_extension/rbs_extension.h +0 -3
- data/ext/rbs_extension/rbs_string_bridging.h +0 -4
- data/include/rbs/ast.h +98 -37
- data/include/rbs/defines.h +12 -38
- data/include/rbs/lexer.h +114 -126
- data/include/rbs/location.h +14 -14
- data/include/rbs/parser.h +37 -21
- data/include/rbs/string.h +5 -3
- data/include/rbs/util/rbs_allocator.h +19 -40
- data/include/rbs/util/rbs_assert.h +1 -12
- data/include/rbs/util/rbs_constant_pool.h +3 -3
- data/include/rbs/util/rbs_encoding.h +1 -3
- data/include/rbs/util/rbs_unescape.h +1 -2
- data/lib/rbs/ast/ruby/annotations.rb +119 -0
- data/lib/rbs/ast/ruby/comment_block.rb +221 -0
- data/lib/rbs/ast/ruby/declarations.rb +86 -0
- data/lib/rbs/ast/ruby/helpers/constant_helper.rb +24 -0
- data/lib/rbs/ast/ruby/helpers/location_helper.rb +15 -0
- data/lib/rbs/ast/ruby/members.rb +213 -0
- data/lib/rbs/buffer.rb +104 -24
- data/lib/rbs/cli/validate.rb +40 -35
- data/lib/rbs/cli.rb +5 -6
- data/lib/rbs/collection/config/lockfile_generator.rb +0 -1
- data/lib/rbs/collection.rb +0 -1
- data/lib/rbs/definition.rb +6 -1
- data/lib/rbs/definition_builder/ancestor_builder.rb +65 -62
- data/lib/rbs/definition_builder/method_builder.rb +45 -30
- data/lib/rbs/definition_builder.rb +44 -9
- data/lib/rbs/environment/class_entry.rb +69 -0
- data/lib/rbs/environment/module_entry.rb +66 -0
- data/lib/rbs/environment.rb +244 -218
- data/lib/rbs/environment_loader.rb +3 -3
- data/lib/rbs/errors.rb +5 -4
- data/lib/rbs/inline_parser/comment_association.rb +117 -0
- data/lib/rbs/inline_parser.rb +206 -0
- data/lib/rbs/location_aux.rb +35 -3
- data/lib/rbs/parser_aux.rb +11 -6
- data/lib/rbs/prototype/runtime.rb +2 -2
- data/lib/rbs/resolver/constant_resolver.rb +2 -2
- data/lib/rbs/resolver/type_name_resolver.rb +38 -124
- data/lib/rbs/source.rb +99 -0
- data/lib/rbs/subtractor.rb +4 -3
- data/lib/rbs/test/type_check.rb +0 -14
- data/lib/rbs/types.rb +1 -3
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs.rb +13 -1
- data/lib/rdoc/discover.rb +1 -1
- data/lib/rdoc_plugin/parser.rb +1 -1
- data/rbs.gemspec +1 -0
- data/sig/ancestor_builder.rbs +1 -1
- data/sig/ast/ruby/annotations.rbs +110 -0
- data/sig/ast/ruby/comment_block.rbs +119 -0
- data/sig/ast/ruby/declarations.rbs +60 -0
- data/sig/ast/ruby/helpers/constant_helper.rbs +11 -0
- data/sig/ast/ruby/helpers/location_helper.rbs +15 -0
- data/sig/ast/ruby/members.rbs +72 -0
- data/sig/buffer.rbs +63 -5
- data/sig/definition.rbs +1 -0
- data/sig/definition_builder.rbs +1 -1
- data/sig/environment/class_entry.rbs +50 -0
- data/sig/environment/module_entry.rbs +50 -0
- data/sig/environment.rbs +28 -133
- data/sig/errors.rbs +13 -6
- data/sig/inline_parser/comment_association.rbs +71 -0
- data/sig/inline_parser.rbs +87 -0
- data/sig/location.rbs +32 -7
- data/sig/manifest.yaml +1 -0
- data/sig/method_builder.rbs +7 -4
- data/sig/parser.rbs +16 -20
- data/sig/resolver/type_name_resolver.rbs +7 -38
- data/sig/source.rbs +48 -0
- data/sig/types.rbs +1 -4
- data/src/ast.c +290 -201
- data/src/lexer.c +2813 -2902
- data/src/lexer.re +4 -0
- data/src/lexstate.c +155 -169
- data/src/location.c +40 -40
- data/src/parser.c +2665 -2433
- data/src/string.c +48 -0
- data/src/util/rbs_allocator.c +77 -80
- data/src/util/rbs_assert.c +10 -10
- data/src/util/rbs_buffer.c +2 -2
- data/src/util/rbs_constant_pool.c +15 -13
- data/src/util/rbs_encoding.c +4062 -20097
- data/src/util/rbs_unescape.c +48 -85
- data/stdlib/bigdecimal/0/big_decimal.rbs +82 -100
- data/stdlib/bigdecimal-math/0/big_math.rbs +8 -169
- data/stdlib/cgi/0/core.rbs +396 -2
- data/stdlib/cgi/0/manifest.yaml +0 -1
- data/stdlib/coverage/0/coverage.rbs +1 -3
- data/stdlib/date/0/date.rbs +59 -67
- data/stdlib/date/0/date_time.rbs +1 -1
- data/stdlib/delegate/0/delegator.rbs +7 -10
- data/stdlib/erb/0/erb.rbs +347 -737
- data/stdlib/fileutils/0/fileutils.rbs +13 -18
- data/stdlib/forwardable/0/forwardable.rbs +0 -3
- data/stdlib/json/0/json.rbs +48 -68
- data/stdlib/net-http/0/net-http.rbs +0 -3
- data/stdlib/objspace/0/objspace.rbs +4 -9
- data/stdlib/open-uri/0/open-uri.rbs +0 -40
- data/stdlib/openssl/0/openssl.rbs +228 -331
- data/stdlib/optparse/0/optparse.rbs +3 -3
- data/{core → stdlib/pathname/0}/pathname.rbs +355 -255
- data/stdlib/psych/0/psych.rbs +3 -3
- data/stdlib/rdoc/0/rdoc.rbs +1 -1
- data/stdlib/resolv/0/resolv.rbs +68 -25
- data/stdlib/ripper/0/ripper.rbs +2 -5
- data/stdlib/singleton/0/singleton.rbs +0 -3
- data/stdlib/socket/0/socket.rbs +1 -13
- data/stdlib/socket/0/tcp_socket.rbs +2 -10
- data/stdlib/stringio/0/stringio.rbs +85 -1176
- data/stdlib/strscan/0/string_scanner.rbs +31 -31
- data/stdlib/tempfile/0/tempfile.rbs +3 -3
- data/stdlib/time/0/time.rbs +1 -1
- data/stdlib/timeout/0/timeout.rbs +7 -63
- data/stdlib/tsort/0/cyclic.rbs +0 -3
- data/stdlib/uri/0/common.rbs +2 -11
- data/stdlib/uri/0/file.rbs +1 -1
- data/stdlib/uri/0/generic.rbs +16 -17
- data/stdlib/uri/0/rfc2396_parser.rbs +7 -6
- data/stdlib/zlib/0/zstream.rbs +0 -1
- metadata +40 -12
- data/.clang-format +0 -74
- data/.clangd +0 -2
- data/.github/workflows/c-check.yml +0 -54
- data/core/ruby.rbs +0 -53
- data/docs/aliases.md +0 -79
- data/docs/encoding.md +0 -56
- data/ext/rbs_extension/compat.h +0 -10
- data/stdlib/cgi-escape/0/escape.rbs +0 -153
data/.clang-format
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
Language: Cpp
|
|
3
|
-
|
|
4
|
-
# Indentation
|
|
5
|
-
UseTab: Never
|
|
6
|
-
IndentWidth: 4
|
|
7
|
-
BreakBeforeBraces: Attach
|
|
8
|
-
IndentCaseLabels: false
|
|
9
|
-
NamespaceIndentation: None
|
|
10
|
-
ContinuationIndentWidth: 4
|
|
11
|
-
IndentPPDirectives: None
|
|
12
|
-
IndentWrappedFunctionNames: false
|
|
13
|
-
AccessModifierOffset: -2
|
|
14
|
-
|
|
15
|
-
# Alignment
|
|
16
|
-
AlignAfterOpenBracket: BlockIndent
|
|
17
|
-
AlignConsecutiveAssignments: false
|
|
18
|
-
AlignConsecutiveDeclarations: false
|
|
19
|
-
AlignConsecutiveMacros: false
|
|
20
|
-
AlignEscapedNewlines: Left
|
|
21
|
-
AlignOperands: false
|
|
22
|
-
AlignTrailingComments: true
|
|
23
|
-
DerivePointerAlignment: false
|
|
24
|
-
PointerAlignment: Right
|
|
25
|
-
|
|
26
|
-
# Function calls formatting
|
|
27
|
-
BinPackArguments: false
|
|
28
|
-
BinPackParameters: false
|
|
29
|
-
AllowAllArgumentsOnNextLine: false
|
|
30
|
-
ExperimentalAutoDetectBinPacking: false
|
|
31
|
-
PenaltyBreakBeforeFirstCallParameter: 1
|
|
32
|
-
AlwaysBreakAfterDefinitionReturnType: None
|
|
33
|
-
|
|
34
|
-
# Wrapping and Breaking
|
|
35
|
-
ColumnLimit: 0
|
|
36
|
-
AllowShortBlocksOnASingleLine: Never
|
|
37
|
-
AllowShortCaseLabelsOnASingleLine: false
|
|
38
|
-
AllowShortFunctionsOnASingleLine: All
|
|
39
|
-
AllowShortIfStatementsOnASingleLine: Always
|
|
40
|
-
AllowShortLoopsOnASingleLine: false
|
|
41
|
-
AlwaysBreakAfterReturnType: None
|
|
42
|
-
AlwaysBreakBeforeMultilineStrings: false
|
|
43
|
-
AlwaysBreakTemplateDeclarations: No
|
|
44
|
-
BreakBeforeBinaryOperators: None
|
|
45
|
-
BreakBeforeTernaryOperators: false
|
|
46
|
-
BreakConstructorInitializers: BeforeColon
|
|
47
|
-
BreakInheritanceList: BeforeColon
|
|
48
|
-
BreakStringLiterals: false
|
|
49
|
-
CompactNamespaces: false
|
|
50
|
-
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
|
51
|
-
Cpp11BracedListStyle: false
|
|
52
|
-
ReflowComments: false
|
|
53
|
-
SortIncludes: Never
|
|
54
|
-
|
|
55
|
-
# Spaces
|
|
56
|
-
SpaceAfterCStyleCast: true
|
|
57
|
-
SpaceAfterLogicalNot: false
|
|
58
|
-
SpaceAfterTemplateKeyword: true
|
|
59
|
-
SpaceBeforeAssignmentOperators: true
|
|
60
|
-
SpaceBeforeCpp11BracedList: true
|
|
61
|
-
SpaceBeforeCtorInitializerColon: true
|
|
62
|
-
SpaceBeforeInheritanceColon: true
|
|
63
|
-
SpaceBeforeParens: ControlStatements
|
|
64
|
-
SpaceBeforeRangeBasedForLoopColon: true
|
|
65
|
-
SpaceBeforeSquareBrackets: false
|
|
66
|
-
SpaceInEmptyBlock: false
|
|
67
|
-
SpaceInEmptyParentheses: false
|
|
68
|
-
SpacesBeforeTrailingComments: 1
|
|
69
|
-
SpacesInAngles: false
|
|
70
|
-
SpacesInCStyleCastParentheses: false
|
|
71
|
-
SpacesInConditionalStatement: false
|
|
72
|
-
SpacesInContainerLiterals: true
|
|
73
|
-
SpacesInParentheses: false
|
|
74
|
-
SpacesInSquareBrackets: false
|
data/.clangd
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
name: C Code Generation and Formatting Check
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
pull_request: {}
|
|
6
|
-
merge_group: {}
|
|
7
|
-
|
|
8
|
-
jobs:
|
|
9
|
-
format-check:
|
|
10
|
-
runs-on: ubuntu-latest
|
|
11
|
-
steps:
|
|
12
|
-
- uses: actions/checkout@v4
|
|
13
|
-
- uses: ruby/setup-ruby@v1
|
|
14
|
-
with:
|
|
15
|
-
ruby-version: "4.0.0-preview3"
|
|
16
|
-
bundler-cache: none
|
|
17
|
-
- name: Set working directory as safe
|
|
18
|
-
run: git config --global --add safe.directory $(pwd)
|
|
19
|
-
- name: Install dependencies
|
|
20
|
-
run: |
|
|
21
|
-
sudo apt-get update
|
|
22
|
-
sudo apt-get install -y libdb-dev curl autoconf automake m4 libtool
|
|
23
|
-
- name: Install clang-format from LLVM
|
|
24
|
-
run: |
|
|
25
|
-
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
|
|
26
|
-
sudo apt-add-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-20 main"
|
|
27
|
-
sudo apt-get update
|
|
28
|
-
sudo apt-get install -y clang-format-20
|
|
29
|
-
sudo ln -sf /usr/bin/clang-format-20 /usr/local/bin/clang-format
|
|
30
|
-
clang-format --version
|
|
31
|
-
- name: Count processors
|
|
32
|
-
run: nproc
|
|
33
|
-
- name: Install Re2c
|
|
34
|
-
run: |
|
|
35
|
-
cd /tmp
|
|
36
|
-
curl -L https://github.com/skvadrik/re2c/archive/refs/tags/4.3.tar.gz > re2c-4.3.tar.gz
|
|
37
|
-
tar xf re2c-4.3.tar.gz
|
|
38
|
-
cd re2c-4.3
|
|
39
|
-
autoreconf -i -W all
|
|
40
|
-
./configure
|
|
41
|
-
make -j"$(nproc)" -l"$(nproc)"
|
|
42
|
-
sudo make install
|
|
43
|
-
- name: Update rubygems & bundler
|
|
44
|
-
run: |
|
|
45
|
-
ruby -v
|
|
46
|
-
gem update --system
|
|
47
|
-
- name: bin/setup
|
|
48
|
-
run: |
|
|
49
|
-
bin/setup
|
|
50
|
-
- name: Check C code generation and formatting
|
|
51
|
-
run: |
|
|
52
|
-
clang-format --version
|
|
53
|
-
bundle exec rake lexer templates compile confirm_lexer confirm_templates
|
|
54
|
-
bundle exec rake format:c_check
|
data/core/ruby.rbs
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
# <!-- rdoc-file=version.c -->
|
|
2
|
-
# The [Ruby](rdoc-ref:Ruby) module that contains portable information among
|
|
3
|
-
# implementations.
|
|
4
|
-
#
|
|
5
|
-
# The constants defined here are aliased in the toplevel with `RUBY_` prefix.
|
|
6
|
-
#
|
|
7
|
-
module Ruby
|
|
8
|
-
# <!-- rdoc-file=version.c -->
|
|
9
|
-
# The copyright string for ruby
|
|
10
|
-
#
|
|
11
|
-
COPYRIGHT: ::String
|
|
12
|
-
|
|
13
|
-
# <!-- rdoc-file=version.c -->
|
|
14
|
-
# The full ruby version string, like `ruby -v` prints
|
|
15
|
-
#
|
|
16
|
-
DESCRIPTION: ::String
|
|
17
|
-
|
|
18
|
-
# <!-- rdoc-file=version.c -->
|
|
19
|
-
# The engine or interpreter this ruby uses.
|
|
20
|
-
#
|
|
21
|
-
ENGINE: ::String
|
|
22
|
-
|
|
23
|
-
# <!-- rdoc-file=version.c -->
|
|
24
|
-
# The version of the engine or interpreter this ruby uses.
|
|
25
|
-
#
|
|
26
|
-
ENGINE_VERSION: ::String
|
|
27
|
-
|
|
28
|
-
# <!-- rdoc-file=version.c -->
|
|
29
|
-
# The patchlevel for this ruby. If this is a development build of ruby the
|
|
30
|
-
# patchlevel will be -1
|
|
31
|
-
#
|
|
32
|
-
PATCHLEVEL: ::Integer
|
|
33
|
-
|
|
34
|
-
# <!-- rdoc-file=version.c -->
|
|
35
|
-
# The platform for this ruby
|
|
36
|
-
#
|
|
37
|
-
PLATFORM: ::String
|
|
38
|
-
|
|
39
|
-
# <!-- rdoc-file=version.c -->
|
|
40
|
-
# The date this ruby was released
|
|
41
|
-
#
|
|
42
|
-
RELEASE_DATE: ::String
|
|
43
|
-
|
|
44
|
-
# <!-- rdoc-file=version.c -->
|
|
45
|
-
# The GIT commit hash for this ruby.
|
|
46
|
-
#
|
|
47
|
-
REVISION: ::String
|
|
48
|
-
|
|
49
|
-
# <!-- rdoc-file=version.c -->
|
|
50
|
-
# The running version of ruby
|
|
51
|
-
#
|
|
52
|
-
VERSION: ::String
|
|
53
|
-
end
|
data/docs/aliases.md
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
# Aliases
|
|
2
|
-
|
|
3
|
-
This document explains module/class aliases and type aliases.
|
|
4
|
-
|
|
5
|
-
## Module/class alias
|
|
6
|
-
|
|
7
|
-
Module/class aliases give another name to a module/class.
|
|
8
|
-
This is useful for some syntaxes that has lexical constraints.
|
|
9
|
-
|
|
10
|
-
```rbs
|
|
11
|
-
class C
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
class D = C # ::D is an alias for ::C
|
|
15
|
-
|
|
16
|
-
class E < D # ::E inherits from ::D, which is actually ::C
|
|
17
|
-
end
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
Note that module/class aliases cannot be recursive.
|
|
21
|
-
|
|
22
|
-
So, we can define a *normalization* of aliased module/class names.
|
|
23
|
-
Normalization follows the chain of alias definitions and resolves them to the original module/class defined with `module`/`class` syntax.
|
|
24
|
-
|
|
25
|
-
```rbs
|
|
26
|
-
class C
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
class D = C
|
|
30
|
-
class E = D
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
`::E` is defined as an alias, and it can be normalized to `::C`.
|
|
34
|
-
|
|
35
|
-
## Type alias
|
|
36
|
-
|
|
37
|
-
The biggest difference from module/class alias is that type alias can be recursive.
|
|
38
|
-
|
|
39
|
-
```rbs
|
|
40
|
-
# cons_cell type is defined recursively
|
|
41
|
-
type cons_cell = nil
|
|
42
|
-
| [Integer, cons_cell]
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
This means type aliases *cannot be* normalized generally.
|
|
46
|
-
So, we provide another operation for type alias, `DefinitionBuilder#expand_alias` and its family.
|
|
47
|
-
It substitutes with the immediate right hand side of a type alias.
|
|
48
|
-
|
|
49
|
-
```
|
|
50
|
-
cons_cell ===> nil | [Integer, cons_cell] (expand 1 step)
|
|
51
|
-
===> nil | [Integer, nil | [Integer, cons_cell]] (expand 2 steps)
|
|
52
|
-
===> ... (expand will go infinitely)
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
Note that the namespace of a type alias *can be* normalized, because they are module names.
|
|
56
|
-
|
|
57
|
-
```rbs
|
|
58
|
-
module M
|
|
59
|
-
type t = String
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
module N = M
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
With the type definition above, a type `::N::t` can be normalized to `::M::t`.
|
|
66
|
-
And then it can be expanded to `::String`.
|
|
67
|
-
|
|
68
|
-
> [!NOTE]
|
|
69
|
-
> This is something like an *unfold* operation in type theory.
|
|
70
|
-
|
|
71
|
-
## Type name resolution
|
|
72
|
-
|
|
73
|
-
Type name resolution in RBS usually rewrites *relative* type names to *absolute* type names.
|
|
74
|
-
`Environment#resolve_type_names` converts all type names in the RBS type definitions, and returns a new `Environment` object.
|
|
75
|
-
|
|
76
|
-
It also *normalizes* modules names in type names.
|
|
77
|
-
|
|
78
|
-
- If the type name can be resolved and normalized successfully, the AST has *absolute* type names.
|
|
79
|
-
- If the type name resolution/normalization fails, the AST has *relative* type names.
|
data/docs/encoding.md
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
# RBS File Encoding
|
|
2
|
-
|
|
3
|
-
## Best Practice
|
|
4
|
-
|
|
5
|
-
**Use UTF-8** for both file encoding and your system locale.
|
|
6
|
-
|
|
7
|
-
## Supported Encodings
|
|
8
|
-
|
|
9
|
-
RBS parser supports ASCII-compatible encodings (similar to Ruby's script encoding support).
|
|
10
|
-
|
|
11
|
-
**Examples**: UTF-8, US-ASCII, Shift JIS, EUC-JP, ...
|
|
12
|
-
|
|
13
|
-
## Unicode Codepoint Symbols
|
|
14
|
-
|
|
15
|
-
String literal types in RBS can contain Unicode codepoint escape sequences (`\uXXXX`).
|
|
16
|
-
|
|
17
|
-
When the file encoding is UTF-8, the parser translates Unicode codepoint symbols:
|
|
18
|
-
|
|
19
|
-
```rbs
|
|
20
|
-
# In UTF-8 encoded files
|
|
21
|
-
|
|
22
|
-
type t = "\u0123" # Translated to the actual Unicode character ģ
|
|
23
|
-
type s = "\u3042" # Translated to the actual Unicode character あ
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
When the file encoding is not UTF-8, Unicode escape sequences are interpreted literally as the string `\uXXXX`:
|
|
27
|
-
|
|
28
|
-
```rbs
|
|
29
|
-
# In non-UTF-8 encoded files
|
|
30
|
-
|
|
31
|
-
type t = "\u0123" # Remains as the literal string "\u0123"
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
## Implementation
|
|
35
|
-
|
|
36
|
-
RBS gem currently doesn't do anything for file encoding. It relies on Ruby's encoding handling, specifically `Encoding.default_external` and `Encoding.default_internal`.
|
|
37
|
-
|
|
38
|
-
`Encoding.default_external` is the encoding Ruby assumes when it reads external resources like files. The Ruby interpreter sets it based on the locale. `Encoding.default_internal` is the encoding Ruby converts the external resources to. The default is `nil` (no conversion.)
|
|
39
|
-
|
|
40
|
-
When your locale is set to use `UTF-8` encoding, `default_external` is `Encoding::UTF_8`. So the RBS file content read from the disk will have UTF-8 encoding.
|
|
41
|
-
|
|
42
|
-
### Parsing non UTF-8 RBS source text
|
|
43
|
-
|
|
44
|
-
If you want to work with another encoding, ensure the source string has ASCII compatible encoding.
|
|
45
|
-
|
|
46
|
-
```ruby
|
|
47
|
-
source = '"日本語"'
|
|
48
|
-
RBS::Parser.parse_type(source.encode(Encoding::EUC_JP)) # => Parses successfully
|
|
49
|
-
RBS::Parser.parse_type(source.encode(Encoding::UTF_32)) # => Returns `nil` since UTF-32 is not ASCII compatible
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
### Specifying file encoding
|
|
53
|
-
|
|
54
|
-
Currently, RBS doesn't support specifying file encoding directly.
|
|
55
|
-
|
|
56
|
-
You can use `Encoding.default_external` while the gem loads RBS files from the storage.
|
data/ext/rbs_extension/compat.h
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
#ifdef __clang__
|
|
2
|
-
#define SUPPRESS_RUBY_HEADER_DIAGNOSTICS_BEGIN \
|
|
3
|
-
_Pragma("clang diagnostic push") \
|
|
4
|
-
_Pragma("clang diagnostic ignored \"-Wc2x-extensions\"")
|
|
5
|
-
#define SUPPRESS_RUBY_HEADER_DIAGNOSTICS_END \
|
|
6
|
-
_Pragma("clang diagnostic pop")
|
|
7
|
-
#else
|
|
8
|
-
#define SUPPRESS_RUBY_HEADER_DIAGNOSTICS_BEGIN
|
|
9
|
-
#define SUPPRESS_RUBY_HEADER_DIAGNOSTICS_END
|
|
10
|
-
#endif
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
# <!-- rdoc-file=lib/cgi/escape.rb -->
|
|
2
|
-
# :stopdoc
|
|
3
|
-
#
|
|
4
|
-
class CGI
|
|
5
|
-
include Escape
|
|
6
|
-
|
|
7
|
-
extend Escape
|
|
8
|
-
|
|
9
|
-
# <!-- rdoc-file=lib/cgi/escape.rb -->
|
|
10
|
-
# Escape/unescape for CGI, HTML, URI.
|
|
11
|
-
#
|
|
12
|
-
module Escape
|
|
13
|
-
# <!--
|
|
14
|
-
# rdoc-file=lib/cgi/escape.rb
|
|
15
|
-
# - escape(string)
|
|
16
|
-
# -->
|
|
17
|
-
# URL-encode a string into application/x-www-form-urlencoded. Space characters
|
|
18
|
-
# (+" "+) are encoded with plus signs (+"+"+)
|
|
19
|
-
# url_encoded_string = CGI.escape("'Stop!' said Fred")
|
|
20
|
-
# # => "%27Stop%21%27+said+Fred"
|
|
21
|
-
#
|
|
22
|
-
def escape: (string str) -> String
|
|
23
|
-
|
|
24
|
-
# <!--
|
|
25
|
-
# rdoc-file=lib/cgi/escape.rb
|
|
26
|
-
# - escapeElement(string, *elements)
|
|
27
|
-
# -->
|
|
28
|
-
# Escape only the tags of certain HTML elements in `string`.
|
|
29
|
-
#
|
|
30
|
-
# Takes an element or elements or array of elements. Each element is specified
|
|
31
|
-
# by the name of the element, without angle brackets. This matches both the
|
|
32
|
-
# start and the end tag of that element. The attribute list of the open tag will
|
|
33
|
-
# also be escaped (for instance, the double-quotes surrounding attribute
|
|
34
|
-
# values).
|
|
35
|
-
#
|
|
36
|
-
# print CGI.escapeElement('<BR><A HREF="url"></A>', "A", "IMG")
|
|
37
|
-
# # "<BR><A HREF="url"></A>"
|
|
38
|
-
#
|
|
39
|
-
# print CGI.escapeElement('<BR><A HREF="url"></A>', ["A", "IMG"])
|
|
40
|
-
# # "<BR><A HREF="url"></A>"
|
|
41
|
-
#
|
|
42
|
-
def escapeElement: (string string, *String | Array[String] elements) -> String
|
|
43
|
-
|
|
44
|
-
# <!--
|
|
45
|
-
# rdoc-file=lib/cgi/escape.rb
|
|
46
|
-
# - escapeHTML(string)
|
|
47
|
-
# -->
|
|
48
|
-
# Escape special characters in HTML, namely '&"<>
|
|
49
|
-
# CGI.escapeHTML('Usage: foo "bar" <baz>')
|
|
50
|
-
# # => "Usage: foo "bar" <baz>"
|
|
51
|
-
#
|
|
52
|
-
def escapeHTML: (string str) -> String
|
|
53
|
-
|
|
54
|
-
# <!--
|
|
55
|
-
# rdoc-file=lib/cgi/escape.rb
|
|
56
|
-
# - escapeURIComponent(string)
|
|
57
|
-
# -->
|
|
58
|
-
# URL-encode a string following RFC 3986 Space characters (+" "+) are encoded
|
|
59
|
-
# with (+"%20"+)
|
|
60
|
-
# url_encoded_string = CGI.escapeURIComponent("'Stop!' said Fred")
|
|
61
|
-
# # => "%27Stop%21%27%20said%20Fred"
|
|
62
|
-
#
|
|
63
|
-
def escapeURIComponent: (string) -> String
|
|
64
|
-
|
|
65
|
-
# <!-- rdoc-file=lib/cgi/escape.rb -->
|
|
66
|
-
# Synonym for CGI.escapeElement(str)
|
|
67
|
-
#
|
|
68
|
-
alias escape_element escapeElement
|
|
69
|
-
|
|
70
|
-
# <!-- rdoc-file=lib/cgi/escape.rb -->
|
|
71
|
-
# Synonym for CGI.escapeHTML(str)
|
|
72
|
-
#
|
|
73
|
-
alias escape_html escapeHTML
|
|
74
|
-
|
|
75
|
-
# <!--
|
|
76
|
-
# rdoc-file=lib/cgi/escape.rb
|
|
77
|
-
# - escape_uri_component(string)
|
|
78
|
-
# -->
|
|
79
|
-
#
|
|
80
|
-
alias escape_uri_component escapeURIComponent
|
|
81
|
-
|
|
82
|
-
# <!--
|
|
83
|
-
# rdoc-file=lib/cgi/escape.rb
|
|
84
|
-
# - h(string)
|
|
85
|
-
# -->
|
|
86
|
-
#
|
|
87
|
-
alias h escapeHTML
|
|
88
|
-
|
|
89
|
-
# <!--
|
|
90
|
-
# rdoc-file=lib/cgi/escape.rb
|
|
91
|
-
# - unescape(string, encoding = @@accept_charset)
|
|
92
|
-
# -->
|
|
93
|
-
# URL-decode an application/x-www-form-urlencoded string with
|
|
94
|
-
# encoding(optional).
|
|
95
|
-
# string = CGI.unescape("%27Stop%21%27+said+Fred")
|
|
96
|
-
# # => "'Stop!' said Fred"
|
|
97
|
-
#
|
|
98
|
-
def unescape: (string str, ?encoding encoding) -> String
|
|
99
|
-
|
|
100
|
-
# <!--
|
|
101
|
-
# rdoc-file=lib/cgi/escape.rb
|
|
102
|
-
# - unescapeElement(string, *elements)
|
|
103
|
-
# -->
|
|
104
|
-
# Undo escaping such as that done by CGI.escapeElement()
|
|
105
|
-
#
|
|
106
|
-
# print CGI.unescapeElement(
|
|
107
|
-
# CGI.escapeHTML('<BR><A HREF="url"></A>'), "A", "IMG")
|
|
108
|
-
# # "<BR><A HREF="url"></A>"
|
|
109
|
-
#
|
|
110
|
-
# print CGI.unescapeElement(
|
|
111
|
-
# CGI.escapeHTML('<BR><A HREF="url"></A>'), ["A", "IMG"])
|
|
112
|
-
# # "<BR><A HREF="url"></A>"
|
|
113
|
-
#
|
|
114
|
-
def unescapeElement: (string string, *String | Array[String] elements) -> String
|
|
115
|
-
|
|
116
|
-
# <!--
|
|
117
|
-
# rdoc-file=lib/cgi/escape.rb
|
|
118
|
-
# - unescapeHTML(string)
|
|
119
|
-
# -->
|
|
120
|
-
# Unescape a string that has been HTML-escaped
|
|
121
|
-
# CGI.unescapeHTML("Usage: foo "bar" <baz>")
|
|
122
|
-
# # => "Usage: foo \"bar\" <baz>"
|
|
123
|
-
#
|
|
124
|
-
def unescapeHTML: (string str) -> String
|
|
125
|
-
|
|
126
|
-
# <!--
|
|
127
|
-
# rdoc-file=lib/cgi/escape.rb
|
|
128
|
-
# - unescapeURIComponent(string, encoding = @@accept_charset)
|
|
129
|
-
# -->
|
|
130
|
-
# URL-decode a string following RFC 3986 with encoding(optional).
|
|
131
|
-
# string = CGI.unescapeURIComponent("%27Stop%21%27+said%20Fred")
|
|
132
|
-
# # => "'Stop!'+said Fred"
|
|
133
|
-
#
|
|
134
|
-
def unescapeURIComponent: (string) -> String
|
|
135
|
-
|
|
136
|
-
# <!-- rdoc-file=lib/cgi/escape.rb -->
|
|
137
|
-
# Synonym for CGI.unescapeElement(str)
|
|
138
|
-
#
|
|
139
|
-
alias unescape_element unescapeElement
|
|
140
|
-
|
|
141
|
-
# <!-- rdoc-file=lib/cgi/escape.rb -->
|
|
142
|
-
# Synonym for CGI.unescapeHTML(str)
|
|
143
|
-
#
|
|
144
|
-
alias unescape_html unescapeHTML
|
|
145
|
-
|
|
146
|
-
# <!--
|
|
147
|
-
# rdoc-file=lib/cgi/escape.rb
|
|
148
|
-
# - unescape_uri_component(string, encoding = @@accept_charset)
|
|
149
|
-
# -->
|
|
150
|
-
#
|
|
151
|
-
alias unescape_uri_component unescapeURIComponent
|
|
152
|
-
end
|
|
153
|
-
end
|