Commit graph

61 commits

Author SHA1 Message Date
Leonardo de Moura
f4aabaecae refactor: move Lean.quote to LeanInit
cc @Kha
2020-09-17 08:15:58 -07:00
Leonardo de Moura
34291e2151 feat: add Name.simpMacroScopes
@Kha We currently have a few macros that create binder names
such as `x`. These macros rely on the hygienic framework. This part is
great. Before this commit we were simply erasing the macro
scopes when creating the actual binders at `Expr.lean`.
The result produced expressions that were hard to debug.
For example, consider the following scenario

1- Macro creates a few binder names using ``x <- `(x)``
2- We create a lambda expression `t` with these binder names.
3- Then, we use `lambdaTelescope t fun xs body => ...`
   Now, if we trace `xs` and `body`, we get `#[x, x, ... x]` and
   we can't distinguish the different `x`s in `body`.
   So, it is really hard to debug anything using the traces.

This commit adds `Name.simpMacroScopes` for simplying "macro scoped"
names. Example: given `x._@.Init.Data.List.Basic._hyg.2.5`, it
produces `x.2.5`. I exported this function, and used it in the old
pretty printer.

I have considered modifying `lambdaTelescope` to make sure it creates
unused names. I think this option is bad because it introduces
overhead, and in a few places we want to preserve the binder names.

I have also considered replacing the `let x := x.eraseMacroScopes` at
`Expr.lean` with `let x := x.simpMacroScopes`. I think this option is
bad since we are destroying scoping information and will not be able
to distiguish which variables have macro scopes when processing
tactics.

Anyway, the solution in this commit is good for this week, but we
should discuss a more permanent solution next week.
2020-09-08 18:22:44 -07:00
Leonardo de Moura
1103806ff4 refactor: HasMonadLift ==> MonadLift 2020-08-25 13:54:41 -07:00
Leonardo de Moura
b672f0820b chore: remove workarounds 2020-08-23 19:56:01 -07:00
Leonardo de Moura
6fc935f6d1 refactor: add MonadNameGenerator 2020-08-23 19:56:01 -07:00
Leonardo de Moura
57ed29e814 revert: panic! changes
@Kha I am reverting this change for now.
I understand that the "default-value" approach is bad for debugging,
and it does not produce good error messages, but at least the frontend
will not "panic" when users add a bad macro.

After we switch to the new frontend, we can have a monadic `getArg`
and `getArgs` in the Elab and Macro monads which produces an
"unexpected syntax" error message. I say we wait for the new frontend
because we will be able to write `(<- s.getArg)` inside of
expressions.
2020-08-19 09:57:58 -07:00
Sebastian Ullrich
4768ac2fbc chore: make Syntax.getArg(s) panic 2020-08-19 09:56:23 -07:00
Sebastian Ullrich
eb5a171764 feat: adjust semantics to new syntax 2020-08-19 09:56:23 -07:00
Leonardo de Moura
3342ba08d2 feat: implement let elaborators without using match_syntax
@Kha I had to do this because of the `ident` vs `Term.id` recurrent
issue. `match_syntax` fails if a `Term.id` is used at `Term.letIdDecl`
where an `ident` is expected.
We should try to remove `Term.id` in the future.
2020-08-17 09:27:54 -07:00
Leonardo de Moura
f1c7665a93 feat: validate patterns, and collect pattern variables 2020-08-11 18:19:29 -07:00
Leonardo de Moura
61f8b4ef07 feat: add support for maximum recursion depth checks at MacroM 2020-08-10 16:50:12 -07:00
Leonardo de Moura
c6e7ea8fd5 feat: add ParserDescr.parser constructor for embedding parser definitions into parser descriptions 2020-06-16 14:06:46 -07:00
Leonardo de Moura
f61e4ffbbd chore: ParserDescr.parser ==> ParserDescr.cat 2020-06-16 13:40:16 -07:00
Leonardo de Moura
1477d23546 feat: remove ParserDescr.prec and update ParserDescr.trailingNode/ParserDescr.node 2020-06-10 14:57:55 -07:00
Leonardo de Moura
8972c7e666 feat: revised syntax commands 2020-06-08 16:12:06 -07:00
Leonardo de Moura
1554f7f99a fix: ParserDescr
This commit also adds the new constructor `ParserDescr.rblLt`
2020-06-08 16:12:05 -07:00
Leonardo de Moura
dbe4aa447e chore: explicit lbp at ParserDescr.symbol 2020-05-27 16:12:53 -07:00
Leonardo de Moura
bd58048449 chore: { <source> with ... } syntax 2020-05-20 15:08:43 -07:00
Sebastian Ullrich
b28eedbd98 refactor: make all fields of SourceInfo optional 2020-05-20 11:54:53 -07:00
Leonardo de Moura
33a10130cf chore: fix stdlib 2020-05-12 15:02:03 -07:00
Sebastian Ullrich
b6fc9428f1 fix: support Windows newlines and '\r' escape 2020-03-27 13:21:21 -07:00
Leonardo de Moura
0c13445da6 fix: mkStructView
Reamrk: `1.2` is a numLit
2020-02-18 20:22:04 -08:00
Sebastian Ullrich
25f764daad feat: antiquotation escapes 2020-02-18 10:57:12 -08:00
Leonardo de Moura
da3bf54ec7 feat: elaborate autoParams
cc @Kha
2020-02-13 16:24:50 -08:00
Leonardo de Moura
44817b8488 feat: autoParam takes the Name of an auxiliary declaration of type Syntax
@Kha The `Name` (tactic name) approach used in Lean3 is not suitable
for Lean4. The issue is that we define tactics using macros, and in
most cases, the user doesn't even know the node id.
2020-02-13 15:09:42 -08:00
Leonardo de Moura
4fe0104b52 feat: add autoParam 2020-02-13 10:53:01 -08:00
Leonardo de Moura
f0e3cf449f fix: unhygienic method 2020-02-11 21:15:05 -08:00
Leonardo de Moura
3f4c27efa5 feat: add getFieldViews 2020-02-05 19:15:05 -08:00
Leonardo de Moura
ca919c2021 refactor: move instance to LeanInit 2020-02-01 00:52:52 -08:00
Leonardo de Moura
3dfc93550a feat: add liftMacroM
We implement `expandDoElems` using `MacroM`.
2020-02-01 00:26:42 -08:00
Leonardo de Moura
b332d5e74d feat: add proper withFreshMacroScope to MacroM
This is useful, for example, for users that want to write recursive
procedural macros.
2020-02-01 00:12:13 -08:00
Leonardo de Moura
21618361b7 refactor: remove ParserKind 2020-01-30 20:56:46 -08:00
Leonardo de Moura
31ebccea58 chore: remove ParserDescr.pushLeading 2020-01-30 19:04:07 -08:00
Leonardo de Moura
410d295429 refactor: remove unnecessary pushLeading, add ParserDescr.trailingNode 2020-01-30 18:32:28 -08:00
Leonardo de Moura
145bd50903 feat: disallow patterns with choice nodes
@Kha Patterns with nested "choice" nodes produce counterintuitive
behavior, and hard to understand errors. They only work when we have
the exact same overloads at macro definition and application time.

