Module: MetaParse

Included in:
FunctionMatcher
Defined in:
lib/meta_parse.rb

Overview

This module contains the classes which implement parsers and, when included, provides class methods for defining custom parsers.

Defined Under Namespace

Modules: ClassMethods Classes: AlternativeMatcher, FunctionMatcher, Matcher, MetaScanner, RepetitionMatcher, SequentialMatcher

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Extend including class with ClassMethods.



12
13
14
# File 'lib/meta_parse.rb', line 12

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#all_matches(scanner, context) ⇒ Object

Extract matches from context and return them, resetting context’s matches to be empty.



419
420
421
422
423
# File 'lib/meta_parse.rb', line 419

def all_matches(scanner, context)
  matches_so_far = context.matches
  context.matches = []
  matches_so_far
end

#all_matches_joined(scanner, context) ⇒ Object

Join all matches as extracted by #all_matches.



428
429
430
# File 'lib/meta_parse.rb', line 428

def all_matches_joined(scanner, context)
  all_matches(scanner,context).join
end

#collapse(&block) ⇒ Object

Apply block to context’s matches stack, then clear context, returning result.



442
443
444
445
446
447
448
449
# File 'lib/meta_parse.rb', line 442

def collapse(&block)
  lambda { |scanner, context|
    stack = context.matches
    result = block.call(stack)
    context.clear
    result
  }
end

#join_strings(array, *args) ⇒ Object

Joins’s string args. Helper function for use in assembling parse results.



435
436
437
# File 'lib/meta_parse.rb', line 435

def join_strings(array, *args)
  array.join(*args)
end

#parse_with_method(method_name, string) ⇒ Object

Parse string using an instance method previously defined by MetaParse::ClassMethodss::match_method.



19
20
21
# File 'lib/meta_parse.rb', line 19

def parse_with_method(method_name, string)
  self.send(method_name, string.meta(self), self)
end