t-ruby 0.0.41 → 0.0.43
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/lib/t_ruby/ast_type_inferrer.rb +2 -0
- data/lib/t_ruby/cache.rb +40 -10
- data/lib/t_ruby/cli.rb +14 -9
- data/lib/t_ruby/code_emitter.rb +254 -0
- data/lib/t_ruby/compiler.rb +186 -3
- data/lib/t_ruby/config.rb +18 -3
- data/lib/t_ruby/diagnostic.rb +115 -0
- data/lib/t_ruby/diagnostic_formatter.rb +162 -0
- data/lib/t_ruby/error_handler.rb +201 -35
- data/lib/t_ruby/error_reporter.rb +57 -0
- data/lib/t_ruby/ir.rb +39 -1
- data/lib/t_ruby/lsp_server.rb +40 -97
- data/lib/t_ruby/parser.rb +18 -4
- data/lib/t_ruby/parser_combinator/combinators/alternative.rb +20 -0
- data/lib/t_ruby/parser_combinator/combinators/chain_left.rb +34 -0
- data/lib/t_ruby/parser_combinator/combinators/choice.rb +29 -0
- data/lib/t_ruby/parser_combinator/combinators/flat_map.rb +21 -0
- data/lib/t_ruby/parser_combinator/combinators/label.rb +22 -0
- data/lib/t_ruby/parser_combinator/combinators/lookahead.rb +21 -0
- data/lib/t_ruby/parser_combinator/combinators/many.rb +29 -0
- data/lib/t_ruby/parser_combinator/combinators/many1.rb +32 -0
- data/lib/t_ruby/parser_combinator/combinators/map.rb +17 -0
- data/lib/t_ruby/parser_combinator/combinators/not_followed_by.rb +21 -0
- data/lib/t_ruby/parser_combinator/combinators/optional.rb +21 -0
- data/lib/t_ruby/parser_combinator/combinators/sep_by.rb +34 -0
- data/lib/t_ruby/parser_combinator/combinators/sep_by1.rb +34 -0
- data/lib/t_ruby/parser_combinator/combinators/sequence.rb +23 -0
- data/lib/t_ruby/parser_combinator/combinators/skip_right.rb +23 -0
- data/lib/t_ruby/parser_combinator/declaration_parser.rb +147 -0
- data/lib/t_ruby/parser_combinator/dsl.rb +115 -0
- data/lib/t_ruby/parser_combinator/parse_error.rb +48 -0
- data/lib/t_ruby/parser_combinator/parse_result.rb +46 -0
- data/lib/t_ruby/parser_combinator/parser.rb +84 -0
- data/lib/t_ruby/parser_combinator/primitives/end_of_input.rb +16 -0
- data/lib/t_ruby/parser_combinator/primitives/fail.rb +16 -0
- data/lib/t_ruby/parser_combinator/primitives/lazy.rb +18 -0
- data/lib/t_ruby/parser_combinator/primitives/literal.rb +21 -0
- data/lib/t_ruby/parser_combinator/primitives/pure.rb +16 -0
- data/lib/t_ruby/parser_combinator/primitives/regex.rb +25 -0
- data/lib/t_ruby/parser_combinator/primitives/satisfy.rb +21 -0
- data/lib/t_ruby/parser_combinator/token/expression_parser.rb +541 -0
- data/lib/t_ruby/parser_combinator/token/statement_parser.rb +644 -0
- data/lib/t_ruby/parser_combinator/token/token_alternative.rb +20 -0
- data/lib/t_ruby/parser_combinator/token/token_body_parser.rb +54 -0
- data/lib/t_ruby/parser_combinator/token/token_declaration_parser.rb +920 -0
- data/lib/t_ruby/parser_combinator/token/token_dsl.rb +16 -0
- data/lib/t_ruby/parser_combinator/token/token_label.rb +22 -0
- data/lib/t_ruby/parser_combinator/token/token_many.rb +29 -0
- data/lib/t_ruby/parser_combinator/token/token_many1.rb +32 -0
- data/lib/t_ruby/parser_combinator/token/token_map.rb +17 -0
- data/lib/t_ruby/parser_combinator/token/token_matcher.rb +29 -0
- data/lib/t_ruby/parser_combinator/token/token_optional.rb +21 -0
- data/lib/t_ruby/parser_combinator/token/token_parse_result.rb +40 -0
- data/lib/t_ruby/parser_combinator/token/token_parser.rb +62 -0
- data/lib/t_ruby/parser_combinator/token/token_sep_by.rb +34 -0
- data/lib/t_ruby/parser_combinator/token/token_sep_by1.rb +34 -0
- data/lib/t_ruby/parser_combinator/token/token_sequence.rb +23 -0
- data/lib/t_ruby/parser_combinator/token/token_skip_right.rb +23 -0
- data/lib/t_ruby/parser_combinator/type_parser.rb +103 -0
- data/lib/t_ruby/parser_combinator.rb +64 -936
- data/lib/t_ruby/ruby_version.rb +112 -0
- data/lib/t_ruby/scanner.rb +883 -0
- data/lib/t_ruby/version.rb +1 -1
- data/lib/t_ruby/watcher.rb +83 -76
- data/lib/t_ruby.rb +17 -1
- metadata +58 -7
- data/lib/t_ruby/body_parser.rb +0 -561
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module TRuby
|
|
4
|
+
# Error raised when an unsupported Ruby version is detected
|
|
5
|
+
class UnsupportedRubyVersionError < StandardError; end
|
|
6
|
+
|
|
7
|
+
# Value object representing a Ruby version with comparison and feature detection
|
|
8
|
+
#
|
|
9
|
+
# @example
|
|
10
|
+
# version = RubyVersion.parse("3.4")
|
|
11
|
+
# version.supports_it_parameter? # => true
|
|
12
|
+
# version >= RubyVersion.parse("3.0") # => true
|
|
13
|
+
#
|
|
14
|
+
class RubyVersion
|
|
15
|
+
include Comparable
|
|
16
|
+
|
|
17
|
+
# Supported version range
|
|
18
|
+
MIN_VERSION = [3, 0].freeze
|
|
19
|
+
MAX_MAJOR = 4
|
|
20
|
+
|
|
21
|
+
# Version string pattern: major.minor or major.minor.patch
|
|
22
|
+
VERSION_REGEX = /\A(\d+)\.(\d+)(?:\.(\d+))?\z/
|
|
23
|
+
|
|
24
|
+
attr_reader :major, :minor, :patch
|
|
25
|
+
|
|
26
|
+
# @param major [Integer] major version number
|
|
27
|
+
# @param minor [Integer] minor version number
|
|
28
|
+
# @param patch [Integer] patch version number (default: 0)
|
|
29
|
+
def initialize(major, minor, patch = 0)
|
|
30
|
+
@major = major
|
|
31
|
+
@minor = minor
|
|
32
|
+
@patch = patch
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Parse a version string into a RubyVersion object
|
|
36
|
+
#
|
|
37
|
+
# @param version_string [String, Numeric] version string (e.g., "3.4", "3.4.1")
|
|
38
|
+
# @return [RubyVersion] parsed version object
|
|
39
|
+
# @raise [ArgumentError] if version format is invalid
|
|
40
|
+
def self.parse(version_string)
|
|
41
|
+
str = version_string.to_s
|
|
42
|
+
match = VERSION_REGEX.match(str)
|
|
43
|
+
|
|
44
|
+
raise ArgumentError, "Invalid version: #{version_string}" unless match
|
|
45
|
+
|
|
46
|
+
new(match[1].to_i, match[2].to_i, (match[3] || 0).to_i)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Get the current Ruby version from the environment
|
|
50
|
+
#
|
|
51
|
+
# @return [RubyVersion] current Ruby version
|
|
52
|
+
def self.current
|
|
53
|
+
parse(RUBY_VERSION)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Compare two versions
|
|
57
|
+
#
|
|
58
|
+
# @param other [RubyVersion] version to compare with
|
|
59
|
+
# @return [Integer] -1, 0, or 1
|
|
60
|
+
def <=>(other)
|
|
61
|
+
[major, minor, patch] <=> [other.major, other.minor, other.patch]
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Convert to string representation
|
|
65
|
+
#
|
|
66
|
+
# @return [String] version string (e.g., "3.4" or "3.4.1")
|
|
67
|
+
def to_s
|
|
68
|
+
patch.zero? ? "#{major}.#{minor}" : "#{major}.#{minor}.#{patch}"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Check if this version is within the supported range (3.0 ~ 4.x)
|
|
72
|
+
#
|
|
73
|
+
# @return [Boolean] true if version is supported
|
|
74
|
+
def supported?
|
|
75
|
+
self >= self.class.parse("#{MIN_VERSION[0]}.#{MIN_VERSION[1]}") && major <= MAX_MAJOR
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# Validate that this version is supported, raising an error if not
|
|
79
|
+
#
|
|
80
|
+
# @return [RubyVersion] self if valid
|
|
81
|
+
# @raise [UnsupportedRubyVersionError] if version is not supported
|
|
82
|
+
def validate!
|
|
83
|
+
unless supported?
|
|
84
|
+
raise UnsupportedRubyVersionError,
|
|
85
|
+
"Ruby #{self}는 지원되지 않습니다. 지원 범위: #{MIN_VERSION.join(".")} ~ #{MAX_MAJOR}.x"
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
self
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# Check if this version supports the `it` implicit block parameter (Ruby 3.4+)
|
|
92
|
+
#
|
|
93
|
+
# @return [Boolean] true if `it` parameter is supported
|
|
94
|
+
def supports_it_parameter?
|
|
95
|
+
self >= self.class.parse("3.4")
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# Check if this version supports anonymous block forwarding `def foo(&) ... end` (Ruby 3.1+)
|
|
99
|
+
#
|
|
100
|
+
# @return [Boolean] true if anonymous block forwarding is supported
|
|
101
|
+
def supports_anonymous_block_forwarding?
|
|
102
|
+
self >= self.class.parse("3.1")
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# Check if numbered parameters (_1, _2, etc.) raise NameError (Ruby 4.0+)
|
|
106
|
+
#
|
|
107
|
+
# @return [Boolean] true if numbered parameters cause errors
|
|
108
|
+
def numbered_parameters_raise_error?
|
|
109
|
+
self >= self.class.parse("4.0")
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|