summary refs log tree commit diff
path: root/source/mod_student/lexer.mll
diff options
context:
space:
mode:
Diffstat (limited to 'source/mod_student/lexer.mll')
-rw-r--r--source/mod_student/lexer.mll26
1 files changed, 24 insertions, 2 deletions
diff --git a/source/mod_student/lexer.mll b/source/mod_student/lexer.mll
index ae11472..d26912f 100644
--- a/source/mod_student/lexer.mll
+++ b/source/mod_student/lexer.mll
@@ -19,7 +19,27 @@
   (* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv 
    * Miejsce na twój kod w Ocamlu
    *)
-
+let explode s =
+  let rec exp i l =
+    if i < 0 then l else exp (i - 1) (s.[i] :: l) in
+  exp (String.length s - 1) [];;
+let implode l =
+  let res = Bytes.create (List.length l) in
+  let rec imp i = function
+  | [] -> res
+  | c :: l -> Bytes.set res i c; imp (i + 1) l in
+  Bytes.to_string(imp 0 l);;
+
+  let unescape str =
+    let rec aux x= match x with
+      | ['"'] -> []
+      | '\\'::'\\'::xs ->'\\'::(aux xs)
+      | '\\'::'n'::xs ->'\n'::(aux xs)
+      | '\\'::'"'::xs ->'"'::(aux xs)
+      | x::xs ->x::(aux xs)
+      | [] -> failwith "missing \" in escaped string"
+    in implode (aux (List.tl (explode str) ) )  ;;
+      
 
   (* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      ----------------------------------------------------------------------------- *)
@@ -31,7 +51,8 @@
    *)
 
   let identifier    = ['a'-'z' '_' 'A' - 'Z']['_' 'A' - 'Z' 'a'-'z' '0'-'9']*
-  let integer       = ['0'-'9']*
+  let integer       = ['0'-'9']+
+  let str           = "\""(([^ '\n''"''\\'])|('\\'['n''\\''"']))*"\""
   
   (* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      ----------------------------------------------------------------------------- *)
@@ -55,6 +76,7 @@
       (* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv 
        * Miejsce na twoje reguły
        *)
+      | str as e  { STRING (unescape e) }
       | ","       { COMMA }
       | "("       { LPAREN }
       | ")"       { RPAREN }