youxkei/ctpg

Regular Expressions do not work

dprog opened this issue · 1 comments

I am trying the following. I have used regular expression [a-zA-Z]+. While it seems to match lower letters, it does not match the upper case letters.

import ctpg;
import std.array: join;
import std.conv: to;
import std.stdio;
import std.algorithm;

mixin(genParsers(
q{
@_setSkip(skip)

// root parser
string root = addExp $;

// addition and subtraction
string addExp =
      mulExp !"+" addExp >> (lhs, rhs){ return lhs ~ "+" ~ rhs; }
    / mulExp !"-" addExp >> (lhs, rhs){ return lhs ~ "-" ~ rhs; }
    / mulExp;

// multiplication and division
string mulExp =
      primary !"*" mulExp >> (lhs, rhs){ return lhs ~ "*" ~ rhs; }
    / primary !"/" mulExp >> (lhs, rhs){ return lhs ~ "/" ~ rhs; }
    / primary;

string primary = !"(" addExp !")" / [a-zA-Z]+ >> to!string;

}));

void main()
{
static bool test()
{
pragma(msg, parse!root("a * b + c * d").value);
pragma(msg, parse!root("A * B + C * D").value);
return true;
};

test();

}

Fixed