Class: Kumi::Parser::TextParser::Api
- Inherits:
-
Object
- Object
- Kumi::Parser::TextParser::Api
- Defined in:
- lib/kumi/parser/text_parser/api.rb
Overview
Public API for TextParser
Class Method Summary collapse
- .analyze(text, source_file: '<input>') ⇒ Object
- .diagnostics_as_json(text, source_file: '<input>') ⇒ Object
- .diagnostics_for_codemirror(text, source_file: '<input>') ⇒ Object
- .diagnostics_for_monaco(text, source_file: '<input>') ⇒ Object
- .parse(text, source_file: '<input>') ⇒ Object
- .valid?(text, source_file: '<input>') ⇒ Boolean
- .validate(text, source_file: '<input>') ⇒ Object
Class Method Details
.analyze(text, source_file: '<input>') ⇒ Object
39 40 41 42 43 44 |
# File 'lib/kumi/parser/text_parser/api.rb', line 39 def analyze(text, source_file: '<input>') ast = parse(text, source_file: source_file) { success: true, ast: ast, diagnostics: [] } rescue StandardError => e { success: false, ast: nil, diagnostics: [create_diagnostic(e, source_file)] } end |
.diagnostics_as_json(text, source_file: '<input>') ⇒ Object
35 36 37 |
# File 'lib/kumi/parser/text_parser/api.rb', line 35 def diagnostics_as_json(text, source_file: '<input>') validate(text, source_file: source_file).map(&:to_h) end |
.diagnostics_for_codemirror(text, source_file: '<input>') ⇒ Object
31 32 33 |
# File 'lib/kumi/parser/text_parser/api.rb', line 31 def diagnostics_for_codemirror(text, source_file: '<input>') validate(text, source_file: source_file) end |
.diagnostics_for_monaco(text, source_file: '<input>') ⇒ Object
27 28 29 |
# File 'lib/kumi/parser/text_parser/api.rb', line 27 def diagnostics_for_monaco(text, source_file: '<input>') validate(text, source_file: source_file) end |
.parse(text, source_file: '<input>') ⇒ Object
11 12 13 14 |
# File 'lib/kumi/parser/text_parser/api.rb', line 11 def parse(text, source_file: '<input>') parser = Parser.new parser.parse(text, source_file: source_file) end |
.valid?(text, source_file: '<input>') ⇒ Boolean
23 24 25 |
# File 'lib/kumi/parser/text_parser/api.rb', line 23 def valid?(text, source_file: '<input>') validate(text, source_file: source_file).empty? end |
.validate(text, source_file: '<input>') ⇒ Object
16 17 18 19 20 21 |
# File 'lib/kumi/parser/text_parser/api.rb', line 16 def validate(text, source_file: '<input>') parse(text, source_file: source_file) [] rescue StandardError => e [create_diagnostic(e, source_file)] end |