lexpointfree.mll 1.95 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
(******************************************************************************)
(*                                                                            *)
(*                                   Menhir                                   *)
(*                                                                            *)
(*                       François Pottier, Inria Paris                        *)
(*              Yann Régis-Gianas, PPS, Université Paris Diderot              *)
(*                                                                            *)
(*  Copyright Inria. All rights reserved. This file is distributed under the  *)
(*  terms of the GNU General Public License version 2, as described in the    *)
(*  file LICENSE.                                                             *)
(*                                                                            *)
(******************************************************************************)

14 15 16 17 18 19
{

  exception InvalidPointFreeAction

}

POTTIER Francois's avatar
POTTIER Francois committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
(* See [ParserAux.validate_pointfree_action]. *)

let lowercase = ['a'-'z' '\223'-'\246' '\248'-'\255' '_']

let uppercase = ['A'-'Z' '\192'-'\214' '\216'-'\222']

let identchar = ['A'-'Z' 'a'-'z' '_' '\192'-'\214' '\216'-'\246' '\248'-'\255' '0'-'9'] (* '\'' forbidden *)

let symbolchar =
  ['!' '$' '%' '&' '*' '+' '-' '.' '/' ':' '<' '=' '>' '?' '@' '^' '|' '~']

let op         =
  symbolchar+
  (* An approximation of OCaml's rules. *)

let whitespace = [ ' ' '\t' '\n' ]

37
rule validate_pointfree_action = parse
POTTIER Francois's avatar
POTTIER Francois committed
38 39
| whitespace* (lowercase | uppercase | '`') (identchar | '.')* whitespace* eof
| whitespace* '(' op ')' whitespace* eof
40
    (* We have got a nonempty point-free action: <id>. *)
POTTIER Francois's avatar
POTTIER Francois committed
41
    { true }
42 43
| whitespace* eof
    (* We have got an empty point-free action: <>. *)
POTTIER Francois's avatar
POTTIER Francois committed
44
    { false }
45 46
| _
    { raise InvalidPointFreeAction }
POTTIER Francois's avatar
POTTIER Francois committed
47 48 49 50 51 52 53

(* See [ParserAux.valid_ocaml_identifier]. *)

and valid_ocaml_identifier = parse
| lowercase identchar* eof
    { true }
| _
54
| eof
POTTIER Francois's avatar
POTTIER Francois committed
55
    { false }