Here is a funky example
```
syntax [myAdd] term "++":65 term:65 : term    -- overloads "++"
/- The following `macro_rules` manages to eliminate "choice" node by using the
   explicitly provided node kind. -/
macro_rules [myAdd] `($a ++ $b) => `($a + $b)

check (1:Nat) ++ 2 -- works as expected

syntax "FOO!" term : term

/- Before this commit, the following pattern was accepted,
   and it contained a "choice" node for `++`. It is a `myAdd` or
   `HasAppend.append`.

   Now, this kind of pattern is rejected since it contains a nested
   "choice" -/
macro_rules `(FOO! $a ++ $b) => `($a ++ $b)

/- Before this commit, the following command worked because
   it contained a "choice" node similar to the one at macro definition
   time. -/
check FOO! [1, 2] ++ [2, 3]

-- Now, we have 3 overloads for "++".
syntax [myAppend] term "++":65 term:65 : term

-- The `macro_rules` fails here.
```

This commit fixes this weird behavior by disallowing "choice" nodes in
patterns.
2020-01-26 15:13:14 -08:00
Leonardo de Moura
8525584a78 refactor: naming consistency ensure List and Array have similar find* methods
`find?`     -> takes predicate
`findSome?` -> takes a function (A -> Option B)
2020-01-26 15:13:05 -08:00
Leonardo de Moura
7133d3fc84 feat: handle explicit node kinds in macro_rules, and handle choice kind 2020-01-26 09:39:46 -08:00
Leonardo de Moura
e52c4291cc feat: allow macro_rules block with different syntax node kinds 2020-01-26 08:39:40 -08:00
Leonardo de Moura
7b6caba457 feat: add `ident as a valid elaboration kind 2020-01-25 14:55:32 -08:00
Leonardo de Moura
6d5de9f965 feat: handle raw identifiers as binders in fun
@Kha I am adding this kind of feature to improve the user experience.
For example, the macro
```
syntax "[" ident "↦" term "]" : term
macro_rules
| `([$x ↦ $v]) => `(fun $x => $v)
```
is accepted and looks perfectly reasonable.
However, before this commit, we would get a nasty error when
elaborating
```lean
check [x ↦ x + 1]
```
2020-01-25 14:55:21 -08:00
Leonardo de Moura
aa045f3b07 feat: safer mkCIdentFrom
cc @Kha
2020-01-24 17:23:21 -08:00
Leonardo de Moura
364bb7bdf7 fix: proper Name literals
cc @kha
2020-01-24 12:38:15 -08:00
Leonardo de Moura
060a68d73f feat: remove addMacroScope approximation 2020-01-23 14:59:31 -08:00
Leonardo de Moura
ed6cb007d0 refactor: ExtractMacroScopesResult => MacroScopesView, add MacroScopesView.review 2020-01-23 14:11:32 -08:00
Leonardo de Moura
b47caaa0a5 refactor: notation and macro commands are now just macros 2020-01-23 13:04:21 -08:00
Leonardo de Moura
d99ef11447 fix: nested addMacroScope 2020-01-23 12:36:37 -08:00
Leonardo de Moura
e681bd71d9 feat: simplify MacroM 2020-01-23 12:22:33 -08:00
Leonardo de Moura
0228f9c9b7 chore: remove addMacroScopeExt 2020-01-23 12:08:20 -08:00
Leonardo de Moura
6fdcb1c192 chore: prepare to remove addMacroScopeExt 2020-01-23 12:02:45 -08:00
Leonardo de Moura
fab256d4cc feat: improve macroscope encoding 2020-01-23 11:33:35 -08:00