summaryrefslogtreecommitdiff
path: root/src/piraha/ILiteral.cc
blob: b78161459fcf32a8ae4c43c19689d1cb350a6418 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "Piraha.hpp"

using namespace cctki_piraha;

ILiteral::ILiteral(char b) : lc(lc_(b)), uc(uc_(b)) {}

bool ILiteral::match(Matcher *m) {
    if(m->pos >= (int)m->input_size )
        return false;
    char c = m->input[m->pos];
    if(c == uc || c == lc) {
        m->max_pos = std::max(m->pos,m->max_pos);
        m->pos++;
        return true;
    } else {
        if(m->pos == m->max_pos+1) {
            Bracket bex;
            bex.addRange(lc,lc);
            bex.addRange(uc,uc);
            m->fail(&bex);
        }
        return false;
    }
}