From 7488a4ec763851a113d598afd2af53d867dd1b6f Mon Sep 17 00:00:00 2001 From: Marwan Ghanem Date: Mon, 1 Jul 2013 22:22:32 +0200 Subject: [PATCH] Parser for seq --- src/GParser.ml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/GParser.ml b/src/GParser.ml index 2a2ad70..9ade099 100644 --- a/src/GParser.ml +++ b/src/GParser.ml @@ -21,6 +21,15 @@ type character = Char of char | EOF;; +let contains s1 s2 = + try + let len = String.length s2 in + for i = 0 to String.length s1 - len do + if String.sub s1 i len = s2 then raise Exit + done; + false + with Exit -> true + let is_space = function | Char(ch) -> ch == ' ' or ch == '\n' or ch == '\t' or ch == '\r' | EOF -> false ;; @@ -131,6 +140,16 @@ let parse_component str i = raise (Parse_Error "Expecting '*', '+' or ';' after ")) else if componentName="*" or componentName="+" then raise (Parse_Error ("Unexpected '" ^ componentName ^ "'")) + else if (contains componentName "SEQ(") == true then + let start = String.index componentName '(' in + let stop = String.index componentName ')' in + let name = String.sub componentName (start+1) (stop-start-1) in + let (next,i'') = next_word str i' in + if next="+" or next =";" then + ((weight,List.rev ((SEQ name)::refs)),i') + else if next="*" then + aux i'' weight ((SEQ name)::refs) + else raise (Parse_Error "Expecting '+', ';' or '*'") else (* component Name is ok *) let (next,i'') = next_word str i' in (* print_endline ("Next = " ^ next) ; *)