Sfoglia il codice sorgente

Make source compatible with latest language/stdlib version.

Taddeus Kroes 3 anni fa
parent
commit
65485d90d0
4 ha cambiato i file con 17 aggiunte e 21 eliminazioni
  1. 1 1
      README.md
  2. 2 2
      lexer.mll
  3. 11 11
      parser.mly
  4. 3 7
      util.ml

+ 1 - 1
README.md

@@ -103,7 +103,7 @@ Dependencies are [OCaml](https://ocaml.org/docs/install.html) 4.02.0,
 
 Bootstrapping on a Debian system can be done as follows:
 
-    $ sudo apt-get install ocaml menhir libgetopt-ocaml-dev git
+    $ sudo apt-get install ocaml menhir ocaml-findlib libgetopt-ocaml-dev git
     $ git clone git@github.com:taddeus/mincss.git
     $ cd mincss
     $ make

+ 2 - 2
lexer.mll

@@ -105,9 +105,9 @@ rule token = parse
   | '@' N A M E S P A C E         { NAMESPACE_SYM }
   | '@' S U P P O R T S           { SUPPORTS_SYM }
   | '@' (('-' ident '-')? as prefix) K E Y F R A M E S
-  { KEYFRAMES_SYM (String.lowercase prefix) }
+  { KEYFRAMES_SYM (String.lowercase_ascii prefix) }
   | '@' (('-' ident '-')? as prefix) V I E W P O R T
-  { VIEWPORT_SYM (String.lowercase prefix) }
+  { VIEWPORT_SYM (String.lowercase_ascii prefix) }
 
   | (s | comment)* s comment* A N D comment* s (s | comment)*
   { advance_pos lexbuf; WS_AND }

+ 11 - 11
parser.mly

@@ -245,26 +245,26 @@ simple_selector:
   | id=HASH  { `Id id }
   | addon=cls | addon=attrib | addon=pseudo_class  { addon }
 element_name:
-  | tag=IDENT  { Element (String.lowercase tag) }
+  | tag=IDENT  { Element (String.lowercase_ascii tag) }
   | STAR       { All_elements }
 cls:
   | DOT name=IDENT
   { `Class name }
 attrib:
   | LBRACK S* left=IDENT S* RBRACK
-  { `Attribute (String.lowercase left, None) }
+  { `Attribute (String.lowercase_ascii left, None) }
   | LBRACK S* left=IDENT S* op=RELATION right=rel_value RBRACK
-  { `Attribute (String.lowercase left, Some (op, right)) }
+  { `Attribute (String.lowercase_ascii left, Some (op, right)) }
 %inline rel_value:
   | S* id=IDENT S*  { Ident id }
   | S* s=STRING S*  { Strlit s }
 pseudo_class:
   | COLON id=IDENT
-  { `Pseudo_class (String.lowercase id, None) }
+  { `Pseudo_class (String.lowercase_ascii id, None) }
   | COLON f=FUNCTION args=wslist(COMMA, function_arg) RPAREN
-  { `Pseudo_class (String.lowercase f, Some args) }
+  { `Pseudo_class (String.lowercase_ascii f, Some args) }
   | DOUBLE_COLON id=IDENT
-  { `Pseudo_element (String.lowercase id) }
+  { `Pseudo_element (String.lowercase_ascii id) }
 function_arg:
   | s=simple_selector
   { Nested_selector s }
@@ -287,7 +287,7 @@ function_arg:
 
 declaration:
   | name=property S* COLON S* value=expr important=boption(ig2(IMPORTANT_SYM, S*))
-  { (String.lowercase name, value, important) }
+  { (String.lowercase_ascii name, value, important) }
 %inline property:
   | name=IDENT       { name }
   | STAR name=IDENT  { "*" ^ name }  (* IE7 property name hack *)
@@ -307,14 +307,14 @@ term:
   | op=unary_operator v=numval S*   { unary_number (Unary (op, v)) }
   | v=numval S*                     { v }
   | str=STRING S*                   { Strlit str }
-  | id=IDENT S*                     { Ident (String.lowercase id) }
+  | id=IDENT S*                     { Ident (String.lowercase_ascii id) }
   | ONLY S*                         { Ident "only" }
   | NOT S*                          { Ident "not" }
   | AND S*                          { Ident "and" }
   | FROM S*                         { Ident "from" }
   | TO S*                           { Ident "to" }
   | uri=URI S*                      { Uri uri }
-  | fn=FUNCTION arg=expr RPAREN S*  { Function (String.lowercase fn, arg) }
+  | fn=FUNCTION arg=expr RPAREN S*  { Function (String.lowercase_ascii fn, arg) }
   | key=IDENT S* COLON S* value=term
   { Key_value (key, ":", value) }
   | key=IDENT S* DOT S* value=term
@@ -329,7 +329,7 @@ term:
   {
     let h = "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]" in
     if Str.string_match (Str.regexp ("^" ^ h ^ "\\(" ^ h ^ "\\)?$")) hex 0
-      then Hexcolor (String.lowercase hex)
+      then Hexcolor (String.lowercase_ascii hex)
       else raise (Syntax_error ("invalid color #" ^ hex))
   }
 unary_operator:
@@ -337,5 +337,5 @@ unary_operator:
   | PLUS   { "+" }
 %inline numval:
   | n=NUMBER      { Number (n, None) }
-  | v=UNIT_VALUE  { let n, u = v in Number (n, Some (String.lowercase u)) }
+  | v=UNIT_VALUE  { let n, u = v in Number (n, Some (String.lowercase_ascii u)) }
   | n=PERCENTAGE  { Number (n, Some "%") }

+ 3 - 7
util.ml

@@ -1,10 +1,6 @@
 open Printf
 open Types
 
-(** Operators *)
-
-let (|>) a b = b a
-
 (** List utilities *)
 
 let is_none = function None -> true | Some _ -> false
@@ -23,16 +19,16 @@ let input_all ic =
   let buf = Bytes.create n in
   really_input ic buf 0 n;
   close_in ic;
-  buf
+  Bytes.unsafe_to_string buf
 
 let input_buffered ic chunksize =
   let rec read_all buf bufsize pos =
     match input ic buf pos (bufsize - pos) with
-    | 0 -> (close_in ic; buf)
+    | 0 -> close_in ic; Bytes.unsafe_to_string buf
     | nread when nread = bufsize - pos ->
       let bufsize = bufsize + chunksize in
       let pos = pos + nread in
-      read_all (buf ^ Bytes.create chunksize) bufsize pos
+      read_all (Bytes.cat buf (Bytes.create chunksize)) bufsize pos
     | nread ->
       read_all buf bufsize (pos + nread)
   in