Commit graph

34 commits

Author SHA1 Message Date
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
Leonardo de Moura
87d002bb43 feat: extend MacroM
It now has access to `mainModule` and a name generator.
2020-01-23 09:48:37 -08:00
Leonardo de Moura
98ee6e9734 refactor: move NameGenerator to LeanInit 2020-01-23 08:49:58 -08:00
Leonardo de Moura
a7a36f80bb feat: add termIdToAntiquot 2020-01-22 13:18:09 -08:00
Leonardo de Moura
5193ce45e4 refactor: move Syntax helper functions to LeanInit 2020-01-22 12:58:06 -08:00
Leonardo de Moura
6f9f581566 feat: add Syntax.identToAtom 2020-01-21 13:25:20 -08:00
Leonardo de Moura
e57d3431ee refactor: move basic Syntax API to LeanInit
We want to make them available for `macro`-building
2020-01-19 14:44:03 -08:00
Leonardo de Moura
60a9aa52c5 feat: add Array.getSepElems
cc @Kha
2020-01-18 19:12:44 -08:00
Leonardo de Moura
d9c6624a0a feat: add support for trailing syntax 2020-01-15 20:53:23 -08:00
Leonardo de Moura
c5ab63a92b refactor: move MonadQuotation to LeanInit, add MacroM 2020-01-15 20:53:23 -08:00
Leonardo de Moura
99aca85ac7 refactor: move declarations used at macro command to LeanInit 2020-01-15 20:53:23 -08:00
Leonardo de Moura
e0bcd9ac13 refactor: LeanExt => LeanInit 2020-01-15 20:53:23 -08:00
Renamed from src/Init/LeanExt.lean (Browse further)