Class: Herb::ParseResult
- Defined in:
- lib/herb/parse_result.rb,
ext/herb/extension.c
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
: Herb::ParserOptions.
-
#value ⇒ Object
readonly
: Herb::AST::DocumentNode.
Attributes inherited from Result
Instance Method Summary collapse
-
#errors ⇒ Object
: () -> Array.
-
#failed? ⇒ Boolean
: () -> bool.
- #initialize(value, source, warnings, errors, options) ⇒ ParseResult constructor
-
#pretty_errors ⇒ Object
: () -> String.
-
#success? ⇒ Boolean
: () -> bool.
-
#visit(visitor) ⇒ Object
: (Visitor) -> void.
Constructor Details
#initialize(value, source, warnings, errors, options) ⇒ ParseResult
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/herb/parse_result.rb', line 12 def initialize(value, source, warnings, errors, ) @value = value @options = super(source, warnings, errors) if .prism_nodes || .prism_nodes_deep value.source = source elsif .prism_program # Using `instance_variable_set` doesn't propagate the source being set on the whole tree value.instance_variable_set(:@source, source) end end |
Instance Attribute Details
#options ⇒ Object (readonly)
: Herb::ParserOptions
9 10 11 |
# File 'lib/herb/parse_result.rb', line 9 def @options end |
#value ⇒ Object (readonly)
: Herb::AST::DocumentNode
8 9 10 |
# File 'lib/herb/parse_result.rb', line 8 def value @value end |
Instance Method Details
#errors ⇒ Object
: () -> Array
26 27 28 |
# File 'lib/herb/parse_result.rb', line 26 def errors super + value.recursive_errors end |
#failed? ⇒ Boolean
: () -> bool
31 32 33 |
# File 'lib/herb/parse_result.rb', line 31 def failed? errors.any? end |
#pretty_errors ⇒ Object
: () -> String
41 42 43 |
# File 'lib/herb/parse_result.rb', line 41 def pretty_errors JSON.pretty_generate(errors) end |
#success? ⇒ Boolean
: () -> bool
36 37 38 |
# File 'lib/herb/parse_result.rb', line 36 def success? !failed? end |
#visit(visitor) ⇒ Object
: (Visitor) -> void
46 47 48 |
# File 'lib/herb/parse_result.rb', line 46 def visit(visitor) value.accept(visitor) end |