Class: Bullematic::AST::Parser
- Inherits:
-
Object
- Object
- Bullematic::AST::Parser
- Defined in:
- lib/bullematic/ast/parser.rb,
sig/generated/bullematic/ast/parser.rbs
Instance Attribute Summary collapse
- #filepath ⇒ Object readonly
- #source_code ⇒ Object readonly
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(source_code, filepath: nil) ⇒ Parser
constructor
A new instance of Parser.
-
#parse ⇒ Object
: () -> untyped.
Constructor Details
#initialize(source_code, filepath: nil) ⇒ Parser
Returns a new instance of Parser.
28 29 30 31 |
# File 'lib/bullematic/ast/parser.rb', line 28 def initialize(source_code, filepath: nil) @source_code = source_code @filepath = filepath end |
Instance Attribute Details
#filepath ⇒ Object (readonly)
23 24 25 |
# File 'lib/bullematic/ast/parser.rb', line 23 def filepath @filepath end |
#source_code ⇒ Object (readonly)
23 24 25 |
# File 'lib/bullematic/ast/parser.rb', line 23 def source_code @source_code end |
Class Method Details
.parse_file(filepath) ⇒ Object
15 16 17 |
# File 'lib/bullematic/ast/parser.rb', line 15 def parse_file(filepath) new(File.binread(filepath), filepath: filepath).parse end |
Instance Method Details
#parse ⇒ Object
: () -> untyped
34 35 36 37 38 39 |
# File 'lib/bullematic/ast/parser.rb', line 34 def parse result = Prism.parse(@source_code, filepath: @filepath) raise ParseError, result.errors.map(&:message).join("\n") if result.failure? result end |