about summary refs log tree commit diff
path: root/users/wpcarro/scratch/compiler/parser.ml
diff options
context:
space:
mode:
Diffstat (limited to 'users/wpcarro/scratch/compiler/parser.ml')
-rw-r--r--users/wpcarro/scratch/compiler/parser.ml23
1 files changed, 11 insertions, 12 deletions
diff --git a/users/wpcarro/scratch/compiler/parser.ml b/users/wpcarro/scratch/compiler/parser.ml
index 75cbe04a3f..dc66f2506e 100644
--- a/users/wpcarro/scratch/compiler/parser.ml
+++ b/users/wpcarro/scratch/compiler/parser.ml
@@ -1,24 +1,23 @@
-(*******************************************************************************
+(****************************************************************************** 
  * Defines a generic parser class.
  ******************************************************************************)
 
+open Vec
+
 exception ParseError of string
 
 type token = string
-type state = { i : int; tokens : token array }
-
-let get (i : int) (xs : 'a array) : 'a option =
-  if i >= Array.length xs then None else Some xs.(i)
+type state = { i : int; tokens : token vec }
 
-class parser (tokens : token array) =
+class parser (tokens : token vec) =
   object (self)
-    val mutable tokens : token array = tokens
+    val mutable tokens = tokens
     val mutable i = ref 0
-    method print_state = Printf.sprintf "{ i = %d; }" !i
+
     method advance = i := !i + 1
-    method prev : token option = get (!i - 1) tokens
-    method curr : token option = get !i tokens
-    method next : token option = get (!i + 1) tokens
+    method prev : token option = Vec.get (!i - 1) tokens
+    method curr : token option = Vec.get !i tokens
+    method next : token option = Vec.get (!i + 1) tokens
 
     method consume : token option =
       match self#curr with
@@ -43,6 +42,6 @@ class parser (tokens : token array) =
             end
           else false
 
-    method exhausted : bool = !i >= Array.length tokens
+    method exhausted : bool = !i >= Vec.length tokens
     method state : state = { i = !i; tokens }
   end