Commit graph

58 commits

Author SHA1 Message Date
Leonardo de Moura
fdbbdf68fc refactor(library/init/lean/elaborator/basic): make sure ElabState does not depend on parser state
cc @kha
2019-07-19 17:07:39 -07:00
Leonardo de Moura
f9459f6e93 feat(library/init/lean/syntax): add Syntax.other
We will use this feature to implement the new elaborator.
An elaborator produces `Syntax Expr` instead of `Syntax`.
2019-07-19 10:45:01 -07:00
Leonardo de Moura
eb7b2b77fa chore(library/init/lean): minor changes 2019-07-18 17:16:44 -07:00
Leonardo de Moura
b1d5a4284d feat(library/init/lean): address issue raised in the previous commit
We also changed the type of `addImportedFn` to `Array (Array α) → IO σ`.
This modification avoids the `unsafeIO` hack at `parser.lean`.
2019-07-18 13:20:46 -07:00
Leonardo de Moura
261d316990 chore(library/init/lean/parser/module): document potential issue 2019-07-18 12:45:26 -07:00
Leonardo de Moura
f0899b381d feat(library/init/lean/parser/module): add displayStx param 2019-07-17 19:09:15 -07:00
Leonardo de Moura
912b7551d2 chore(library/init/lean/parser/module): interrupt test parser at #exit 2019-07-16 14:15:40 -07:00
Leonardo de Moura
3169a5f0d1 chore(library/init/lean/parser/module): display parsing time in test parser 2019-07-16 13:49:10 -07:00
Leonardo de Moura
b157b2c9e9 feat(library/init/lean/parser): improve error messages 2019-07-16 08:16:03 -07:00
Leonardo de Moura
367f28e90b chore(library/init/lean/parser/module): export test function 2019-07-15 13:39:56 -07:00
Leonardo de Moura
a8c36d4c29 feat(library/init/lean/syntax): remove MacroScopes
We are going to use a simpler approach to help users writing hygienic
macros. Suppose we have a syntax quotation such as
```
`(let x := %%a;
  ite x x %%b)
```
We will parse this quotation, and during elaboration, we must create
code (i.e., an `Expr`) such that given `a` and `b`, it constructs
a (new) syntax object, and we want to guarantee that there is no accidental name capture.
So, given the syntax object `S` representing the quotation above, we
first pre-resolve the identifiers in `S`. In this step, we annotate the
identifier `ite` with the global declaration `_root_.ite`.
Then, we create a fresh identifier for each identifier, but we would
preserve the pre-resolved information.
Assume the monadic action `mkFresh <id>` creates a fresh identifier with
prefix `<id>`, and `mkFreshWithPreresolved <id> <pre-list>` creates a
fresh identifier with prefix <id> and pre-resolved list `<pre-list>`.
Then, the quotation above would be transformed into:
```
let x := mkFresh `x;
let ite := mkFreshWith `ite [`_root_.ite];
`(let %%x := %%a;
 %%ite %%x %%x %%b)
```
Here, the new quotation is just syntax sugar for a sequence of `Syntax`
constructor applications. Now, whenever we want to create a syntax
object using the quotation above, we guarantee there is no accidental
name capture because we are creating a fresh identifier for all
identifiers in the quotation. Global references are preserved using the
field preresolved that we already have.
It is straightforward to implement the transformation above using a
mapping. Note that if we use the same mapping to elaborate two different
quotations, we are essentially saying they share the same scope.
For example, suppose we have
```
let c := `(ite x x %%b);
`(let x := %%a; %%c)
```
If we use the same mapping, we produce
```
let x := mkFresh `x;
let ite := mkFreshWith `ite [`_root_.ite];
let c := `(%%ite %%x %%x %%b);
`(let %%x := %%a; %%c)
```
If we create a new mapping when compiling each quotation, we get
```
let x := mkFresh `x;
let ite := mkFreshWith `ite [`_root_.ite];
let c := `(%%ite %%x %%x %%b);
let x1 := mkFresh `x;
`(let %%x1 := %%a; %%c)
```
which is probably not what the user wants.
We can provide a simple notation for users specifying which behavior
they want. The default may be super simple. Example: we have a new mapping (aka scope) per declaration.
The approach above is simple and efficient. It is also great for
users that want to create syntax objects during the elaboration phase
and want to avoid name capture.
2019-07-15 10:00:27 -07:00
Leonardo de Moura
146a796c5c feat(library/init/lean/module): add ModuleParser with error recovery 2019-07-15 09:32:13 -07:00
Leonardo de Moura
b9149dd428 fix(library/init/lean/parser/module): token table initialization 2019-07-14 08:31:12 -07:00
Leonardo de Moura
52157cebf7 feat(library/init/lean/parser): add ParserAttribute skeleton 2019-07-14 07:16:14 -07:00
Leonardo de Moura
e4c9326c00 feat(library/init/lean/parser): add module.lean 2019-07-12 16:42:25 -07:00
Leonardo de Moura
55626ba60d chore(library/init/lean): disable new frontend for now
We are going to start making drastic changes in the parser,
elaborator, attributes, etc. Examples:
- No View objects. I am going to implement match_syntax.
- No RecT in the parser. I am going to implement parser extensions
using an approach similar to the one I used to implement environment
extensions.
- No Parsec. I will use an approach similar to the one used in the
experiment https://github.com/leanprover/lean4/tree/master/tests/playground/parser

It is easier to perform these changes with the new frontend disabled.
I will slowly re-active it as I apply the changes.

cc @kha
2019-06-05 15:26:43 -07:00
Leonardo de Moura
e58949e938 chore(library/init/control/id): rename id monad to Id 2019-03-29 16:45:52 -07:00
Leonardo de Moura
60f8d17942 refactor(library/init/data/string/basic): simplify String.Iterator
The `offset` field is problematic because it prevents us from having an
efficient way of moving back and forth between `String.Pos` and `String.Iterator`.

@kha I temporarily added `String.OldIterator` for making sure the
parser doesn't break. This is a temporary fix that will be eliminated
after we replace `parsec`.
2019-03-25 07:57:12 -07:00
Leonardo de Moura
91204a52d6 chore(library/init/data/dlist): Dlist => DList 2019-03-21 17:03:22 -07:00
Leonardo de Moura
3befc219c9 chore(library/init): Empty => empty when it is a function 2019-03-21 17:03:15 -07:00
Leonardo de Moura
2be87ecd92 chore(library/init): Bool.tt => Bool.true and Bool.ff => Bool.false 2019-03-21 15:06:44 -07:00
Leonardo de Moura
04e20623e6 chore(*): use lowercase dir names 2019-03-21 15:06:44 -07:00
Leonardo de Moura
67fb78bb47 chore(*): renaming files 2019-03-21 15:06:44 -07:00
Sebastian Ullrich
beda5f5f43 chore(library): capitalize types and namespaces 2019-03-21 15:06:43 -07:00
Sebastian Ullrich
b939162168 chore(library): switch from snake_case to camelCase 2019-03-21 15:06:43 -07:00
Leonardo de Moura
ecdb9d6df0 feat(library/init, frontends/lean): add abbreviation for abbreviation 2019-03-15 16:01:25 -07:00
Sebastian Ullrich
e0bbc094ad chore(library/init): remove coroutines from stdlib 2019-03-08 15:34:17 +01:00
Sebastian Ullrich
234e4d1e8a refactor(library/init/lean/elaborator): replace coroutines with explicit state 2019-03-08 15:23:01 +01:00
Sebastian Ullrich
81615fc856 refactor(library/init/lean/parser/module): replace coroutines with explicit snapshot state 2019-03-07 10:32:28 -08:00
Sebastian Ullrich
6f83faaee0 perf(library/init/lean/parser/command): index command parsers by first token 2019-03-07 11:28:42 +01:00
Sebastian Ullrich
cfce916438 perf(library/init/lean/parser/module): make sure commands_aux is tail-recursive 2019-03-06 13:58:26 +01:00
Sebastian Ullrich
85bc52b9f2 feat(library/init/lean/frontend): profile frontend 2019-03-06 11:08:38 +01:00
Sebastian Ullrich
bd70dc1fc9 perf(library/init/lean/parser): move backtrackable state from parser_core_t to module_parser_m 2018-11-08 15:58:41 +01:00
Sebastian Ullrich
41f4a34d4b feat(library/init/lean/parser/token): cache hit statistics 2018-11-08 14:52:54 +01:00
Sebastian Ullrich
090c4c0ce7 feat(library/init/lean/syntax): add lazily propagated macro scopes to syntax_node 2018-11-06 16:46:50 +01:00
Sebastian Ullrich
0d7ea62f9a perf(frontends/lean/elaborator,library/init/lean): put out_params first to benefit from instance pre-filtering 2018-10-30 17:43:05 +01:00
Sebastian Ullrich
2e0d6649be perf(library/init/lean/parser/basic): make basic_parser_m semireducible 2018-10-30 17:43:05 +01:00
Leonardo de Moura
89afabae29 refactor(library/init/lean/parser/parsec): make sure custom error message doesn't need to be inhabited 2018-10-21 10:57:23 -07:00
Sebastian Ullrich
ca8e75be9e fix(library/init/lean/elaborator): check for and consume end of input 2018-10-03 16:00:08 -07:00
Sebastian Ullrich
097b7be14f refactor(library/init/lean/parser/token): change raw view type to option syntax_atom and create raw_str to give some raw parsers view defaults 2018-10-02 14:55:28 -07:00
Sebastian Ullrich
df278096c4 fix(library/init/lean): fixes fixes fixes 2018-09-28 13:08:25 -07:00
Sebastian Ullrich
2e5ea16e2f perf(library/init/lean/parser): cache consecutive calls to token at the same position
Parser performance improved by about 33%
2018-09-27 16:08:19 -07:00
Sebastian Ullrich
e661aaeacf refactor(library/init/lean/parser): store registered parsers in configs, use config hierarchy to avoid mutually recursive types
And other refactorings along the way
2018-09-27 10:05:10 -07:00
Sebastian Ullrich
2c07922327 refactor(library/init/lean/parser): minimize parser_state, have the module coroutine take and return parser_config 2018-09-26 13:20:07 -07:00
Sebastian Ullrich
07901fcfcb refactor(library/init/lean/parser/module): put prelude and imports into non-optional header parser to make the life of the elaborator and other consumers a bit easier 2018-09-26 13:20:07 -07:00
Sebastian Ullrich
1d01e81de8 refactor(library/init/lean/parser): do not construct final syntax tree independent from intermediate outputs
This makes sure we have a single consistent view of the file
2018-09-25 18:28:53 -07:00
Sebastian Ullrich
c7c459d47b Revert "perf(library/init/lean/parser): collect tokens in trie instead of list, do not inline"
This reverts commit e4c50b2b09.

Lists are efficient enough and make it easier to customize the trie construction.

Keep the `donotinline` though.
2018-09-20 09:38:10 -07:00
Leonardo de Moura
5ff9e24b17 feat(library/init/control): do not use unnecessary structures
It confuses the compiler.
2018-09-20 08:39:25 -07:00
Sebastian Ullrich
e4c50b2b09 perf(library/init/lean/parser): collect tokens in trie instead of list, do not inline 2018-09-19 12:36:34 -07:00
Sebastian Ullrich
a6f25e2ae7 refactor(library/init/lean/parser/token): id ~> ident, ident ~> ident.parser 2018-09-17 18:47:50 -07:00