Commit graph

96 commits

Author SHA1 Message Date
Leonardo de Moura
a52f67cea8 chore(library/init/lean/parser/parser): missing space 2019-07-16 13:10:07 -07:00
Leonardo de Moura
6f31f6a38f fix(library/init/lean/parser/parser): typo at quotedCharFn 2019-07-16 10:48:28 -07:00
Leonardo de Moura
0dcdc2c198 feat(library/init/lean/parser/term): add support for "named" patterns n@(x :: s)
@kha, the implementation is a little bit hackish. It is whitespace
sensitive to avoid `f @g`, an application with argument `@g` to be
parsed as a named pattern.
Here are other approaches I have considered:

1- In the `namedPattern`, we add a guard that ensures the pattern
is *not* an identifier. Thus, `f @g` would not be considered a valid
`namedPattern`. Drawback: we would always try to parse it as a
namedPattern first, fail, and then try as an application.

2- Enforce whitespace before application arguments. Drawback: `f(a+b)`
would not be a valid application anymore.
2019-07-16 10:09:01 -07:00
Leonardo de Moura
260ea04add fix(library/init/lean/parser/parser): typo startPart ==> startPos 2019-07-16 09:36:44 -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
f206b30fd7 feat(library/init/lean/parser): add charLit 2019-07-16 07:22:09 -07:00
Leonardo de Moura
1636083cae fix(library/init/lean/parser/parser): typo 2019-07-15 14:07:27 -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
6a47055850 feat(library/init/lean/parser/parser): improve orelse error message 2019-07-15 09:31:37 -07:00
Leonardo de Moura
f8fba6877b fix(library/init/lean/parser/parser): add ident as possible first token for symbolOrIdent 2019-07-14 08:19:42 -07:00
Leonardo de Moura
1dce4a8f70 feat(library/init/lean/parser/parser): add symbolOrIdent 2019-07-14 08:09:04 -07:00
Leonardo de Moura
a843c0be55 feat(library/init/lean/parser/parser): shared TokenTable 2019-07-14 07:53:24 -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
36da73b6cb feat(library/init/lean/parser/command): add (some) notation commands 2019-07-12 14:01:23 -07:00
Leonardo de Moura
151735d356 chore(library/init/lean/parser/parser): remove testParser 2019-07-12 13:57:56 -07:00
Leonardo de Moura
166a6fa75a feat(library/init/lean/parser/command): missing commands 2019-07-12 11:00:14 -07:00
Leonardo de Moura
72477f3cc6 feat(library/init/lean/parser/command): improve how optional affects firstTokens field 2019-07-11 17:22:26 -07:00
Leonardo de Moura
05a3bab321 feat(library/init/lean/parser): add command.lean 2019-07-11 16:43:44 -07:00
Leonardo de Moura
3370ab7398 feat(library/init/lean/parser/term): allow equations to be used in let-decls 2019-07-11 13:13:08 -07:00
Leonardo de Moura
195fb27ce5 feat(library/init/lean/parser/term): add let 2019-07-11 09:51:34 -07:00
Leonardo de Moura
2c979459a9 feat(library/init/lean/parser/parser): add many1Indent1 combinator
It is useful for create whitespace sensitive notation such as `match` expressions.
2019-07-10 16:10:41 -07:00
Leonardo de Moura
f95ed02999 feat(library/init/lean/parser/parser): add withPosition and checkColGe parsers 2019-07-10 15:11:54 -07:00
Leonardo de Moura
e55e5953d5 chore(library/init/lean/parser/term): remove manual eta expansions 2019-07-09 16:35:06 -07:00
Leonardo de Moura
5dae0303af chore(library/init/lean/parser): force eta expansion and remove unnecessary [inline]
TODO: improve eta-expansion step in the compiler.
2019-07-09 14:09:24 -07:00
Leonardo de Moura
b89a389427 chore(library/init/lean/parser/parser): force eta-expansion 2019-07-08 20:46:34 -07:00
Leonardo de Moura
5cfa13d08b fix(library/init/lean/parser/parser): consume whitespace in the beginning of the input 2019-07-08 14:13:50 -07:00
Leonardo de Moura
f66f6fd455 fix(library/init/lean/parser/parser): The first tokens of try p are the first tokens of p 2019-07-08 13:46:19 -07:00
Leonardo de Moura
d3ca360e7f feat(library/init/lean/parser): depArrow proof of concept 2019-07-08 10:49:54 -07:00
Leonardo de Moura
e2bcf179ac fix(library/init/lean/parser/parser): missing trim 2019-07-08 10:33:51 -07:00
Leonardo de Moura
8b3d932212 chore(library/init/lean/parser): maxPrec ==> appPrec 2019-07-08 09:17:32 -07:00
Leonardo de Moura
9334f54b87 feat(library/init/lean/parser/parser): support for whitespace sensitive left binding power
We use this new feature to implement array access notation `a[i]`.
2019-07-07 07:21:10 -07:00
Leonardo de Moura
794edcb18c chore(library/init/lean/parser): minor modifications 2019-07-05 18:31:03 -07:00
Leonardo de Moura
ee5ec98fa9 feat(library/init/lean/parser/parser): add symbolNoWs trailing parser 2019-07-05 16:22:36 -07:00
Leonardo de Moura
dca0ba60fa feat(library/init/lean/parser/parser): add fieldIdx parser
We should not use `numLit` for projections since it will parse
`p.1.2` as
```
Term.proj `p (numLit "1.2")
```
2019-07-05 15:07:51 -07:00
Leonardo de Moura
e3c75d2af6 fix(library/init/lean/parser/parser): position information for strLit, numLit, ident 2019-07-05 12:07:37 -07:00
Leonardo de Moura
24f9cd9564 chore(library/init/lean/parser/parser): minor 2019-07-05 11:23:45 -07:00
Leonardo de Moura
70fbf58c50 fix(library/init/lean/parser/parser): bug at identFnAux 2019-07-05 10:46:20 -07:00
Leonardo de Moura
ea6eee516b chore(frontends/lean): use => instead of := in match-expressions
Motivation: use same separator used in lambda expressions as in
other programming languages.
2019-07-04 11:38:38 -07:00
Leonardo de Moura
56007d7c97 feat(library/init/lean/parser/parser): display builtinParser name when updateTokens fails 2019-07-02 16:06:39 -07:00
Leonardo de Moura
a02443d23d chore(frontends/lean): fun x, e ==> fun x => e 2019-07-02 13:22:11 -07:00
Leonardo de Moura
6841e47aa4 chore(frontends/lean/builtin_exprs): remove support for (<infix>) and (<infix> <expr>) notations
In Lean 4, we will support the more general

`a + ·` ==> `fun x, a + x`
`· + b` ==> `fun x, x + b`
`· + ·` ==> `fun x y, x + y`
`f · y` ==> `fun x, f a y`
`g · · b` ==> `fun x y, g x y b`
2019-07-02 08:06:06 -07:00
Leonardo de Moura
ee2d3faa63 feat(library/init/lean/parser/parser): change optional p behavior
It ignores error only if `p` does not consume any input. This change
improves the quality of the error messages. The previous behavior can be
obtained by using `optional (try p)`.
2019-07-02 07:52:22 -07:00
Leonardo de Moura
9d50b3ca47 feat(library/init/lean/parser/term): paren parser 2019-07-01 19:44:13 -07:00
Leonardo de Moura
13b5747713 fix(library/init/lean/parser/parser): prattParser 2019-07-01 16:00:58 -07:00
Leonardo de Moura
5691450b5b feat(library/init/lean/parser): term parser skeleton 2019-07-01 15:04:13 -07:00
Leonardo de Moura
24647cb7cb fix(library/init/lean/parser/parser): better representation for many1 Syntax node 2019-06-30 09:02:06 -07:00
Leonardo de Moura
531ef5d700 feat(library/init/lean/parser): universe level parser and bug fixes 2019-06-30 09:02:06 -07:00
Leonardo de Moura
91e1d30cf8 feat(frontends/lean/builtin_exprs): use ; in do-notation 2019-06-27 18:00:43 -07:00