prism 0.25.0 → 0.26.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -1
- data/Makefile +17 -14
- data/config.yml +12 -1
- data/docs/configuration.md +1 -0
- data/docs/releasing.md +7 -9
- data/ext/prism/extconf.rb +8 -3
- data/ext/prism/extension.c +28 -2
- data/ext/prism/extension.h +1 -1
- data/include/prism/diagnostic.h +12 -1
- data/include/prism/parser.h +5 -1
- data/include/prism/version.h +2 -2
- data/lib/prism/desugar_compiler.rb +4 -2
- data/lib/prism/ffi.rb +10 -0
- data/lib/prism/node.rb +16 -0
- data/lib/prism/parse_result.rb +5 -0
- data/lib/prism/reflection.rb +421 -0
- data/lib/prism/serialize.rb +13 -2
- data/lib/prism/translation/parser/compiler.rb +48 -11
- data/lib/prism.rb +1 -16
- data/prism.gemspec +7 -3
- data/rbi/prism/node.rbi +453 -0
- data/rbi/prism/parse_result.rbi +3 -0
- data/rbi/prism/reflection.rbi +64 -0
- data/rbi/prism/translation/parser.rbi +11 -0
- data/rbi/prism/translation/parser33.rbi +6 -0
- data/rbi/prism/translation/parser34.rbi +6 -0
- data/rbi/prism.rbi +33 -33
- data/sig/prism/node.rbs +10 -1
- data/sig/prism/parse_result.rbs +1 -0
- data/sig/prism/reflection.rbs +56 -0
- data/sig/prism.rbs +2 -2
- data/src/diagnostic.c +30 -8
- data/src/options.c +30 -19
- data/src/prism.c +404 -67
- data/src/token_type.c +3 -3
- data/src/util/pm_integer.c +14 -8
- metadata +8 -4
- data/include/prism/util/pm_state_stack.h +0 -42
- data/src/util/pm_state_stack.c +0 -25
data/rbi/prism/parse_result.rbi
CHANGED
@@ -72,6 +72,9 @@ class Prism::Location
|
|
72
72
|
sig { params(source: Prism::Source, start_offset: Integer, length: Integer).returns(Prism::Location) }
|
73
73
|
def copy(source: self.source, start_offset: self.start_offset, length: self.length); end
|
74
74
|
|
75
|
+
sig { returns(Prism::Location) }
|
76
|
+
def chop; end
|
77
|
+
|
75
78
|
sig { returns(String) }
|
76
79
|
def inspect; end
|
77
80
|
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# typed: strict
|
2
|
+
|
3
|
+
module Prism::Reflection
|
4
|
+
end
|
5
|
+
|
6
|
+
class Prism::Reflection::Field
|
7
|
+
sig { returns(Symbol) }
|
8
|
+
attr_reader :name
|
9
|
+
|
10
|
+
sig { params(name: Symbol).void }
|
11
|
+
def initialize(name); end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Prism::Reflection::NodeField < Prism::Reflection::Field
|
15
|
+
end
|
16
|
+
|
17
|
+
class Prism::Reflection::OptionalNodeField < Prism::Reflection::Field
|
18
|
+
end
|
19
|
+
|
20
|
+
class Prism::Reflection::NodeListField < Prism::Reflection::Field
|
21
|
+
end
|
22
|
+
|
23
|
+
class Prism::Reflection::ConstantField < Prism::Reflection::Field
|
24
|
+
end
|
25
|
+
|
26
|
+
class Prism::Reflection::OptionalConstantField < Prism::Reflection::Field
|
27
|
+
end
|
28
|
+
|
29
|
+
class Prism::Reflection::ConstantListField < Prism::Reflection::Field
|
30
|
+
end
|
31
|
+
|
32
|
+
class Prism::Reflection::StringField < Prism::Reflection::Field
|
33
|
+
end
|
34
|
+
|
35
|
+
class Prism::Reflection::LocationField < Prism::Reflection::Field
|
36
|
+
end
|
37
|
+
|
38
|
+
class Prism::Reflection::OptionalLocationField < Prism::Reflection::Field
|
39
|
+
end
|
40
|
+
|
41
|
+
class Prism::Reflection::UInt8Field < Prism::Reflection::Field
|
42
|
+
end
|
43
|
+
|
44
|
+
class Prism::Reflection::UInt32Field < Prism::Reflection::Field
|
45
|
+
end
|
46
|
+
|
47
|
+
class Prism::Reflection::FlagsField < Prism::Reflection::Field
|
48
|
+
sig { returns(T::Array[Symbol]) }
|
49
|
+
attr_reader :flags
|
50
|
+
|
51
|
+
sig { params(name: Symbol, flags: T::Array[Symbol]).void }
|
52
|
+
def initialize(name, flags); end
|
53
|
+
end
|
54
|
+
|
55
|
+
class Prism::Reflection::IntegerField < Prism::Reflection::Field
|
56
|
+
end
|
57
|
+
|
58
|
+
class Prism::Reflection::DoubleField < Prism::Reflection::Field
|
59
|
+
end
|
60
|
+
|
61
|
+
module Prism::Reflection
|
62
|
+
sig { params(node: T.class_of(Prism::Node)).returns(T::Array[Prism::Reflection::Field]) }
|
63
|
+
def self.fields_for(node); end
|
64
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# typed: strict
|
2
|
+
|
3
|
+
# We keep these shims in here because our client libraries might not have parser
|
4
|
+
# in their bundle.
|
5
|
+
module Parser; end
|
6
|
+
class Parser::Base; end
|
7
|
+
|
8
|
+
class Prism::Translation::Parser < Parser::Base
|
9
|
+
sig { overridable.returns(Integer) }
|
10
|
+
def version; end
|
11
|
+
end
|
data/rbi/prism.rbi
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
# typed: strict
|
2
2
|
|
3
3
|
module Prism
|
4
|
-
sig { params(source: String,
|
5
|
-
def self.dump(source,
|
4
|
+
sig { params(source: String, command_line: T.nilable(String), encoding: T.nilable(T.any(String, Encoding)), filepath: T.nilable(String), frozen_string_literal: T.nilable(T::Boolean), line: T.nilable(Integer), scopes: T.nilable(T::Array[T::Array[Symbol]]), version: T.nilable(String)).returns(String) }
|
5
|
+
def self.dump(source, command_line: nil, encoding: nil, filepath: nil, frozen_string_literal: nil, line: nil, scopes: nil, version: nil); end
|
6
6
|
|
7
|
-
sig { params(filepath: String,
|
8
|
-
def self.dump_file(filepath,
|
7
|
+
sig { params(filepath: String, command_line: T.nilable(String), encoding: T.nilable(T.any(String, Encoding)), frozen_string_literal: T.nilable(T::Boolean), line: T.nilable(Integer), scopes: T.nilable(T::Array[T::Array[Symbol]]), version: T.nilable(String)).returns(String) }
|
8
|
+
def self.dump_file(filepath, command_line: nil, encoding: nil, frozen_string_literal: nil, line: nil, scopes: nil, version: nil); end
|
9
9
|
|
10
|
-
sig { params(source: String,
|
11
|
-
def self.lex(source,
|
10
|
+
sig { params(source: String, command_line: T.nilable(String), encoding: T.nilable(T.any(String, Encoding)), filepath: T.nilable(String), frozen_string_literal: T.nilable(T::Boolean), line: T.nilable(Integer), scopes: T.nilable(T::Array[T::Array[Symbol]]), version: T.nilable(String)).returns(Prism::ParseResult[T::Array[T.untyped]]) }
|
11
|
+
def self.lex(source, command_line: nil, encoding: nil, filepath: nil, frozen_string_literal: nil, line: nil, scopes: nil, version: nil); end
|
12
12
|
|
13
|
-
sig { params(filepath: String,
|
14
|
-
def self.lex_file(filepath,
|
13
|
+
sig { params(filepath: String, command_line: T.nilable(String), encoding: T.nilable(T.any(String, Encoding)), frozen_string_literal: T.nilable(T::Boolean), line: T.nilable(Integer), scopes: T.nilable(T::Array[T::Array[Symbol]]), version: T.nilable(String)).returns(Prism::ParseResult[T::Array[T.untyped]]) }
|
14
|
+
def self.lex_file(filepath, command_line: nil, encoding: nil, frozen_string_literal: nil, line: nil, scopes: nil, version: nil); end
|
15
15
|
|
16
|
-
sig { params(source: String,
|
17
|
-
def self.lex_compat(source,
|
16
|
+
sig { params(source: String, options: T::Hash[Symbol, T.untyped]).returns(Prism::ParseResult[T::Array[T.untyped]]) }
|
17
|
+
def self.lex_compat(source, **options); end
|
18
18
|
|
19
19
|
sig { params(source: String).returns(T::Array[T.untyped]) }
|
20
20
|
def self.lex_ripper(source); end
|
@@ -22,36 +22,36 @@ module Prism
|
|
22
22
|
sig { params(source: String, serialized: String).returns(Prism::ParseResult[Prism::ProgramNode]) }
|
23
23
|
def self.load(source, serialized); end
|
24
24
|
|
25
|
-
sig { params(source: String,
|
26
|
-
def self.parse(source,
|
27
|
-
|
28
|
-
sig { params(filepath: String, line: T.nilable(Integer), offset: T.nilable(Integer), encoding: T.nilable(Encoding), frozen_string_literal: T.nilable(T::Boolean), verbose: T.nilable(T::Boolean), scopes: T.nilable(T::Array[T::Array[Symbol]])).returns(Prism::ParseResult[Prism::ProgramNode]) }
|
29
|
-
def self.parse_file(filepath, line: nil, offset: nil, encoding: nil, frozen_string_literal: nil, verbose: nil, scopes: nil); end
|
25
|
+
sig { params(source: String, command_line: T.nilable(String), encoding: T.nilable(T.any(String, Encoding)), filepath: T.nilable(String), frozen_string_literal: T.nilable(T::Boolean), line: T.nilable(Integer), scopes: T.nilable(T::Array[T::Array[Symbol]]), version: T.nilable(String)).returns(Prism::ParseResult[Prism::ProgramNode]) }
|
26
|
+
def self.parse(source, command_line: nil, encoding: nil, filepath: nil, frozen_string_literal: nil, line: nil, scopes: nil, version: nil); end
|
30
27
|
|
31
|
-
sig { params(
|
32
|
-
def self.
|
28
|
+
sig { params(filepath: String, command_line: T.nilable(String), encoding: T.nilable(T.any(String, Encoding)), frozen_string_literal: T.nilable(T::Boolean), line: T.nilable(Integer), scopes: T.nilable(T::Array[T::Array[Symbol]]), version: T.nilable(String)).returns(Prism::ParseResult[Prism::ProgramNode]) }
|
29
|
+
def self.parse_file(filepath, command_line: nil, encoding: nil, frozen_string_literal: nil, line: nil, scopes: nil, version: nil); end
|
33
30
|
|
34
|
-
sig { params(
|
35
|
-
def self.
|
31
|
+
sig { params(stream: T.any(IO, StringIO), command_line: T.nilable(String), encoding: T.nilable(T.any(String, Encoding)), filepath: T.nilable(String), frozen_string_literal: T.nilable(T::Boolean), line: T.nilable(Integer), scopes: T.nilable(T::Array[T::Array[Symbol]]), version: T.nilable(String)).returns(Prism::ParseResult[Prism::ProgramNode]) }
|
32
|
+
def self.parse_stream(stream, command_line: nil, encoding: nil, filepath: nil, frozen_string_literal: nil, line: nil, scopes: nil, version: nil); end
|
36
33
|
|
37
|
-
sig { params(
|
38
|
-
def self.
|
34
|
+
sig { params(source: String, command_line: T.nilable(String), encoding: T.nilable(T.any(String, Encoding)), filepath: T.nilable(String), frozen_string_literal: T.nilable(T::Boolean), line: T.nilable(Integer), scopes: T.nilable(T::Array[T::Array[Symbol]]), version: T.nilable(String)).returns(T::Array[Prism::Comment]) }
|
35
|
+
def self.parse_comments(source, command_line: nil, encoding: nil, filepath: nil, frozen_string_literal: nil, line: nil, scopes: nil, version: nil); end
|
39
36
|
|
40
|
-
sig { params(
|
41
|
-
def self.
|
37
|
+
sig { params(filepath: String, command_line: T.nilable(String), encoding: T.nilable(T.any(String, Encoding)), frozen_string_literal: T.nilable(T::Boolean), line: T.nilable(Integer), scopes: T.nilable(T::Array[T::Array[Symbol]]), version: T.nilable(String)).returns(T::Array[Prism::Comment]) }
|
38
|
+
def self.parse_file_comments(filepath, command_line: nil, encoding: nil, frozen_string_literal: nil, line: nil, scopes: nil, version: nil); end
|
42
39
|
|
43
|
-
sig { params(
|
44
|
-
def self.
|
40
|
+
sig { params(source: String, command_line: T.nilable(String), encoding: T.nilable(T.any(String, Encoding)), filepath: T.nilable(String), frozen_string_literal: T.nilable(T::Boolean), line: T.nilable(Integer), scopes: T.nilable(T::Array[T::Array[Symbol]]), version: T.nilable(String)).returns(Prism::ParseResult[[Prism::ProgramNode, T::Array[T.untyped]]]) }
|
41
|
+
def self.parse_lex(source, command_line: nil, encoding: nil, filepath: nil, frozen_string_literal: nil, line: nil, scopes: nil, version: nil); end
|
45
42
|
|
46
|
-
sig { params(
|
47
|
-
def self.
|
43
|
+
sig { params(filepath: String, command_line: T.nilable(String), encoding: T.nilable(T.any(String, Encoding)), frozen_string_literal: T.nilable(T::Boolean), line: T.nilable(Integer), scopes: T.nilable(T::Array[T::Array[Symbol]]), version: T.nilable(String)).returns(Prism::ParseResult[[Prism::ProgramNode, T::Array[T.untyped]]]) }
|
44
|
+
def self.parse_lex_file(filepath, command_line: nil, encoding: nil, frozen_string_literal: nil, line: nil, scopes: nil, version: nil); end
|
48
45
|
|
49
|
-
sig { params(source: String,
|
50
|
-
def self.
|
46
|
+
sig { params(source: String, command_line: T.nilable(String), encoding: T.nilable(T.any(String, Encoding)), filepath: T.nilable(String), frozen_string_literal: T.nilable(T::Boolean), line: T.nilable(Integer), scopes: T.nilable(T::Array[T::Array[Symbol]]), version: T.nilable(String)).returns(T::Boolean) }
|
47
|
+
def self.parse_success?(source, command_line: nil, encoding: nil, filepath: nil, frozen_string_literal: nil, line: nil, scopes: nil, version: nil); end
|
51
48
|
|
52
|
-
sig { params(
|
53
|
-
def self.
|
49
|
+
sig { params(source: String, command_line: T.nilable(String), encoding: T.nilable(T.any(String, Encoding)), filepath: T.nilable(String), frozen_string_literal: T.nilable(T::Boolean), line: T.nilable(Integer), scopes: T.nilable(T::Array[T::Array[Symbol]]), version: T.nilable(String)).returns(T::Boolean) }
|
50
|
+
def self.parse_failure?(source, command_line: nil, encoding: nil, filepath: nil, frozen_string_literal: nil, line: nil, scopes: nil, version: nil); end
|
54
51
|
|
55
|
-
sig { params(filepath: String,
|
56
|
-
def self.
|
52
|
+
sig { params(filepath: String, command_line: T.nilable(String), encoding: T.nilable(T.any(String, Encoding)), frozen_string_literal: T.nilable(T::Boolean), line: T.nilable(Integer), scopes: T.nilable(T::Array[T::Array[Symbol]]), version: T.nilable(String)).returns(T::Boolean) }
|
53
|
+
def self.parse_file_success?(filepath, command_line: nil, encoding: nil, frozen_string_literal: nil, line: nil, scopes: nil, version: nil); end
|
54
|
+
|
55
|
+
sig { params(filepath: String, command_line: T.nilable(String), encoding: T.nilable(T.any(String, Encoding)), frozen_string_literal: T.nilable(T::Boolean), line: T.nilable(Integer), scopes: T.nilable(T::Array[T::Array[Symbol]]), version: T.nilable(String)).returns(T::Boolean) }
|
56
|
+
def self.parse_file_failure?(filepath, command_line: nil, encoding: nil, frozen_string_literal: nil, line: nil, scopes: nil, version: nil); end
|
57
57
|
end
|
data/sig/prism/node.rbs
CHANGED
@@ -3,7 +3,14 @@
|
|
3
3
|
# if you are looking to modify the template
|
4
4
|
|
5
5
|
module Prism
|
6
|
+
# Methods implemented on every subclass of a singleton of Node
|
7
|
+
interface _NodeSingleton
|
8
|
+
def type: () -> Symbol
|
9
|
+
end
|
10
|
+
|
6
11
|
class Node
|
12
|
+
extend _NodeSingleton
|
13
|
+
|
7
14
|
attr_reader location: Location
|
8
15
|
attr_reader source: Source
|
9
16
|
|
@@ -14,6 +21,8 @@ module Prism
|
|
14
21
|
def to_dot: () -> String
|
15
22
|
end
|
16
23
|
|
24
|
+
type node_singleton = singleton(Node) & _NodeSingleton
|
25
|
+
|
17
26
|
# Methods implemented by every subclass of Node
|
18
27
|
interface _Node
|
19
28
|
def accept: (_Visitor) -> void
|
@@ -21,7 +30,7 @@ module Prism
|
|
21
30
|
def deconstruct: () -> Array[Prism::node?]
|
22
31
|
def compact_child_nodes: () -> Array[Prism::node]
|
23
32
|
def comment_targets: () -> Array[Prism::node | Location]
|
24
|
-
|
33
|
+
def fields: () -> Array[Prism::Reflection::Field]
|
25
34
|
def inspect: (?untyped) -> String
|
26
35
|
def type: () -> Symbol
|
27
36
|
end
|
data/sig/prism/parse_result.rbs
CHANGED
@@ -29,6 +29,7 @@ module Prism
|
|
29
29
|
def trailing_comment: (comment) -> void
|
30
30
|
def comments: () -> Array[comment]
|
31
31
|
def copy: (?source: Source, ?start_offset: Integer, ?length: Integer) -> Location
|
32
|
+
def chop: () -> Location
|
32
33
|
def slice: () -> String
|
33
34
|
def start_character_offset: () -> Integer
|
34
35
|
def end_offset: () -> Integer
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Prism
|
2
|
+
module Reflection
|
3
|
+
class Field
|
4
|
+
attr_reader name: Symbol
|
5
|
+
|
6
|
+
def initialize: (Symbol name) -> void
|
7
|
+
end
|
8
|
+
|
9
|
+
class NodeField < Field
|
10
|
+
end
|
11
|
+
|
12
|
+
class OptionalNodeField < Field
|
13
|
+
end
|
14
|
+
|
15
|
+
class NodeListField < Field
|
16
|
+
end
|
17
|
+
|
18
|
+
class ConstantField < Field
|
19
|
+
end
|
20
|
+
|
21
|
+
class OptionalConstantField < Field
|
22
|
+
end
|
23
|
+
|
24
|
+
class ConstantListField < Field
|
25
|
+
end
|
26
|
+
|
27
|
+
class StringField < Field
|
28
|
+
end
|
29
|
+
|
30
|
+
class LocationField < Field
|
31
|
+
end
|
32
|
+
|
33
|
+
class OptionalLocationField < Field
|
34
|
+
end
|
35
|
+
|
36
|
+
class UInt8Field < Field
|
37
|
+
end
|
38
|
+
|
39
|
+
class UInt32Field < Field
|
40
|
+
end
|
41
|
+
|
42
|
+
class FlagsField < Field
|
43
|
+
attr_reader flags: Array[Symbol]
|
44
|
+
|
45
|
+
def initialize: (Symbol name, Array[Symbol] flags) -> void
|
46
|
+
end
|
47
|
+
|
48
|
+
class IntegerField < Field
|
49
|
+
end
|
50
|
+
|
51
|
+
class DoubleField < Field
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.fields_for: (node_singleton node) -> Array[Field]
|
55
|
+
end
|
56
|
+
end
|
data/sig/prism.rbs
CHANGED
@@ -178,10 +178,10 @@ module Prism
|
|
178
178
|
) -> bool
|
179
179
|
|
180
180
|
interface _Stream
|
181
|
-
def gets(?Integer integer) -> String | nil
|
181
|
+
def gets: (?Integer integer) -> (String | nil)
|
182
182
|
end
|
183
183
|
|
184
|
-
def self.parse_stream(
|
184
|
+
def self.parse_stream: (
|
185
185
|
_Stream stream,
|
186
186
|
?filepath: String,
|
187
187
|
?line: Integer,
|
data/src/diagnostic.c
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
|
9
9
|
#include "prism/diagnostic.h"
|
10
10
|
|
11
|
-
#define PM_DIAGNOSTIC_ID_MAX
|
11
|
+
#define PM_DIAGNOSTIC_ID_MAX 281
|
12
12
|
|
13
13
|
/** This struct holds the data for each diagnostic. */
|
14
14
|
typedef struct {
|
@@ -107,13 +107,13 @@ static const pm_diagnostic_data_t diagnostic_messages[PM_DIAGNOSTIC_ID_MAX] = {
|
|
107
107
|
[PM_ERR_ARGUMENT_FORMAL_IVAR] = { "invalid formal argument; formal argument cannot be an instance variable", PM_ERROR_LEVEL_SYNTAX },
|
108
108
|
[PM_ERR_ARGUMENT_FORWARDING_UNBOUND] = { "unexpected `...` in an non-parenthesized call", PM_ERROR_LEVEL_SYNTAX },
|
109
109
|
[PM_ERR_ARGUMENT_IN] = { "unexpected `in` keyword in arguments", PM_ERROR_LEVEL_SYNTAX },
|
110
|
-
[PM_ERR_ARGUMENT_NO_FORWARDING_AMP] = { "unexpected
|
110
|
+
[PM_ERR_ARGUMENT_NO_FORWARDING_AMP] = { "unexpected `&`; no anonymous block parameter", PM_ERROR_LEVEL_SYNTAX },
|
111
111
|
[PM_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES] = { "unexpected ... when the parent method is not forwarding", PM_ERROR_LEVEL_SYNTAX },
|
112
112
|
[PM_ERR_ARGUMENT_NO_FORWARDING_STAR] = { "unexpected `*`; no anonymous rest parameter", PM_ERROR_LEVEL_SYNTAX },
|
113
113
|
[PM_ERR_ARGUMENT_NO_FORWARDING_STAR_STAR] = { "unexpected `**`; no anonymous keyword rest parameter", PM_ERROR_LEVEL_SYNTAX },
|
114
114
|
[PM_ERR_ARGUMENT_SPLAT_AFTER_ASSOC_SPLAT] = { "unexpected `*` splat argument after a `**` keyword splat argument", PM_ERROR_LEVEL_SYNTAX },
|
115
115
|
[PM_ERR_ARGUMENT_SPLAT_AFTER_SPLAT] = { "unexpected `*` splat argument after a `*` splat argument", PM_ERROR_LEVEL_SYNTAX },
|
116
|
-
[PM_ERR_ARGUMENT_TERM_PAREN] = { "expected a `)` to close the arguments", PM_ERROR_LEVEL_SYNTAX },
|
116
|
+
[PM_ERR_ARGUMENT_TERM_PAREN] = { "unexpected %s; expected a `)` to close the arguments", PM_ERROR_LEVEL_SYNTAX },
|
117
117
|
[PM_ERR_ARGUMENT_UNEXPECTED_BLOCK] = { "unexpected `{` after a method call without parenthesis", PM_ERROR_LEVEL_SYNTAX },
|
118
118
|
[PM_ERR_ARRAY_ELEMENT] = { "expected an element for the array", PM_ERROR_LEVEL_SYNTAX },
|
119
119
|
[PM_ERR_ARRAY_EXPRESSION] = { "expected an expression for the array element", PM_ERROR_LEVEL_SYNTAX },
|
@@ -152,15 +152,14 @@ static const pm_diagnostic_data_t diagnostic_messages[PM_DIAGNOSTIC_ID_MAX] = {
|
|
152
152
|
[PM_ERR_CONSTANT_PATH_COLON_COLON_CONSTANT] = { "expected a constant after the `::` operator", PM_ERROR_LEVEL_SYNTAX },
|
153
153
|
[PM_ERR_DEF_ENDLESS] = { "could not parse the endless method body", PM_ERROR_LEVEL_SYNTAX },
|
154
154
|
[PM_ERR_DEF_ENDLESS_SETTER] = { "invalid method name; a setter method cannot be defined in an endless method definition", PM_ERROR_LEVEL_SYNTAX },
|
155
|
-
[PM_ERR_DEF_NAME] = { "expected a method name", PM_ERROR_LEVEL_SYNTAX },
|
156
|
-
[PM_ERR_DEF_NAME_AFTER_RECEIVER] = { "expected a method name after the receiver", PM_ERROR_LEVEL_SYNTAX },
|
155
|
+
[PM_ERR_DEF_NAME] = { "unexpected %s; expected a method name", PM_ERROR_LEVEL_SYNTAX },
|
157
156
|
[PM_ERR_DEF_PARAMS_TERM] = { "expected a delimiter to close the parameters", PM_ERROR_LEVEL_SYNTAX },
|
158
157
|
[PM_ERR_DEF_PARAMS_TERM_PAREN] = { "expected a `)` to close the parameters", PM_ERROR_LEVEL_SYNTAX },
|
159
158
|
[PM_ERR_DEF_RECEIVER] = { "expected a receiver for the method definition", PM_ERROR_LEVEL_SYNTAX },
|
160
159
|
[PM_ERR_DEF_RECEIVER_TERM] = { "expected a `.` or `::` after the receiver in a method definition", PM_ERROR_LEVEL_SYNTAX },
|
161
160
|
[PM_ERR_DEF_TERM] = { "expected an `end` to close the `def` statement", PM_ERROR_LEVEL_SYNTAX },
|
162
161
|
[PM_ERR_DEFINED_EXPRESSION] = { "expected an expression after `defined?`", PM_ERROR_LEVEL_SYNTAX },
|
163
|
-
[PM_ERR_EMBDOC_TERM] = { "
|
162
|
+
[PM_ERR_EMBDOC_TERM] = { "embedded document meets end of file", PM_ERROR_LEVEL_SYNTAX },
|
164
163
|
[PM_ERR_EMBEXPR_END] = { "expected a `}` to close the embedded expression", PM_ERROR_LEVEL_SYNTAX },
|
165
164
|
[PM_ERR_EMBVAR_INVALID] = { "invalid embedded variable", PM_ERROR_LEVEL_SYNTAX },
|
166
165
|
[PM_ERR_END_UPCASE_BRACE] = { "expected a `{` after `END`", PM_ERROR_LEVEL_SYNTAX },
|
@@ -189,6 +188,7 @@ static const pm_diagnostic_data_t diagnostic_messages[PM_DIAGNOSTIC_ID_MAX] = {
|
|
189
188
|
[PM_ERR_EXPECT_EXPRESSION_AFTER_STAR] = { "expected an expression after `*`", PM_ERROR_LEVEL_SYNTAX },
|
190
189
|
[PM_ERR_EXPECT_IDENT_REQ_PARAMETER] = { "expected an identifier for the required parameter", PM_ERROR_LEVEL_SYNTAX },
|
191
190
|
[PM_ERR_EXPECT_LPAREN_REQ_PARAMETER] = { "expected a `(` to start a required parameter", PM_ERROR_LEVEL_SYNTAX },
|
191
|
+
[PM_ERR_EXPECT_MESSAGE] = { "unexpected %s; expecting a message to send to the receiver", PM_ERROR_LEVEL_SYNTAX },
|
192
192
|
[PM_ERR_EXPECT_RBRACKET] = { "expected a matching `]`", PM_ERROR_LEVEL_SYNTAX },
|
193
193
|
[PM_ERR_EXPECT_RPAREN] = { "expected a matching `)`", PM_ERROR_LEVEL_SYNTAX },
|
194
194
|
[PM_ERR_EXPECT_RPAREN_AFTER_MULTI] = { "expected a `)` after multiple assignment", PM_ERROR_LEVEL_SYNTAX },
|
@@ -196,6 +196,14 @@ static const pm_diagnostic_data_t diagnostic_messages[PM_DIAGNOSTIC_ID_MAX] = {
|
|
196
196
|
[PM_ERR_EXPECT_STRING_CONTENT] = { "expected string content after opening string delimiter", PM_ERROR_LEVEL_SYNTAX },
|
197
197
|
[PM_ERR_EXPECT_WHEN_DELIMITER] = { "expected a delimiter after the predicates of a `when` clause", PM_ERROR_LEVEL_SYNTAX },
|
198
198
|
[PM_ERR_EXPRESSION_BARE_HASH] = { "unexpected bare hash in expression", PM_ERROR_LEVEL_SYNTAX },
|
199
|
+
[PM_ERR_EXPRESSION_NOT_WRITABLE] = { "unexpected '='; target cannot be written", PM_ERROR_LEVEL_SYNTAX },
|
200
|
+
[PM_ERR_EXPRESSION_NOT_WRITABLE_ENCODING] = { "Can't assign to __ENCODING__", PM_ERROR_LEVEL_SYNTAX },
|
201
|
+
[PM_ERR_EXPRESSION_NOT_WRITABLE_FALSE] = { "Can't assign to false", PM_ERROR_LEVEL_SYNTAX },
|
202
|
+
[PM_ERR_EXPRESSION_NOT_WRITABLE_FILE] = { "Can't assign to __FILE__", PM_ERROR_LEVEL_SYNTAX },
|
203
|
+
[PM_ERR_EXPRESSION_NOT_WRITABLE_LINE] = { "Can't assign to __LINE__", PM_ERROR_LEVEL_SYNTAX },
|
204
|
+
[PM_ERR_EXPRESSION_NOT_WRITABLE_NIL] = { "Can't assign to nil", PM_ERROR_LEVEL_SYNTAX },
|
205
|
+
[PM_ERR_EXPRESSION_NOT_WRITABLE_SELF] = { "Can't change the value of self", PM_ERROR_LEVEL_SYNTAX },
|
206
|
+
[PM_ERR_EXPRESSION_NOT_WRITABLE_TRUE] = { "Can't assign to true", PM_ERROR_LEVEL_SYNTAX },
|
199
207
|
[PM_ERR_FLOAT_PARSE] = { "could not parse the float '%.*s'", PM_ERROR_LEVEL_SYNTAX },
|
200
208
|
[PM_ERR_FOR_COLLECTION] = { "expected a collection after the `in` in a `for` statement", PM_ERROR_LEVEL_SYNTAX },
|
201
209
|
[PM_ERR_FOR_INDEX] = { "expected an index after `for`", PM_ERROR_LEVEL_SYNTAX },
|
@@ -325,6 +333,7 @@ static const pm_diagnostic_data_t diagnostic_messages[PM_DIAGNOSTIC_ID_MAX] = {
|
|
325
333
|
[PM_ERR_TERNARY_EXPRESSION_TRUE] = { "expected an expression after `?` in the ternary operator", PM_ERROR_LEVEL_SYNTAX },
|
326
334
|
[PM_ERR_UNDEF_ARGUMENT] = { "invalid argument being passed to `undef`; expected a bare word, constant, or symbol argument", PM_ERROR_LEVEL_SYNTAX },
|
327
335
|
[PM_ERR_UNARY_RECEIVER] = { "unexpected %s, expected a receiver for unary `%c`", PM_ERROR_LEVEL_SYNTAX },
|
336
|
+
[PM_ERR_UNEXPECTED_BLOCK_ARGUMENT] = { "block argument should not be given", PM_ERROR_LEVEL_SYNTAX },
|
328
337
|
[PM_ERR_UNEXPECTED_TOKEN_CLOSE_CONTEXT] = { "unexpected %s, assuming it is closing the parent %s", PM_ERROR_LEVEL_SYNTAX },
|
329
338
|
[PM_ERR_UNEXPECTED_TOKEN_IGNORE] = { "unexpected %s, ignoring it", PM_ERROR_LEVEL_SYNTAX },
|
330
339
|
[PM_ERR_UNTIL_TERM] = { "expected an `end` to close the `until` statement", PM_ERROR_LEVEL_SYNTAX },
|
@@ -360,7 +369,9 @@ static const pm_diagnostic_data_t diagnostic_messages[PM_DIAGNOSTIC_ID_MAX] = {
|
|
360
369
|
[PM_WARN_LITERAL_IN_CONDITION_VERBOSE] = { "%sliteral in %s", PM_WARNING_LEVEL_VERBOSE },
|
361
370
|
[PM_WARN_SHEBANG_CARRIAGE_RETURN] = { "shebang line ending with \\r may cause problems", PM_WARNING_LEVEL_DEFAULT },
|
362
371
|
[PM_WARN_UNEXPECTED_CARRIAGE_RETURN] = { "encountered \\r in middle of line, treated as a mere space", PM_WARNING_LEVEL_DEFAULT },
|
363
|
-
[
|
372
|
+
[PM_WARN_UNREACHABLE_STATEMENT] = { "statement not reached", PM_WARNING_LEVEL_VERBOSE },
|
373
|
+
[PM_WARN_UNUSED_LOCAL_VARIABLE] = { "assigned but unused variable - %.*s", PM_WARNING_LEVEL_VERBOSE },
|
374
|
+
[PM_WARN_VOID_STATEMENT] = { "possibly useless use of %.*s in void context", PM_WARNING_LEVEL_VERBOSE }
|
364
375
|
};
|
365
376
|
|
366
377
|
/**
|
@@ -430,7 +441,6 @@ pm_diagnostic_id_human(pm_diagnostic_id_t diag_id) {
|
|
430
441
|
case PM_ERR_DEF_ENDLESS: return "def_endless";
|
431
442
|
case PM_ERR_DEF_ENDLESS_SETTER: return "def_endless_setter";
|
432
443
|
case PM_ERR_DEF_NAME: return "def_name";
|
433
|
-
case PM_ERR_DEF_NAME_AFTER_RECEIVER: return "def_name_after_receiver";
|
434
444
|
case PM_ERR_DEF_PARAMS_TERM: return "def_params_term";
|
435
445
|
case PM_ERR_DEF_PARAMS_TERM_PAREN: return "def_params_term_paren";
|
436
446
|
case PM_ERR_DEF_RECEIVER: return "def_receiver";
|
@@ -467,6 +477,7 @@ pm_diagnostic_id_human(pm_diagnostic_id_t diag_id) {
|
|
467
477
|
case PM_ERR_EXPECT_EXPRESSION_AFTER_STAR: return "expect_expression_after_star";
|
468
478
|
case PM_ERR_EXPECT_IDENT_REQ_PARAMETER: return "expect_ident_req_parameter";
|
469
479
|
case PM_ERR_EXPECT_LPAREN_REQ_PARAMETER: return "expect_lparen_req_parameter";
|
480
|
+
case PM_ERR_EXPECT_MESSAGE: return "expect_message";
|
470
481
|
case PM_ERR_EXPECT_RBRACKET: return "expect_rbracket";
|
471
482
|
case PM_ERR_EXPECT_RPAREN: return "expect_rparen";
|
472
483
|
case PM_ERR_EXPECT_RPAREN_AFTER_MULTI: return "expect_rparen_after_multi";
|
@@ -474,6 +485,14 @@ pm_diagnostic_id_human(pm_diagnostic_id_t diag_id) {
|
|
474
485
|
case PM_ERR_EXPECT_STRING_CONTENT: return "expect_string_content";
|
475
486
|
case PM_ERR_EXPECT_WHEN_DELIMITER: return "expect_when_delimiter";
|
476
487
|
case PM_ERR_EXPRESSION_BARE_HASH: return "expression_bare_hash";
|
488
|
+
case PM_ERR_EXPRESSION_NOT_WRITABLE: return "expression_not_writable";
|
489
|
+
case PM_ERR_EXPRESSION_NOT_WRITABLE_ENCODING: return "expression_not_writable_encoding";
|
490
|
+
case PM_ERR_EXPRESSION_NOT_WRITABLE_FALSE: return "expression_not_writable_false";
|
491
|
+
case PM_ERR_EXPRESSION_NOT_WRITABLE_FILE: return "expression_not_writable_file";
|
492
|
+
case PM_ERR_EXPRESSION_NOT_WRITABLE_LINE: return "expression_not_writable_line";
|
493
|
+
case PM_ERR_EXPRESSION_NOT_WRITABLE_NIL: return "expression_not_writable_nil";
|
494
|
+
case PM_ERR_EXPRESSION_NOT_WRITABLE_SELF: return "expression_not_writable_self";
|
495
|
+
case PM_ERR_EXPRESSION_NOT_WRITABLE_TRUE: return "expression_not_writable_true";
|
477
496
|
case PM_ERR_FLOAT_PARSE: return "float_parse";
|
478
497
|
case PM_ERR_FOR_COLLECTION: return "for_collection";
|
479
498
|
case PM_ERR_FOR_IN: return "for_in";
|
@@ -605,6 +624,7 @@ pm_diagnostic_id_human(pm_diagnostic_id_t diag_id) {
|
|
605
624
|
case PM_ERR_TERNARY_EXPRESSION_TRUE: return "ternary_expression_true";
|
606
625
|
case PM_ERR_UNARY_RECEIVER: return "unary_receiver";
|
607
626
|
case PM_ERR_UNDEF_ARGUMENT: return "undef_argument";
|
627
|
+
case PM_ERR_UNEXPECTED_BLOCK_ARGUMENT: return "unexpected_block_argument";
|
608
628
|
case PM_ERR_UNEXPECTED_TOKEN_CLOSE_CONTEXT: return "unexpected_token_close_context";
|
609
629
|
case PM_ERR_UNEXPECTED_TOKEN_IGNORE: return "unexpected_token_ignore";
|
610
630
|
case PM_ERR_UNTIL_TERM: return "until_term";
|
@@ -638,7 +658,9 @@ pm_diagnostic_id_human(pm_diagnostic_id_t diag_id) {
|
|
638
658
|
case PM_WARN_LITERAL_IN_CONDITION_VERBOSE: return "literal_in_condition_verbose";
|
639
659
|
case PM_WARN_SHEBANG_CARRIAGE_RETURN: return "shebang_carriage_return";
|
640
660
|
case PM_WARN_UNEXPECTED_CARRIAGE_RETURN: return "unexpected_carriage_return";
|
661
|
+
case PM_WARN_UNREACHABLE_STATEMENT: return "unreachable_statement";
|
641
662
|
case PM_WARN_UNUSED_LOCAL_VARIABLE: return "unused_local_variable";
|
663
|
+
case PM_WARN_VOID_STATEMENT: return "void_statement";
|
642
664
|
}
|
643
665
|
|
644
666
|
assert(false && "unreachable");
|
data/src/options.c
CHANGED
@@ -47,29 +47,40 @@ pm_options_command_line_set(pm_options_t *options, uint8_t command_line) {
|
|
47
47
|
*/
|
48
48
|
PRISM_EXPORTED_FUNCTION bool
|
49
49
|
pm_options_version_set(pm_options_t *options, const char *version, size_t length) {
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
switch (length) {
|
51
|
+
case 0:
|
52
|
+
if (version == NULL) {
|
53
|
+
options->version = PM_OPTIONS_VERSION_LATEST;
|
54
|
+
return true;
|
55
|
+
}
|
54
56
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
return true;
|
59
|
-
}
|
57
|
+
return false;
|
58
|
+
case 5:
|
59
|
+
assert(version != NULL);
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
}
|
61
|
+
if (strncmp(version, "3.3.0", length) == 0) {
|
62
|
+
options->version = PM_OPTIONS_VERSION_CRUBY_3_3_0;
|
63
|
+
return true;
|
64
|
+
}
|
66
65
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
66
|
+
if (strncmp(version, "3.4.0", length) == 0) {
|
67
|
+
options->version = PM_OPTIONS_VERSION_LATEST;
|
68
|
+
return true;
|
69
|
+
}
|
70
|
+
|
71
|
+
return false;
|
72
|
+
case 6:
|
73
|
+
assert(version != NULL);
|
71
74
|
|
72
|
-
|
75
|
+
if (strncmp(version, "latest", length) == 0) {
|
76
|
+
options->version = PM_OPTIONS_VERSION_LATEST;
|
77
|
+
return true;
|
78
|
+
}
|
79
|
+
|
80
|
+
return false;
|
81
|
+
default:
|
82
|
+
return false;
|
83
|
+
}
|
73
84
|
}
|
74
85
|
|
75
86
|
// For some reason, GCC analyzer thinks we're leaking allocated scopes and
|