Advertisement
chadjoan

parser_builder.d output

Nov 4th, 2013
476
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 2.48 KB | None | 0 0
  1. struct callMe
  2. {
  3.     alias MatchT!char Match;
  4.  
  5.     static Match n0( const char[] inputRange, size_t cursor, size_t ubound )
  6.     {
  7.         writefln("n0(%s,%s,%s)",inputRange,cursor,ubound);
  8.         /* Sequence */
  9.         auto m0 = n1(inputRange, cursor, ubound);
  10.         if ( !m0.successful )
  11.             return Match.failure(inputRange);
  12.  
  13.         return Match.success(inputRange, m0.begin, m0.end);
  14.     }
  15.  
  16.     static Match n1( const char[] inputRange, size_t cursor, size_t ubound )
  17.     {
  18.         writefln("n1(%s,%s,%s)",inputRange,cursor,ubound);
  19.         /* Sequence */
  20.         auto m0 = n2(inputRange, cursor, ubound);
  21.         if ( !m0.successful )
  22.             return Match.failure(inputRange);
  23.  
  24.         auto m1 = n3(inputRange, m0.end, ubound);
  25.         if ( !m1.successful )
  26.             return Match.failure(inputRange);
  27.  
  28.         return Match.success(inputRange, m0.begin, m1.end);
  29.     }
  30.  
  31.     static Match n2( const char[] inputRange, size_t cursor, size_t ubound )
  32.     {
  33.         writefln("n2(%s,%s,%s)",inputRange,cursor,ubound);
  34.         /* Literal */
  35.         if ( cursor >= ubound )
  36.             return Match.failure(inputRange);
  37.         else if ( inputRange[cursor] == 'x' )
  38.             return Match.success(inputRange, cursor, cursor+1);
  39.         else
  40.             return Match.failure(inputRange);
  41.     }
  42.  
  43.     static Match n3( const char[] inputRange, size_t cursor, size_t ubound )
  44.     {
  45.         writefln("n3(%s,%s,%s)",inputRange,cursor,ubound);
  46.         /* Ordered Choice */
  47.         auto m0 = n4(inputRange, cursor, ubound);
  48.         if ( m0.successful )
  49.             return Match.success(inputRange, m0.begin, m0.end);
  50.  
  51.         auto m1 = n5(inputRange, cursor, ubound);
  52.         if ( m1.successful )
  53.             return Match.success(inputRange, m1.begin, m1.end);
  54.  
  55.         return Match.failure(inputRange);
  56.     }
  57.  
  58.     static Match n4( const char[] inputRange, size_t cursor, size_t ubound )
  59.     {
  60.         writefln("n4(%s,%s,%s)",inputRange,cursor,ubound);
  61.         /* Epsilon */
  62.         return Match.success(inputRange, cursor, cursor);
  63.     }
  64.  
  65.     static Match n5( const char[] inputRange, size_t cursor, size_t ubound )
  66.     {
  67.         writefln("n5(%s,%s,%s)",inputRange,cursor,ubound);
  68.         /* Literal */
  69.         if ( cursor >= ubound )
  70.             return Match.failure(inputRange);
  71.         else if ( inputRange[cursor] == 'y' )
  72.             return Match.success(inputRange, cursor, cursor+1);
  73.         else
  74.             return Match.failure(inputRange);
  75.     }
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement