Commit graph

106 commits

Author SHA1 Message Date
Sebastian Ullrich
93d13ffea3 chore(library/init/lean): lean.parser.reader ~> lean.parser 2018-08-30 16:34:47 -07:00
Sebastian Ullrich
d60e3a66ce refactor(library/init/lean/parser/reader): make monad stack not reducible 2018-08-30 15:59:38 -07:00
Sebastian Ullrich
de9d894c14 feat(library/init/lean/parser/reader): use coroutine on the module level 2018-08-29 16:42:24 -07:00
Sebastian Ullrich
2528aee72b refactor(library/init/lean/parser/reader): use different monad stacks for different parts of the reader 2018-08-29 16:42:24 -07:00
Sebastian Ullrich
cec1ee2564 feat(library/init/lean/parser/parsec): reintroduce parsec_t 2018-08-29 16:42:24 -07:00
Sebastian Ullrich
a178f181a8 chore(library/init/lean/parser/macro): remove old name resolution prototype 2018-08-28 13:13:14 -07:00
Sebastian Ullrich
46f734b1b1 refactor(library/init/lean/parser/reader): replace macro with syntax_node_kind
Also make sure that the name inside a node kind is the full name of the
declaration. This way, we cannot have accidentally conflicting node kind names.
2018-08-28 13:13:14 -07:00
Sebastian Ullrich
61f8ebf4ef refactor(library/init/lean/parser/reader): destructure reader into monad and has_tokens typeclass 2018-08-23 10:38:59 -07:00
Sebastian Ullrich
762259a96f chore(library/init/lean/parser/reader): cleanup 2018-08-22 14:32:03 -07:00
Sebastian Ullrich
287fdce45b refactor(library/init/lean/parser/reader): remove reader.has_view default instance 2018-08-22 14:32:03 -07:00
Sebastian Ullrich
c69cc61292 feat(frontends/lean,library/init/lean/parser/reader/module): add node_choice! macro
Creates an inductive type from an ordered choice reader
2018-08-22 14:32:03 -07:00
Sebastian Ullrich
1b8e74123c feat(frontends/lean/{builtin_exprs,elaborator}): special-case try inside of node! 2018-08-22 14:32:03 -07:00
Sebastian Ullrich
26d696a937 feat(frontends/lean,library/init/lean/parser/reader/module): basic node! macro 2018-08-22 14:32:03 -07:00
Leonardo de Moura
261dc999d0 refactor(frontends/lean/elaborator): mark thunk as opaque, and thunk A to A is now a coercion
@kha I was working in the new declaration type and using tasks there.
Since we don't have tasks yet in Lean, I decided to start refactoring
the `thunk` type. I defined it as:

```
-- TODO(Leo): mark as opaque, it is implemented by the new runtime
structure thunk (α : Type u) : Type u :=
(fn : unit → α)

def thunk.pure {α : Type u} (a : α) : thunk α :=
⟨λ _, a⟩

def thunk.get {α : Type u} (t : thunk α) : α :=
t.fn ()
```

The idea is to use the runtime primitives to implement them.
Then, I realized the support for `thunk`s in the elaborator are quite
hacky. Given `f x`, if `f`'s domain has type `thunk A`, we elaborate
`f x` as `f (fun _, x)` even if `x` has type `thunk A`.
This is quite bad, for example, suppose we have
```
def f (x : thunk A) := ...
```
Then, the following definition is type incorrect.
```
def g (x : thunk A) := f x
```
and we are forced to write
```
def g (x : thunk A) := f (x ())
```
The term `f (x ())` will be elaborated as `f (fun _, x ())` and an
unnecessary closure is created at runtime.

This mechanism inherited from Lean 3 is also incompatible with the
new thunk definition. Given `x : thunk A`, I want to write `x.get`
to retrieve the value instead of `x ()` as in Lean 3.
However, `x.get` expands into the nonsensical `(fun _, x).get`.

So, I decided to view the mapping `A` to `thunk A` as a "coercion".
I used double quotes, because it is a macro instead of a function.
If it were a coercion, then we would be using `thunk.pure` to coerce
values but this is not we want most of the time.
For example, given `f : thunk A -> B` and a term `t : A`, when we write
`f t`, we want it to be converted into `f (fun _, t)` instead of
`f (thunk.pure t)` which would eagerly compute `t`. The transformation
`t` into `fun _, t` is syntactic.
We cannot implement it using type classes. I implemented it as
a hard-coded extra case like the one from `Prop` to `bool`.
We can also add a coercion from `thunk A` to `A` to avoid the `.get`.

That being said, I had a few breakages in the code base since we only
use coercions when the given and expected type do not contain
metavariables.
2018-08-21 15:27:51 -07:00
Sebastian Ullrich
6b55e24ab7 feat(library/init/{io,control/except}): use lift_t to automatically upcast io and other errors 2018-08-21 08:43:09 -07:00
Sebastian Ullrich
ba7d3ee178 refactor(library/init/lean/parser/{reader/module,syntax}): move new coercions 2018-08-06 15:05:41 -07:00
Sebastian Ullrich
bf043ab8bd feat(library/init/lean/parser/reader/basic): first has_view prototype, plus prefix ~> notation expansion based on it 2018-08-02 20:35:15 -07:00
Sebastian Ullrich
f52395140a feat(library/init/lean/parser/parsec): add dbg helper combinator 2018-08-02 13:32:42 -07:00
Sebastian Ullrich
1e1bf4b0f8 feat(library/init/lean/parser/reader/basic): add explicit syntax.missing objects on error 2018-08-02 13:32:28 -07:00
Sebastian Ullrich
eda9e4bb3f feat(library/derive_attribute): temporary, hacky C++ implementation of @[derive] 2018-08-01 18:44:23 -07:00
Sebastian Ullrich
3951db3b0b fix(library/init/lean/parser/reader/basic): error recovery reprint issue 2018-07-30 17:55:17 -07:00
Sebastian Ullrich
87dc8adbe6 fix(library/init/lean/parser/parsec): monad_except.catch should not reset position, consumed flag 2018-07-30 17:50:37 -07:00
Sebastian Ullrich
8666047703 feat(library/init/lean/parser/reader/module): reserve, mixfix, universe commands 2018-07-30 17:30:20 -07:00
Sebastian Ullrich
242d63af25 fix(library/init/lean/parser/reader/basic): store token start position for perfect roundtripping 2018-07-30 17:30:20 -07:00
Sebastian Ullrich
312de57aec test(tests/lean/reader1): test error recovery and fix bug 2018-07-30 17:30:20 -07:00
Sebastian Ullrich
0fd9d29ba2 feat(library/init/lean/parser/reader/module): command-level error recovery 2018-07-30 10:38:00 -07:00
Sebastian Ullrich
3728b2ba3f feat(library/init/lean/parser/reader/basic): add error list handling 2018-07-30 10:38:00 -07:00
Sebastian Ullrich
e34f2e8cd7 chore(library/init/lean/parser): improve error messages 2018-07-30 10:38:00 -07:00
Sebastian Ullrich
2823bebd23 refactor(library/init/lean/parser/parsec): message.pos: replace with iterator
This allows efficient recovery from a parse error as well as implementing
`has_to_string` for `message`
2018-07-30 10:38:00 -07:00
Sebastian Ullrich
898e14cdf5 fix(library/init/lean/parser/parsec): orelse: do not backtrack on success
This change makes backtracking behavior more predictable and
matches Parsec and Megaparsec's behavior. While the original Parsec paper
motivates the old behavior by arguing it implements the "longest match" rule,
this is obviously only true in a very limited sense.
2018-07-30 10:38:00 -07:00
Sebastian Ullrich
10b18e77a1 feat(library/init/lean/parser/reader/basic): combinators: create partial syntax trees 2018-07-27 16:19:02 -07:00
Sebastian Ullrich
0b240cbfe9 feat(library/init/lean/parser/reader/basic): read_m: change custom message type to syntax 2018-07-27 15:27:37 -07:00
Sebastian Ullrich
389e9b7b49 feat(library/init/lean/parser/parsec): use [inhabited μ] instead of unit for custom message type of basic parsers
In hindsight, this seems to simplify usage without compromising static typing much
2018-07-27 15:10:20 -07:00
Sebastian Ullrich
65fd050b83 feat(library/init/lean/parser/parsec): add custom error message type 2018-07-27 14:29:50 -07:00
Sebastian Ullrich
ad1e72d3e1 fix(library/init/lean/parser/reader/module): fix file 2018-07-27 09:14:11 -07:00
Sebastian Ullrich
f714a6703f refactor(library/init/lean/parser/reader/module): coercions and notations 2018-07-26 17:28:11 -07:00
Sebastian Ullrich
d526262266 refactor(library/init/lean/parser/reader/basic): rec_t.recurse: clearer implementation 2018-07-26 17:28:11 -07:00
Sebastian Ullrich
669de39df8 refactor(library/init/lean/parser/reader/module): make symbol a local coercion 2018-07-26 17:28:11 -07:00
Leonardo de Moura
5d3f421e70 feat(library/init/lean/parser/parsec): avoid unnecessary [alternative m] dependencies 2018-07-26 15:51:00 -07:00
Leonardo de Moura
35b100bb94 feat(library/init/lean/parser/parsec): implement not_followed_by using catch 2018-07-26 15:47:19 -07:00
Sebastian Ullrich
134d27dbec feat(library/init/lean/parser/parsec): longest_match should return all longest parses
In the case of overlapping notations, we will return a choice node of all
possible parses.
2018-07-25 18:07:56 -07:00
Sebastian Ullrich
18b4456a84 Revert "refactor(library/init/lean/parser/parsec): monad_parsec: move from monad_lift/monad_map to direct primitives"
This reverts commit 9db0724bf1.
2018-07-25 13:53:29 -07:00
Sebastian Ullrich
218af640bb fix(library/init/lean/parser/reader/term): add missing file 2018-07-20 18:44:37 +02:00
Sebastian Ullrich
1c561726de feat(library/init/lean/parser/reader/module): basic notation command 2018-07-18 17:45:37 +02:00
Sebastian Ullrich
8444a7412e feat(library/init/lean/parser/reader/basic): add a small monad transformer for managing recursion and use it to implement recursive section parsing 2018-07-16 18:39:23 +02:00
Sebastian Ullrich
5b55600e71 feat(library/init/lean/parser/reader/module): open command 2018-07-16 12:38:27 +02:00
Sebastian Ullrich
9e5ae42625 chore(library/init/lean/parser/reader/token): improve error messages 2018-07-13 16:10:13 +02:00
Sebastian Ullrich
09a0397648 fix(library/init/lean/parser/reader/token): fix keyword parsing using longest_match 2018-07-13 15:51:48 +02:00
Sebastian Ullrich
8707773872 feat(library/init/lean/parser/parsec): introduce observing and longest_match primitive parser combinators 2018-07-13 15:51:00 +02:00
Sebastian Ullrich
9db0724bf1 refactor(library/init/lean/parser/parsec): monad_parsec: move from monad_lift/monad_map to direct primitives
This breaks the code for variable-length tokens that depended on lifting
`parsec` into `read_m`. Either `read_m` could be parameterized by its state,
or we just hard-code all variable-length tokens.
2018-07-12 17:53:43 +02:00