Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct callMe
- {
- alias MatchT!char Match;
- static Match n0( const char[] inputRange, size_t cursor, size_t ubound )
- {
- writefln("n0(%s,%s,%s)",inputRange,cursor,ubound);
- /* Sequence */
- auto m0 = n1(inputRange, cursor, ubound);
- if ( !m0.successful )
- return Match.failure(inputRange);
- return Match.success(inputRange, m0.begin, m0.end);
- }
- static Match n1( const char[] inputRange, size_t cursor, size_t ubound )
- {
- writefln("n1(%s,%s,%s)",inputRange,cursor,ubound);
- /* Sequence */
- auto m0 = n2(inputRange, cursor, ubound);
- if ( !m0.successful )
- return Match.failure(inputRange);
- auto m1 = n3(inputRange, m0.end, ubound);
- if ( !m1.successful )
- return Match.failure(inputRange);
- return Match.success(inputRange, m0.begin, m1.end);
- }
- static Match n2( const char[] inputRange, size_t cursor, size_t ubound )
- {
- writefln("n2(%s,%s,%s)",inputRange,cursor,ubound);
- /* Literal */
- if ( cursor >= ubound )
- return Match.failure(inputRange);
- else if ( inputRange[cursor] == 'x' )
- return Match.success(inputRange, cursor, cursor+1);
- else
- return Match.failure(inputRange);
- }
- static Match n3( const char[] inputRange, size_t cursor, size_t ubound )
- {
- writefln("n3(%s,%s,%s)",inputRange,cursor,ubound);
- /* Ordered Choice */
- auto m0 = n4(inputRange, cursor, ubound);
- if ( m0.successful )
- return Match.success(inputRange, m0.begin, m0.end);
- auto m1 = n5(inputRange, cursor, ubound);
- if ( m1.successful )
- return Match.success(inputRange, m1.begin, m1.end);
- return Match.failure(inputRange);
- }
- static Match n4( const char[] inputRange, size_t cursor, size_t ubound )
- {
- writefln("n4(%s,%s,%s)",inputRange,cursor,ubound);
- /* Epsilon */
- return Match.success(inputRange, cursor, cursor);
- }
- static Match n5( const char[] inputRange, size_t cursor, size_t ubound )
- {
- writefln("n5(%s,%s,%s)",inputRange,cursor,ubound);
- /* Literal */
- if ( cursor >= ubound )
- return Match.failure(inputRange);
- else if ( inputRange[cursor] == 'y' )
- return Match.success(inputRange, cursor, cursor+1);
- else
- return Match.failure(inputRange);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement