Commit graph

405 commits

Author SHA1 Message Date
Leonardo de Moura
d27770ea0e chore: prepare to add scoped and local instances 2020-12-05 15:36:23 -08:00
Leonardo de Moura
1faed06dc1 feat: new attrKind syntax 2020-12-05 13:59:08 -08:00
Leonardo de Moura
f1f8c2482f feat: prepare to change attrKind parser
We want to add a proper node and kind.
2020-12-05 13:49:59 -08:00
Leonardo de Moura
32d5ef8b78 feat: scoped and local unification hints 2020-12-05 13:49:36 -08:00
Leonardo de Moura
10102bf370 chore: remove "local" before attribute command
`local` is now part of the `Term.attrInstance` parser.
2020-12-05 07:47:28 -08:00
Leonardo de Moura
bcf4ffdd1a feat: local modifier at @[...] 2020-12-05 07:24:55 -08:00
Leonardo de Moura
c6ab0b4d2c feat: allow local modifier at infix, notation, and syntax commands 2020-12-05 07:00:06 -08:00
Leonardo de Moura
4d428c8660 feat: add ScopedEnvExtension.addLocalEntry 2020-12-05 06:54:03 -08:00
Leonardo de Moura
0ab368581a refactor: ScopedEnvExtension
1) `ScopedEnvExtension` module now mananges the push/pop/activate
methods. Motivations:
  - Easier to add attributes
  - One `ScopedEnvExtension` may be shared between multiple
  attributes (e.g., parsers)

2) Add `AttributeKind`
2020-12-04 16:22:43 -08:00
Leonardo de Moura
02e13081a9 feat: implement AttributeImpl scoping methods for parsers 2020-12-04 16:22:43 -08:00
Sebastian Ullrich
04f09cc34f perf: avoid redundant token collections from antiquotation scopes 2020-12-04 22:43:31 +01:00
Leonardo de Moura
5a772c6cae feat: expand scoped notation into scoped attribute modifier 2020-12-04 11:39:00 -08:00
Leonardo de Moura
4d523e3b8c chore: prepare to add optional "scoped" at syntax, infix, and notation commands 2020-12-04 11:20:48 -08:00
Sebastian Ullrich
d7f27a140e feat: antiquotation scopes 2020-12-04 19:24:32 +01:00
Sebastian Ullrich
92cbe27810 refactor: clean up & delay registering parser aliases 2020-12-04 19:24:32 +01:00
Leonardo de Moura
6f1facd07c feat: implement ParserExtension using ScopedEnvExtension 2020-12-04 09:57:35 -08:00
Leonardo de Moura
963b0f1270 feat: scoped attributes cont. 2020-12-03 10:46:09 -08:00
Leonardo de Moura
2408b5c6b5 feat: basic support for scoped attributes 2020-12-03 10:39:59 -08:00
Sebastian Ullrich
80d4ae82e8 feat: arbitrary quotation kinds via name resolution in the parser and execution in the interpreter 2020-12-03 17:46:13 +01:00
Sebastian Ullrich
21f4257da5 feat: name resolution during parsing 2020-12-03 17:46:13 +01:00
Leonardo de Moura
b95c4788c1 refactor: OfDecimal ==> OfScientific
`decimalLit` ==> `scientificLit`
2020-12-03 08:08:19 -08:00
Leonardo de Moura
d1f4d4f57e feat: scientific notation 2020-12-03 07:49:20 -08:00
Leonardo de Moura
85c9ab072c feat: elaborate and delaborate decimals 2020-12-02 15:31:06 -08:00
Leonardo de Moura
facb28d080 feat: basic support for decimal numbers 2020-12-02 14:54:59 -08:00
Leonardo de Moura
c476954eef feat: heterogeneous OrElse and AndThen
@Kha I had a few issues similar to the `Append` issues.
We used a similar idiom for writing builtin parsers where we may write
```
def p : Parser := "foo " >> "bla "
```
as a shorthand for
```
def p : Parser := symbol "foo " >> symbol "bla "
```
I want to support `builtin syntax` one day :)

That being said, we should decide whether we keep `HAppend`, `HOrElse`,
and `HAndThen` or not.
The only one I wish I had in the past is `HAndThen`.
2020-12-01 18:32:24 -08:00
Leonardo de Moura
2120883307 refactor: heterogeneous operators
@Kha I had some unexpected surprises, but it is a good change.
Here is the summary.

1- We could get rid of `a %ₙ b` and `ModN` class. We can use `HMod`
instead. It was a positive surprise since I didn't remember we had
this `ModN` class.

2- Coercions are never used in heterogeneous operators. This is
expected since `a * b` is now notation for `HMul.hMul a b`, and
`a` and `b` may have different types. I manually added instances such
as `HMul Nat Int Int`. However, I did not try to add generic instances
such as
```
instance [Coe a b] [Mul b] : HMul a b b where
  hMul x y := mul (coe x) y
```
I will try later.

3- Give `h : cs.size > 0`, I got a type error at
```
let idx : Fin cs.size := ⟨cs.size - 1, Nat.predLt h⟩
```
`Nat.predLt h` has type `Nat.pred cs.size < cs.size`
However, `Nat.pred cs.size` doesn't unify with `cs.size - 1`.
The problem is that we can't synthesize the `HSub` instance until
we apply the default instances.
It worked before because `isDefEq` would force the pending TC
problem `Sub Nat` to be resolved, and after that we would be able
to reduce `cs.size - 1` and establish that it is definitionally
equal to `Nat.pred cs.size`.
I considered two possible workarounds
a) `let idx : Fin cs.size := ⟨cs.size - (1:Nat), Nat.predLt h⟩`
b) `let idx : Fin cs.size := ⟨cs.size - 1, by exact Nat.predLt h⟩`
The first one works because we are not providing enough information
for synthesizing the `HSub` instance. The second works because it
postpones the elaboration of `Nat.predLt h`. The default instances
will be applied before we start applying tactics.

4- The `.` notation is affected too. For example, `(x + 1).toUInt8`
doesn't work since we don't know the type of `x+1` until we apply
default instances. I fixed it by using `(x + (1:Nat)).toUInt8`.
Another possible fix is `Nat.toUInt8 (x + 1)`.
Similarly, `(x+1).fold ...` doesn't work.

5- The following code failed to be elaborated
```
indent (push s!"{ss'}\n") (some (0 - Format.getIndent (← getOptions)))
```
It was working before, but it relied on how the expected type is
propagated. The elaborator process
```
some (0 - Format.getIndent (← getOptions))
```
with expected type `(Option Int)`. So, the `-` is interpreted as
`Int.sub` although `Format.getIndent (← getOptions)` has type `Nat`.
In the new `HSub`, the expected type doesn't really influence TC
resolution since it is an `outparam`. So, we failed with the error
failed to synthesize `HSub Nat Nat Int`.
One possible fix was to add the instance `HSub Nat Nat Int` with
`Int.sub`, but I used the following fix
```
some ((0 : Int) - Format.getIndent (← getOptions))
```
which makes it clear that we want the `Int.sub` operator instead of
`Nat.sub`.
2020-12-01 14:02:46 -08:00
Sebastian Ullrich
32618b0398 chore: remove built-in prefix operators
To reappear soon
2020-12-01 11:57:20 -08:00
Leonardo de Moura
e9069b6965 feat: expand optional priority at notation and mixfix commands 2020-11-29 08:22:47 -08:00
Leonardo de Moura
ee5679c77c chore: prepare to add optional priorities to the notation and mixfix commands 2020-11-29 08:05:26 -08:00
Sebastian Ullrich
3c86f79bad fix: one instance of parenthesizer "visiting a syntax tree without precedences" 2020-11-28 12:37:35 +01:00
Leonardo de Moura
3d3bed56fd feat: add alias bracketedBinder 2020-11-27 19:01:26 -08:00
Leonardo de Moura
0869f38de4 chore: update structure, class, inductive 2020-11-27 15:09:30 -08:00
Leonardo de Moura
2909313475 fix: doLetArrow and doReassignArrow
@Kha the new tests did not work without this fix.
The `| _ =>` was being parsed as part of the `doLetArrow` and `doReassignArrow`
2020-11-26 10:29:08 -08:00
Leonardo de Moura
43d98ef7e3 fix: Term/Sort parsers
missing `checkColGt`
2020-11-26 09:34:32 -08:00
Leonardo de Moura
d6f778bec4 refactor: arbitrary without explicit arguments
@Kha I was tired of writing `arbitrary _` :)
There 0 places in the stdlib where the type needs to be provided.
If in the future we need to specify the type we can use
`arbitrary (α := <type>)`
2020-11-25 09:07:38 -08:00
Sebastian Ullrich
375e6232e0 chore: introduce doSeqItem kind 2020-11-25 12:10:49 +01:00
Sebastian Ullrich
bd7bb6f5b5 fix: do formatting 2020-11-25 11:30:24 +01:00
Leonardo de Moura
5585f9823f chore: cleaner structure/class syntax
@Kha I implemented the syntax for structure/class that we discussed this morning.
It is much cleaner. See new tests at `struct2.lean`.
I updated the documentation to use it.
2020-11-24 13:07:43 -08:00
Leonardo de Moura
5884b9c19a feat: add support for instance ... where
@Kha The fields are not mutually recursive yet, but it is good enough
 for writing examples in the manual.

See new test
2020-11-23 18:07:02 -08:00
Leonardo de Moura
ac85650e0a feat: add optional where clause at declarations
closes #191

@Kha Note that it expands into a "let rec".
There are many other places where an optional `where`-clause is
useful. We can add them later. It is relatively easy to add support in
other places using the new helper functions
`expandWhereDeclsOpt` and `expandMatchAltsWhereDecls`
2020-11-23 12:04:51 -08:00
Leonardo de Moura
3f27d7318e chore: prepare to add where clause to declarations 2020-11-23 10:41:12 -08:00
Leonardo de Moura
c7a31ed52e chore: remove duplicate instances 2020-11-21 11:05:52 -08:00
Leonardo de Moura
fcbd72f2af feat: optional , at structure instances 2020-11-20 15:24:34 -08:00
Leonardo de Moura
27e26998d2 chore: prepare to change structInst syntax 2020-11-20 13:57:52 -08:00
Leonardo de Moura
8a59fe5b52 feat: add ASCII version for · 2020-11-19 09:17:08 -08:00
Leonardo de Moura
d7d53bf3a8 chore: remove builtin $
We will define it at `Notation.lean`
2020-11-19 09:04:41 -08:00
Leonardo de Moura
b6a1914299 chore: remove $. notation
It has been replaced by `|>.`
2020-11-19 08:47:35 -08:00
Leonardo de Moura
91b3e3e318 feat: add pipe proj notation
We will delete `dollarProj`
2020-11-19 08:14:29 -08:00
Leonardo de Moura
c305c2691f chore: use := 2020-11-19 07:22:31 -08:00
Leonardo de Moura
0fcf6217ec feat: optional := before constructors in the inductive command
@Kha In the documentation, I will always use `:=`. The idea is to
avoid the issue: why does `structure` have a `:=` but `inductive`
doesn't.
2020-11-19 06:43:14 -08:00