Commits

orbitz  committed b60034d

Adding support for multi-character non-alphanum keywords, strings, and chars

  • Participants
  • Parent commits f73f78e

Comments (0)

Files changed (4)

File src/formatter.ml

 let format program_options out_chan code = raise (Failure "uhhh..")
 
 
-
-let construct_string options 

File src/lexer.ml

     let buffer = Buffer.create initial_buffer_size in
     Buffer.add_char buffer first_digit;
     lex_number buffer stream
+  | [< ''$'; stream >] ->
+    lex_char stream
+  | [< ' ('"'); stream >] ->
+    let buffer = Buffer.create initial_buffer_size in
+    lex_string buffer stream
   | [< ''='; stream >] ->
     lex_equal stream
-  | [< ''-'; sream >] ->
+  | [< ''-'; stream >] ->
     lex_minus stream
   | [< 'c; stream >] ->
     [< 'Token.Keyword (String.make 1 c); lex stream >]
     lex_number buffer stream
   | [< stream >] ->
     [< 'Token.Number (Buffer.contents buffer); lex stream >]
+and lex_char = parser
+  | [< ' ('\\'); ' ('\\' | ' ' | 's' | 'n' | 'r' | 't' | 'v') as c; stream >] ->
+    [< 'Token.Char ("$\\" ^ (String.make 1 c)); lex stream >]
+  | [< 'c; stream >] ->
+    [< 'Token.Char ("$" ^ (String.make 1 c)); lex stream >]
+and lex_string buffer = parser
+  | [< ' ('"'); stream >] ->
+    [< 'Token.String (Buffer.contents buffer); lex stream >]
+  | [< ' ('\\'); ' ('"'); stream >] ->
+    Buffer.add_string buffer "\\\"";
+    lex_string buffer stream
+  | [< 'c; stream >] ->
+    Buffer.add_char buffer c;
+    lex_string buffer stream
 and lex_equal = parser
   | [< ''/'; stream >] ->
     lex_not_equal stream
     [< 'Token.Keyword "=/="; lex stream >]
   | [< stream >] ->
     [< 'Token.Keyword "=/"; lex stream >]
+and lex_minus = parser
+  | [< ''>'; stream >] ->
+    [< 'Token.Keyword "->"; lex stream >]
+  | [< stream >] ->
+    [< 'Token.Keyword "-"; lex stream >]
 and whitespace = parser
   | [< ' (' ' | '\r' | '\t'); stream >] -> whitespace stream
 

File src/token.ml

   (* { } ( ) + = === : .. etc *)
   | Atom of string
   | Var of string
-  | Char of char
+  (* 
+   * Using a string here so we can store actual 
+   * representation in code 
+   *)
+  | Char of string
   (* In this iteration we don't care if a number is valid *)
   | Number of string
   | String of string
   | Var var ->
     Printf.sprintf "Var %s" var
   | Char c ->
-    Printf.sprintf "Char '%c'" c
+    Printf.sprintf "Char %s" c
   | Number num ->
     Printf.sprintf "Number %s" num
   | String str ->

File src/token.mli

   | Keyword of string
   | Atom of string
   | Var of string
-  | Char of char
+  (* 
+   * Using a string here so we can store actual 
+   * representation in code 
+   *)
+  | Char of string
   (* In this iteration we don't care if a number is valid *)
   | Number of string
   | String of string