Skip to content

Commit

Permalink
Parser for seq
Browse files Browse the repository at this point in the history
  • Loading branch information
MarwanG committed Jul 1, 2013
1 parent 5082eaa commit 7488a4e
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/GParser.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;;
Expand Down Expand Up @@ -131,6 +140,16 @@ let parse_component str i =
raise (Parse_Error "Expecting '*', '+' or ';' after <z>"))
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) ; *)
Expand Down

0 comments on commit 7488a4e

Please sign in to comment.