class ParserCombinator::StringParser

Public Class Methods

char(char) click to toggle source
# File lib/parser_combinator/string_parser.rb, line 19
def self.char(char)
  sat{|c| c == char}
end
convert_string_into_items(string, document_name) click to toggle source
# File lib/parser_combinator/string_parser.rb, line 5
def self.convert_string_into_items(string, document_name)
  integers = (1..100000).lazy
  items = string.each_line.zip(integers).map{|line, line_number|
    line.chars.zip(integers).map{|char, column_number|
      Item.new(char, :document_name => document_name, :line_number => line_number, :column_number => column_number)
    }
  }.flatten
  return Items.new(items)
end
digit() click to toggle source
# File lib/parser_combinator/string_parser.rb, line 41
def self.digit
  sat{|c| "0" <= c && c <= "9"}
end
lower_alpha() click to toggle source
# File lib/parser_combinator/string_parser.rb, line 33
def self.lower_alpha
  sat{|c| "a" <= c && c <= "z"}
end
notchar(char) click to toggle source
# File lib/parser_combinator/string_parser.rb, line 23
def self.notchar(char)
  sat{|c| c != char}
end
pdigit() click to toggle source
# File lib/parser_combinator/string_parser.rb, line 45
def self.pdigit
  sat{|c| "1" <= c && c <= "9"}
end
str(object) click to toggle source
# File lib/parser_combinator/string_parser.rb, line 27
def self.str(object)
  seq(*object.to_s.chars.map{|c| char(c)}) >> proc{|items|
    ok Items.new(items.to_a)
  }
end
upper_alpha() click to toggle source
# File lib/parser_combinator/string_parser.rb, line 37
def self.upper_alpha
  sat{|c| "A" <= c && c <= "Z"}
end

Public Instance Methods

parse_from_string(input_string, document_name="anonymous") click to toggle source
# File lib/parser_combinator/string_parser.rb, line 15
def parse_from_string(input_string, document_name="anonymous")
  parse(self.class.convert_string_into_items(input_string,  document_name))
end