Module: Kumi::Parser::TextParser

Defined in:
lib/kumi/parser/text_parser.rb,
lib/kumi/parser/text_parser/api.rb

Defined Under Namespace

Classes: Api

Class Method Summary collapse

Class Method Details

.parse(text, source_file: '<input>') ⇒ Object

Parse text to AST



14
15
16
17
18
19
20
# File 'lib/kumi/parser/text_parser.rb', line 14

def parse(text, source_file: '<input>')
  tokens = Kumi::Parser::SmartTokenizer.new(text, source_file: source_file).tokenize
  Kumi::Parser::DirectParser.new(tokens).parse
rescue Kumi::Parser::Errors::ParseError, Kumi::Parser::Errors::TokenizerError => e
  # Convert parser errors to the expected SyntaxError for compatibility
  raise Kumi::Errors::SyntaxError, e.message
end

.valid?(text, source_file: '<input>') ⇒ Boolean

Check if text is syntactically valid

Returns:

  • (Boolean)


23
24
25
26
27
28
# File 'lib/kumi/parser/text_parser.rb', line 23

def valid?(text, source_file: '<input>')
  parse(text, source_file: source_file)
  true
rescue StandardError => e
  false
end

.validate(text, source_file: '<input>') ⇒ Object

Basic validation - returns array of error hashes



31
32
33
34
35
# File 'lib/kumi/parser/text_parser.rb', line 31

def validate(text, source_file: '<input>')
  # Use SyntaxValidator for proper diagnostic extraction
  validator = Kumi::Parser::SyntaxValidator.new
  validator.validate(text, source_file: source_file)
end