Module: Musa::Neumalang::Neumalang

Extended by:
Neumalang
Included in:
Neumalang
Defined in:
lib/musa-dsl/neumalang/neumalang.rb

Defined Under Namespace

Modules: Parser

Instance Method Summary collapse

Instance Method Details

#parse(string_or_file, decode_with: nil, debug: nil) ⇒ Object



336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
# File 'lib/musa-dsl/neumalang/neumalang.rb', line 336

def parse(string_or_file, decode_with: nil, debug: nil)
  case string_or_file
  when String
    match = Parser::Grammar::Grammar.parse string_or_file

  when File
    match = Parser::Grammar::Grammar.parse string_or_file.read

  else
    raise ArgumentError, 'Only String or File allowed to be parsed'
  end

  match.dump if debug

  serie = match.value

  if decode_with
    serie.eval do |e|
      if e[:kind] == :gdvd
        decode_with.decode(e[:gdvd])
      else
        raise ArgumentError, "Don't know how to convert #{e} to neumas"
      end
    end
  else
    serie
  end
end

#parse_file(filename, decode_with: nil, debug: nil) ⇒ Object



365
366
367
368
369
# File 'lib/musa-dsl/neumalang/neumalang.rb', line 365

def parse_file(filename, decode_with: nil, debug: nil)
  File.open filename do |file|
    parse file, decode_with: decode_with, debug: debug
  end
end