-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
193 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
(include_subdirs no) | ||
|
||
(library | ||
(name mcltt) | ||
(modules main parser lexer test) | ||
(inline_tests) | ||
(preprocess | ||
(pps ppx_inline_test))) | ||
(name Mcltt) | ||
(modules main lexer) | ||
(libraries MclttExtracted) | ||
; (inline_tests) | ||
; (preprocess | ||
; (pps ppx_inline_test)) | ||
) | ||
|
||
(env | ||
(dev | ||
(flags | ||
(:standard -w -67 -w -32 -w -39)))) | ||
(:standard -w -67 -w -32 -w -33 -w -39)))) | ||
|
||
(ocamllex lexer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Generated Files | ||
*.ml | ||
*.mli |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
(library | ||
(name MclttExtracted)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,39 @@ | ||
{ | ||
open Parser | ||
open Lexing | ||
open MclttExtracted.Parser | ||
|
||
let get_position lexbuf = (lexbuf.lex_start_p, lexbuf.lex_curr_p) | ||
} | ||
|
||
let string = ['a'-'z']+ | ||
let string = ['a'-'z''A'-'Z']+ | ||
|
||
rule read = | ||
parse | ||
| '(' { LPAREN () } | ||
| ')' { RPAREN () } | ||
| '.' { DOT () } | ||
| ':' { COLON () } | ||
| "zero" { ZERO () } | ||
| "succ " { SUCC () } | ||
| "fun" { LAMBDA () } | ||
| "pi" { PI () } | ||
| [' ' '\t' '\n' ] { read lexbuf } | ||
| "Nat" { NAT () } | ||
| ['0'-'9']+ as lxm { INT (int_of_string lxm) } | ||
| "Type" { TYPE () } | ||
| string { VAR (Lexing.lexeme lexbuf) } | ||
| eof { EOF () } | ||
| "->" { ARROW (get_position lexbuf) } | ||
| '@' { AT (get_position lexbuf) } | ||
| '|' { BAR (get_position lexbuf) } | ||
| ':' { COLON (get_position lexbuf) } | ||
| ',' { COMMA (get_position lexbuf) } | ||
| "=>" { DARROW (get_position lexbuf) } | ||
| "(*" { comment lexbuf } | ||
| '(' { LPAREN (get_position lexbuf) } | ||
| ')' { RPAREN (get_position lexbuf) } | ||
| "zero" { ZERO (get_position lexbuf) } | ||
| "succ" { SUCC (get_position lexbuf) } | ||
| "rec" { REC (get_position lexbuf) } | ||
| "return" { RETURN (get_position lexbuf) } | ||
| "end" { END (get_position lexbuf) } | ||
| "fun" { LAMBDA (get_position lexbuf) } | ||
| "forall" { PI (get_position lexbuf) } | ||
| [' ' '\t'] { read lexbuf } | ||
| ['\n'] { new_line lexbuf; read lexbuf } | ||
| "Nat" { NAT (get_position lexbuf) } | ||
| ['0'-'9']+ as lxm { INT (get_position lexbuf, int_of_string lxm) } | ||
| "Type" { TYPE (get_position lexbuf) } | ||
| string { VAR (get_position lexbuf, Lexing.lexeme lexbuf) } | ||
| eof { EOF (get_position lexbuf) } | ||
| _ as c { failwith (Printf.sprintf "unexpected character: %C at line %d, column %d" c lexbuf.lex_start_p.pos_lnum (lexbuf.lex_start_p.pos_cnum - lexbuf.lex_start_p.pos_bol)) } | ||
and comment = | ||
parse | ||
| "*)" { read lexbuf } | ||
| _ { comment lexbuf } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,25 @@ | ||
open Parser.MenhirLibParser.Inter | ||
module Parser = MclttExtracted.Parser | ||
module Entrypoint = MclttExtracted.Entrypoint | ||
open Parser | ||
open MenhirLibParser.Inter | ||
open Entrypoint | ||
|
||
let parse text = | ||
(* Before parsing, we must generate a token stream from a lexer buffer, | ||
which we then feed into the parser. *) | ||
let rec loop lexbuf = lazy (Buf_cons (Lexer.read lexbuf, loop lexbuf)) in | ||
let token_stream = loop (Lexing.from_string text) in | ||
match Parser.prog 50 token_stream with | ||
| Parsed_pr (e, _) -> Some e | ||
| Parsed_pr ((exp, _typ), _) -> Some exp | ||
| Fail_pr_full (_, _) -> None | ||
| _ -> None | ||
|
||
let main () = | ||
print_string "File path to load: "; | ||
let fp = read_line () in | ||
let chan = open_in fp in | ||
(* Before parsing, we must generate a token stream from a lexer buffer, | ||
which we then feed into the parser. *) | ||
let rec loop lexbuf = lazy (Buf_cons (Lexer.read lexbuf, loop lexbuf)) in | ||
let token_stream = loop (Lexing.from_channel chan) in | ||
Entrypoint.main 50 token_stream |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
(* Unit test cases for parsing *) | ||
|
||
open Main | ||
open Parser.Cst | ||
open Entrypoint.Cst | ||
|
||
let x, y, z = ("x", "y", "z") | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
(lang dune 3.4) | ||
(lang dune 3.16) | ||
(using menhir 2.1) | ||
(name mcltt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
From Coq Require Extraction. | ||
From Coq Require Import ExtrOcamlBasic ExtrOcamlNatInt ExtrOcamlNativeString. | ||
|
||
From Equations Require Import Equations. | ||
|
||
From Mcltt.Core Require Import Base. | ||
From Mcltt.Core.Syntactic Require Import SystemOpt. | ||
From Mcltt.Extraction Require Import TypeCheck. | ||
From Mcltt.Frontend Require Import Elaborator Parser. | ||
Import MenhirLibParser.Inter. | ||
Import Syntax_Notations. | ||
|
||
Variant main_result := | ||
| AllGood : forall A M, {{ ⋅ ⊢ M : A }} -> main_result | ||
| TypeCheckingFailure : forall A M, ~ {{ ⋅ ⊢ M : A }} -> main_result | ||
| ElaborationFailure : forall cst, elaborate cst nil = None -> main_result | ||
| ParserFailure : Aut.state -> Aut.Gram.token -> main_result | ||
| ParserTimeout : nat -> main_result | ||
. | ||
|
||
Definition inspect {A} (x : A) : { y | x = y } := exist _ x eq_refl. | ||
Extraction Inline inspect. | ||
|
||
#[local] | ||
Ltac impl_obl_tac := try eassumption. | ||
#[tactic="impl_obl_tac"] | ||
Equations main (log_fuel : nat) (buf : buffer) : main_result := | ||
| log_fuel, buf with Parser.prog log_fuel buf => { | ||
| Parsed_pr (cst_exp, cst_typ) _ with inspect (elaborate cst_typ nil) => { | ||
| exist _ (Some A) _ with inspect (elaborate cst_exp nil) => { | ||
| exist _ (Some M) _ with type_check_closed A _ M _ => { | ||
| left _ => AllGood A M _ | ||
| right _ => TypeCheckingFailure A M _ | ||
} | ||
| exist _ None _ => ElaborationFailure cst_exp _ | ||
} | ||
| exist _ None _ => ElaborationFailure cst_typ _ | ||
} | ||
| Fail_pr_full s t => ParserFailure s t | ||
| Timeout_pr => ParserTimeout log_fuel | ||
} | ||
. | ||
Next Obligation. | ||
eapply elaborator_gives_user_exp; eassumption. | ||
Qed. | ||
Next Obligation. | ||
eapply elaborator_gives_user_exp; eassumption. | ||
Qed. | ||
|
||
Extraction Language OCaml. | ||
|
||
Set Extraction Flag 1007. | ||
Set Extraction Output Directory "../driver/extracted". |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.