\0 is a delimiter
authorJordan <jordanlavatai@gmail.com>
Mon, 16 Jan 2017 20:19:22 +0000 (12:19 -0800)
committerJordan <jordanlavatai@gmail.com>
Mon, 16 Jan 2017 20:19:22 +0000 (12:19 -0800)
src/lexer.rl

index b56ac48..da397c0 100644 (file)
@@ -37,6 +37,8 @@ uint8_t   lval_offs;
 #define PUSHOP(O)   LEXTOK(O, val, 0)
 #define PUSHPATH(P) LEXTOK(PATH, str, P)
 
+#define DEBUG 1
+
 /* Lexstring is the main lexer for APC and is generated by ragel. It lexes file names of files 
    that have been scanned and pushes their types and values into the tok_stack, which yyparse 
    eventually calls during parsing. */
@@ -62,45 +64,45 @@ uint8_t   lval_offs;
                            }
                          PUSHNUM(lval.val);
                         }
-  action push_name      { //printf("Lexer_lexstring:: action:push_name: from %s to %s\n", ts, p);
+  action push_name      { if(DEBUG) printf("Lexer_lexstring:: action:push_name: from %s to %s\n", ts, p);
                          PUSHNAME(ts);
                         }
-  action push_map       { //printf("Lexer_lexstring:: action:push_map: pushing map token\n");
+  action push_map       { if(DEBUG) printf("Lexer_lexstring:: action:push_map: pushing map token\n");
                          PUSHOP(MAP);
                        }
-  action set_ts         { //printf("Lexer_lexstring:: action:set_ts. ts = %s\n", p);
+  action set_ts         { if(DEBUG) printf("Lexer_lexstring:: action:set_ts. ts = %s\n", p);
                           ts = p; }
-  action push_SS        { //printf("Lexer_lexstring:: action:push_SS. p = %s\n",p);
+  action push_SS        { if(DEBUG) printf("Lexer_lexstring:: action:push_SS. p = %s\n",p);
                           PUSHOP(SS);
                         }
-  action push_S         { //printf("Lexer_lexstring:: action:push_S. p = %s\n", p);
+  action push_S         { if(DEBUG) printf("Lexer_lexstring:: action:push_S. p = %s\n", p);
                          PUSHFACE(SFACE);
                         }
-  action push_SW        { //printf("Lexer_lexstring:: action:push_SW. p = %s\n", p);
+  action push_SW        { if(DEBUG) printf("Lexer_lexstring:: action:push_SW. p = %s\n", p);
                           PUSHFACE(SWFACE);
                        }
-  action push_W         { //printf("Lexer_lexstring:: action:push_W. p = %s\n", p);
+  action push_W         { if(DEBUG) printf("Lexer_lexstring:: action:push_W. p = %s\n", p);
                           PUSHFACE(WFACE);
                         }
-  action push_NW        { //printf("Lexer_lexstring:: action:push_NW. p = %s\n", p);
+  action push_NW        { if(DEBUG) printf("Lexer_lexstring:: action:push_NW. p = %s\n", p);
                          PUSHFACE(NWFACE);
                         }
-  action push_N         { //printf("Lexer_lexstring:: action:push_N. p = %s\n", p);
+  action push_N         { if(DEBUG) printf("Lexer_lexstring:: action:push_N. p = %s\n", p);
                           PUSHFACE(NFACE);
                         }
-  action push_NE        { //printf("Lexer_lexstring:: action:push_NE. p = %s\n", p);
+  action push_NE        { if(DEBUG) printf("Lexer_lexstring:: action:push_NE. p = %s\n", p);
                          PUSHFACE(NEFACE);
                         }
-  action push_E         { //printf("Lexer_lexstring:: action:push_N. p = %s\n", p);
+  action push_E         { if(DEBUG) printf("Lexer_lexstring:: action:push_N. p = %s\n", p);
                          PUSHFACE(EFACE);
                         }
-  action push_SE        { //printf("Lexer_lexstring:: action:push_N. p = %s\n", p);
+  action push_SE        { if(DEBUG) printf("Lexer_lexstring:: action:push_N. p = %s\n", p);
                          PUSHFACE(SEFACE);
                         }
-  action ref_error      { //printf("ref from %s to %s has an inappropriate amount of hex digits, it must have eight.\n", ts, p);
+  action ref_error      { if(DEBUG) printf("ref from %s to %s has an inappropriate amount of hex digits, it must have eight.\n", ts, p);
                           exit(1);
                         }
-  action p              { //printf("Lexer_lexstring:: p = %s\n", p);
+  action p              { if(DEBUG) printf("Lexer_lexstring:: p = %s\n", p);
                         }
     
   N = 'N' %push_N;
@@ -112,7 +114,7 @@ uint8_t   lval_offs;
   SW = 'SW' %push_SW;
   SE = 'SE' %push_SE;
 
-  tok_delimiter = [_];
+  tok_delimiter = [_\0];
 
   direction = (N | W | S | E | NW | NE | SW | SE) ;
   dimensions = (digit+ - '0') >set_ts %push_val 'x' (digit+ - '0') >set_ts  %push_val;
@@ -158,12 +160,12 @@ int lexer_lexstring
   p = ts = str;
   pe = eof =  p + size + 1;
 
-  //printf("|---Begin lexstring on p = %s, pe = %s.\n",p, pe);
+  if(DEBUG) printf("|---Begin lexstring on p = %s, pe = %s.\n",p, pe);
 
   %%write init;
   %%write exec;
 
-  //printf("Ending lexstring of file %s, pushed %d tokens.\n",str, ntok);
+  if(DEBUG) printf("Ending lexstring of file %s, pushed %d tokens.\n",str, ntok);
 
   return ntok;
 }