more bug fixes
[henge/apc.git] / src / lexer_fsm.rl
index f7b4665..96d999a 100644 (file)
@@ -1,6 +1,6 @@
 #include <stdio.h>
 #include <stdint.h>
-#include <apc/parser.tab.h>
+#include "parser.tab.h"
 #include "apc.h"
 #include <unistdio.h>
 #include <unistr.h>
@@ -32,7 +32,7 @@ int lexer_setstr(uint8_t*, int);
   action push_ref       { PUSHTOK(REF, ttov, ref); }
   action push_val       { PUSHTOK(NUM, ttov, val); }
   action push_name      { printf("Lexer_lexstring:: action:push_name: from %s to %s\n", ts, p);
-                          PUSHTOK(NAME, tton, str);
+                          PUSHTOK(NAME, tton, name);
                         }
   action push_map       { printf("Lexer_lexstring:: action:push_map: pushing '~'\n");
                           yylval.str = (uint8_t*) '~';
@@ -84,11 +84,9 @@ int lexer_setstr(uint8_t*, int);
                           PUSHTOK(WIDTH, ttov, val);
                         }
   action push_link      {yylval.str = (uint8_t*) '#'; lexer_pushtok(LINK),yylval); }
-  action lex_error      { printf("input error: character %c in filename %s is invalid\n p = %s\n", fc, str, p);}
+  #action lex_error      { printf("input error: character %c in filename %s is invalid\n p = %s\n", fc, str, p);}
   action p              { printf("Lexer_lexstring:: p = %s\n", p);}
     
-  # Parses a regular filename (not a mapping) and pushes
-  # tokens to the parser
   N = 'N' %push_N;
   W = 'W' %push_W;
   S = 'S' %push_S;
@@ -98,7 +96,10 @@ int lexer_setstr(uint8_t*, int);
   SW = 'SW' %push_SW;
   SE = 'SE' %push_SE;
 
+  #what goes in between tokens in a filename
   tok_delimiter = [_];
+
+  #types of tokes a filename can contain
   direction = (N | W | S | E | NW | NE | SW | SE) ;
   #make sure 0x123123 doesnt get mistaken for a ref
   dimensions = (digit+ - '0') >set_ts %push_height 'x' (digit+ - '0') >set_ts  %push_width;
@@ -108,10 +109,10 @@ int lexer_setstr(uint8_t*, int);
   val = digit+ >set_ts %push_val ;
   name = (lower+ >set_ts) %push_name ;
   map = '+MAP' %to(push_map);
-  tok = name %to(push_name) ;
+  tok = (name | val | ref | dimensions | map | link | SS | direction);
   
 
-  tok_lexer := ((name | val | ref | dimensions | map) tok_delimiter)+ tok [\0];
+  tok_lexer := (tok tok_delimiter)+ tok [\0];
 
   write data;
   
@@ -121,17 +122,17 @@ int
 lexer_lexstring
 (uint8_t* str, int size)
 { uint8_t *p; 
-  uint8_t *ts, *pe, *eof;
-  int cs, ntok, tok_t, direction;
+  uint8_t *ts, *pe;
+  int cs, ntok, tok_t;
 
-  ntok = direction = 0;
+  ntok = 0;
   p = ts = str;
-  pe = p + size +1;
+  pe = p + size + 1;
 
   printf("|---Begin lexstring on p = %s, pe = %s.\n",p, pe);
 
   %%write init;
-  %%write exec ;
+  %%write exec;
 
    printf("Ending lexstring of file %s, pushed %d tokens.\n",str, ntok);
 
@@ -139,6 +140,17 @@ lexer_lexstring
 }
 
 
+/**************************/
+/****Abandon All Hope******/
+/**************************/
+/***                    ***/
+/***                    ***/       
+/***                    ***/
+/***                    ***/
+
+
+#if 0 
+
 %%{
   machine setdirection;
 
@@ -166,9 +178,11 @@ lexer_lexstring
   main := direction; 
 
   write data;
-  
+
 }%%
 
+
 int
 lexer_setdirection
 (uint8_t* str, int size)
@@ -191,16 +205,6 @@ lexer_setdirection
 
 
 
-/**************************/
-/****Abandon All Hope******/
-/**************************/
-/***                    ***/
-/***                    ***/       
-/***                    ***/
-/***                    ***/
-
-
-#if 0 
 %%{
   machine setstr;