Module: RaddDjur::Grammar::Parsers

Includes:
Immutable
Included in:
RaddDjur::Grammar, Parser
Defined in:
lib/radd_djur/grammar.rb

Class Method Summary collapse

Class Method Details

.any_charObject



74
75
76
# File 'lib/radd_djur/grammar.rb', line 74

def any_char
  Parser.new(&:char)
end

.char(ch) ⇒ Object



78
79
80
81
82
83
84
85
86
# File 'lib/radd_djur/grammar.rb', line 78

def char(ch)
  any_char.bind { |c|
    if c == ch
      ret c
    else
      fail
    end
  }
end

.failObject



68
69
70
71
72
# File 'lib/radd_djur/grammar.rb', line 68

def fail
  Parser.new { |d|
    Promise.eager(NO_PARSE)
  }
end

.ret(value) ⇒ Object



62
63
64
65
66
# File 'lib/radd_djur/grammar.rb', line 62

def ret(value)
  Parser.new { |d|
    Promise.eager(Parsed.new(value, d))
  }
end

.string(str) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
# File 'lib/radd_djur/grammar.rb', line 88

def string(str)
  if str.empty?
    ret ""
  else
    char(str[0]).bind { |c|
      string(str[1..-1]).bind { |s|
        ret c + s
      }
    }
  end
end