Commit 4f3dcacd authored by Benoit Barbot's avatar Benoit Barbot
Browse files

parser color

parent 04763327
Pipeline #902 passed with stage
in 22 seconds
......@@ -26,6 +26,7 @@ rule token = parse
| ']' {RSQBRAK}
| ';' {SEMICOLON}
| ',' {COMMA}
| '=' {EQ}
| ":" {COLON}
| "--" {PATHDELIM}
| ".." {CONTROLDELIM}
......@@ -38,9 +39,8 @@ rule token = parse
| "draw" {DRAW}
| "path" {PATH}
| "at" {AT}
| ['a'-'z' 'A'-'Z' '>' '-' '<' '='] [ '>' '-' '<' '=' 'a'-'z' 'A'-'Z' '_' '0'-'9']* as lxm {
STRING(lxm)
}
| ['a'-'z' 'A'-'Z' '>' '-' '<' ][ '>' '-' '<' '_' 'a'-'z' 'A'-'Z' '0'-'9']* as lxm { IDENTIFIER(lxm)}
| _ { raise (SyntaxError ("Unexpected char: " ^ Lexing.lexeme lexbuf)) }
| eof {EOF}
and read_string buf = parse
......@@ -63,7 +63,6 @@ and read_tex_content buf = parse
| '\\' '/' { Buffer.add_char buf '/'; read_tex_content buf lexbuf }
| '\\' '\\' { Buffer.add_char buf '\\'; read_tex_content buf lexbuf }
| '\\' 'b' { Buffer.add_char buf '\b'; read_tex_content buf lexbuf }
| '\\' 'f' { Buffer.add_char buf '\012'; read_tex_content buf lexbuf }
| '\\' 'n' { Buffer.add_char buf '\n'; read_tex_content buf lexbuf }
| '\\' 'r' { Buffer.add_char buf '\r'; read_tex_content buf lexbuf }
| '\\' 't' { Buffer.add_char buf '\t'; read_tex_content buf lexbuf }
......@@ -73,4 +72,7 @@ and read_tex_content buf = parse
}
| _ { raise (SyntaxError ("Illegal string character: " ^ Lexing.lexeme lexbuf)) }
| eof { raise (SyntaxError ("String is not terminated")) }
(* | ['a'-'z' 'A'-'Z' '>' '-' '<' '='] [ '>' '-' '<' '=' 'a'-'z' 'A'-'Z' '_' '0'-'9']* as lxm {
STRING(lxm)
}*)
......@@ -5,10 +5,11 @@
%token <int> INT
%token <float> FLOAT
%token <string> STRING
%token <string> IDENTIFIER
%token <string> TEXCONTENT
%token LPAR RPAR
%token BACKSLASH
%token SEMICOLON COLON PRIME COMMA QMARK
%token SEMICOLON COLON PRIME COMMA QMARK EQ
%token LSQBRAK RSQBRAK
%token EOF
%token BEGIN END AND
......@@ -44,10 +45,10 @@ let (al,start,fin,pl) = $3 in
| BACKSLASH END { [],[] };
node:
AT LPAR FLOAT COMMA FLOAT RPAR LSQBRAK attribute_list RSQBRAK LPAR STRING RPAR TEXCONTENT SEMICOLON { ($3,$5),$8,$11,$13 };
AT LPAR FLOAT COMMA FLOAT RPAR LSQBRAK attribute_list RSQBRAK LPAR IDENTIFIER RPAR TEXCONTENT SEMICOLON { ($3,$5),$8,$11,$13 };
draw:
LSQBRAK attribute_list RSQBRAK LPAR STRING RPAR pathlist SEMICOLON {
LSQBRAK attribute_list RSQBRAK LPAR IDENTIFIER RPAR pathlist SEMICOLON {
let pl,fin = $7 in ($2,$5,fin,pl) }
pathlist:
......@@ -56,7 +57,7 @@ PATHDELIM LPAR FLOAT COMMA FLOAT RPAR pathlist
| CONTROLDELIM CONTROLS LPAR FLOAT COMMA FLOAT RPAR AND LPAR FLOAT COMMA FLOAT RPAR CONTROLDELIM pathlist2
{ let l,f = $15 in
`ControlPoint ($4,$6)::`ControlPoint ($10,$12)::l,f }
| PATHDELIM LPAR STRING RPAR { [],$3 }
| PATHDELIM LPAR IDENTIFIER RPAR { [],$3 }
| NODE TEXCONTENT pathlist {
let l,f = $3 in (`Text (0.5,$2)::l,f) }
......@@ -64,7 +65,7 @@ pathlist2:
LPAR FLOAT COMMA FLOAT RPAR pathlist { let l,f = $6 in (`Point ($2,$4)::l,f) }
| NODE TEXCONTENT pathlist2 {
let l,f = $3 in (`Text (0.5,$2)::l,f) }
| LPAR STRING RPAR { [],$2 }
| LPAR IDENTIFIER RPAR { [],$2 }
attribute_list:
| attribute { [$1] }
......@@ -73,5 +74,6 @@ attribute_list:
attribute:
| DRAW { "draw" }
| STRING { $1 }
| STRING STRING { $1^" "^$2 }
| IDENTIFIER { $1 }
| IDENTIFIER IDENTIFIER { $1^" "^$2 }
| IDENTIFIER EQ TEXCONTENT { $1^"="^$3}
......@@ -59,7 +59,10 @@ module Color = struct
|_ ->0 in
let ios a b = (int_of_l a)*16 + int_of_l b in
(ios x.[1] x.[2],ios x.[3] x.[4],ios x.[5] x.[6])
with _ -> (0,0,0) end
with _ -> (0,0,0) end
| x when String.length x>=4 && x.[0]='r' && x.[1]='g' && x.[2]='b' ->
Scanf.sscanf x "rgb,255:red,%i;green,%i;blue,%i" (fun r g b -> (r,g,b))
| _ -> (0,0,0)
let to_string (r,g,b) =
......@@ -70,7 +73,7 @@ module Color = struct
|_ ->'0' in
Printf.sprintf "#%c%c%c%c%c%c" (loi (r/16)) (loi (r mod 16))
(loi (g/16)) (loi (g mod 16)) (loi (b/16)) (loi (b mod 16))
let to_tikz_string (r,g,b) =
Printf.sprintf "rgb,255:red,%i;green,%i;blue,%i" r g b
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment