module MetaParse
This module contains the classes which implement parsers and, when included, provides class methods for defining custom parsers.
Public Class Methods
included(base)
click to toggle source
Extend including class with ClassMethods
.
# File lib/meta_parse.rb, line 12 def self.included(base) base.extend ClassMethods end
Public Instance Methods
all_matches(scanner, context)
click to toggle source
Extract matches from context and return them, resetting context's matches to be empty.
# 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)
click to toggle source
Join all matches as extracted by all_matches
.
# File lib/meta_parse.rb, line 428 def all_matches_joined(scanner, context) all_matches(scanner,context).join end
collapse(&block)
click to toggle source
Apply block to context's matches stack, then clear context, returning result.
# 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)
click to toggle source
Joins's string args. Helper function for use in assembling parse results.
# File lib/meta_parse.rb, line 435 def join_strings(array, *args) array.join(*args) end
parse_with_method(method_name, string)
click to toggle source
Parse string using an instance method previously defined by MetaParse::ClassMethodss::match_method.
# File lib/meta_parse.rb, line 19 def parse_with_method(method_name, string) self.send(method_name, string.meta(self), self) end