Skip to content

Commit

Permalink
Fix #295
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGen committed Apr 8, 2024
1 parent b32a293 commit 767de3c
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 15 deletions.
4 changes: 4 additions & 0 deletions kernel/basic.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ let string_of_mident s = s

let mident_eq = ident_eq

let mident_of_ident = function
| s when String.starts_with ~prefix:"{|" s -> String.(sub s 2 (length s - 4))
| s -> s

type name = mident * ident

let mk_name md id = (md, id)
Expand Down
5 changes: 4 additions & 1 deletion kernel/basic.mli
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ val mk_mident : string -> mident
(** [mident_eq md md'] checks if the two modules identifiers [mid] and [mid'] are equals *)
val mident_eq : mident -> mident -> bool

(** [string_of_ident id] returns a string of the identifier [id] *)
(** [string_of_mident id] returns a string of the module identifier [id] *)
val string_of_mident : mident -> string

(** [mident_of_ident id] transform the identifier [id] into a module identifier *)
val mident_of_ident : ident -> mident

(** type for constant names such as [foo.bar] *)
type name

Expand Down
10 changes: 5 additions & 5 deletions parsing/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ rule token = parse
| "injective" { KW_INJ ( get_loc lexbuf ) }
| "thm" { KW_THM ( get_loc lexbuf ) }
| "private" { KW_PRV ( get_loc lexbuf ) }
| "require" space+ (mident as md) { REQUIRE (get_loc lexbuf , mk_mident md) }
| "require" { REQUIRE ( get_loc lexbuf ) }
| "assert" { ASSERT ( get_loc lexbuf ) }
| "#NAME" space+ (mident as md) { NAME (get_loc lexbuf , mk_mident md) }
| "#REQUIRE" space+ (mident as md) { REQUIRE (get_loc lexbuf , mk_mident md) }
| "#NAME" { NAME ( get_loc lexbuf ) }
| "#REQUIRE" { REQUIRE ( get_loc lexbuf ) }
| "#EVAL" { EVAL ( get_loc lexbuf ) }
| "#INFER" { INFER ( get_loc lexbuf ) }
| "#CHECK" { CHECK ( get_loc lexbuf ) }
| "#CHECKNOT" { CHECKNOT ( get_loc lexbuf ) }
| "#ASSERT" { ASSERT ( get_loc lexbuf ) }
| "#ASSERT" { ASSERT ( get_loc lexbuf ) }
| "#ASSERTNOT"{ ASSERTNOT ( get_loc lexbuf ) }
| "#PRINT" { PRINT ( get_loc lexbuf ) }
| "#GDT" { GDT ( get_loc lexbuf ) }
| "#" { pragma [] lexbuf }
| "#" { pragma [] lexbuf }
| mident as md '.' (ident as id)
{ QID ( get_loc lexbuf , mk_mident md , mk_ident id ) }
| ident as id
Expand Down
8 changes: 4 additions & 4 deletions parsing/menhir_parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ let make_declaration ~lid ~parameters ~definibility ~ty md =
%token <Kernel.Basic.loc> ASSERTNOT
%token <Kernel.Basic.loc> PRINT
%token <Kernel.Basic.loc> GDT
%token <Kernel.Basic.loc*Basic.mident> NAME
%token <Kernel.Basic.loc*Basic.mident> REQUIRE
%token <Kernel.Basic.loc> NAME
%token <Kernel.Basic.loc> REQUIRE
%token <Kernel.Basic.loc> TYPE
%token <Kernel.Basic.loc> KW_DEF
%token <Kernel.Basic.loc> KW_DEFAC
Expand Down Expand Up @@ -173,8 +173,8 @@ line:
| PRINT STRING DOT {fun _ -> Print($1, $2)}
| GDT ID DOT {fun _ -> DTree($1, None, snd $2)}
| GDT QID DOT {fun _ -> let (_,m,v) = $2 in DTree($1, Some m, v)}
| n=NAME DOT {fun _ -> Name(fst n, snd n)}
| r=REQUIRE DOT {fun _ -> Require(fst r,snd r)}
| NAME ID DOT {fun _ -> Name($1, mident_of_ident (snd $2))}
| REQUIRE ID DOT {fun _ -> Require($1, mident_of_ident (snd $2))}
| PRAGMA {fun _ -> Pragma (fst $1, snd $1) }
| EOF {raise End_of_file}

Expand Down
6 changes: 3 additions & 3 deletions parsing/tokens.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ type token =
| RIGHTSQU
| RIGHTPAR
| RIGHTBRA
| ID of (loc * ident)
| QID of (loc * mident * ident)
| NAME of (loc * mident)
| REQUIRE of (loc * mident)
| LONGARROW
| LEFTSQU
| LEFTPAR
| LEFTBRA
| ID of (loc * ident)
| FATARROW
| EOF
| DOT
Expand All @@ -27,6 +25,8 @@ type token =
| COLON
| EQUAL
| ARROW
| NAME of loc
| REQUIRE of loc
| EVAL of loc
| INFER of loc
| CHECK of loc
Expand Down
1 change: 1 addition & 0 deletions tests/OK/invalid-name.dk
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0 : Type.
4 changes: 2 additions & 2 deletions tests/OK/require.dk
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
require def.
require {|def|}.

x : def.A.
x : def.A.
3 changes: 3 additions & 0 deletions tests/OK/require_invalid.dk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#REQUIRE {|invalid-name|}.

1 : 0.

0 comments on commit 767de3c

Please sign in to comment.