Class: Oxc::ParseResult
- Inherits:
-
Object
show all
- Includes:
- Diagnosed
- Defined in:
- lib/oxc/parse_result.rb,
sig/oxc/parse_result.rbs
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#initialize(comments:, diagnostics:, source: nil, program: nil, module_record: nil, symbols: nil, panicked: false) ⇒ ParseResult
constructor
: (comments: Array, diagnostics: Array, ?source: String?, ?program: Hash[String, untyped]?, ?module_record: Hash[String, untyped]?, ?symbols: Hash[String, untyped]?, ?panicked: bool) -> void.
-
#inspect ⇒ String
-
#root ⇒ Oxc::Node?
-
#validate! ⇒ Oxc::ParseResult
: () -> Oxc::ParseResult.
Methods included from Diagnosed
#errors, #errors?, #panicked?, #warnings, #warnings?
Constructor Details
#initialize(comments:, diagnostics:, source: nil, program: nil, module_record: nil, symbols: nil, panicked: false) ⇒ ParseResult
: (comments: Array, diagnostics: Array, ?source: String?, ?program: Hash[String, untyped]?, ?module_record: Hash[String, untyped]?, ?symbols: Hash[String, untyped]?, ?panicked: bool) -> void
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/oxc/parse_result.rb', line 30
def initialize(comments:, diagnostics:, source: nil, program: nil, module_record: nil, symbols: nil, panicked: false)
@source = source
@program = program.freeze
@module_record = module_record.freeze
@symbols = symbols.freeze
@comments = .freeze
@diagnostics = diagnostics.freeze
@panicked = panicked
freeze
end
|
Instance Attribute Details
11
12
13
|
# File 'lib/oxc/parse_result.rb', line 11
def
@comments
end
|
12
13
14
|
# File 'lib/oxc/parse_result.rb', line 12
def diagnostics
@diagnostics
end
|
#module_record ⇒ Hash[String, untyped]?
9
10
11
|
# File 'lib/oxc/parse_result.rb', line 9
def module_record
@module_record
end
|
#program ⇒ Hash[String, untyped]?
8
9
10
|
# File 'lib/oxc/parse_result.rb', line 8
def program
@program
end
|
#source ⇒ String?
7
8
9
|
# File 'lib/oxc/parse_result.rb', line 7
def source
@source
end
|
#symbols ⇒ Hash[String, untyped]?
10
11
12
|
# File 'lib/oxc/parse_result.rb', line 10
def symbols
@symbols
end
|
Class Method Details
.from_json(payload, source = nil) ⇒ Oxc::ParseResult
: (String, ?String?) -> Oxc::ParseResult
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/oxc/parse_result.rb', line 15
def self.from_json(payload, source = nil)
parsed = JSON.parse(payload)
new(
source: source,
program: parsed["program"],
module_record: parsed["module_record"],
symbols: parsed["symbols"],
comments: parsed.fetch("comments").map { || Comment.from_hash() },
diagnostics: parsed.fetch("errors").map { |diagnostic| Diagnostic.from_hash(diagnostic) },
panicked: parsed.fetch("panicked")
)
end
|
Instance Method Details
#inspect ⇒ String
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/oxc/parse_result.rb', line 55
def inspect
parts = [] parts << "#{root&.type} range=[#{root&.start}, #{root&.finish}]" if program
parts << "module_record" if module_record
parts << "symbols=#{symbols.fetch("declared").length}" if symbols
parts << "comments=#{.length}" unless .empty?
parts << "diagnostics=#{diagnostics.length}" unless diagnostics.empty?
"#<#{self.class.name}#{" #{parts.join(" ")}" unless parts.empty?}>"
end
|
43
44
45
|
# File 'lib/oxc/parse_result.rb', line 43
def root
program ? Node.new(program, nil, source) : nil
end
|
48
49
50
51
52
|
# File 'lib/oxc/parse_result.rb', line 48
def validate!
return self unless errors? || panicked?
raise SyntaxError.new(errors.first&.message || "oxc could not read the source", self)
end
|