Commit graph

1707 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
d43a65aed0 feat: elaboarate local syntax, infix and notation commands 2020-12-05 08:05:40 -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
9389bca624 feat: elaborate attrKind 2020-12-05 07:40:55 -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
b37213e378 chore: remove workaround 2020-12-04 18:11:53 -08:00
Leonardo de Moura
752578a64c chore: temporary staging workaround 2020-12-04 18:07:09 -08:00
Leonardo de Moura
aad8ea9c76 feat: stable parser names
```
syntax term "+" term : term              -- generates `term_+_`
syntax "[" sepBy(term, ", ") "]"  : term -- generates `term[_,]`
syntax "done" : tactic                   -- generates `tacticDone`
```

cc @Kha
2020-12-04 18:00:51 -08:00
Leonardo de Moura
c2cfbf2cdd chore: remove workaround 2020-12-04 16:22:45 -08:00
Leonardo de Moura
2ef84a1b64 chore: temporary staging workaround
@Kha It seems the new builtin antiquotation notation you added depends
on the array literal notation that is not builtin. I got the following
error after `update-stage0`

```
Lean/PrettyPrinter/Delaborator/Builtins.lean:455:2: error: elaboration function for '_kind.term._@.Init.Data.Array.Basic._hyg.3391' has not been implemented
```

The base name changed from `_kind.term` to `termKind`. I had to change
it because every parser we were defining was in the artificial (sub-)namespace
`_kind` :)
We didn't notive because we didn't have scoped parsers.
2020-12-04 16:22:44 -08:00
Leonardo de Moura
0749cb9fa9 fix: avoid artificial hierarchical name at parser declarations 2020-12-04 16:22:43 -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
a25e6bdd6e refactor: try out antiquotation scopes
current limitations:
* don't work in patterns
* nested antiquotations must be of the form `$id`, not `$(e)`, and at most two of them
* sepBy antiquotation scopes hard-coded to `,`, `;`, `|` (e.g. `$[...],*`)
* unclear whether they can replace the old `$id:kind*` syntax yet

/cc @leodemoura
2020-12-04 19:33:04 +01: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
Sebastian Ullrich
878f32b662 chore: remove obsolete antiquot choice workaround
We now parse antiquotations before calling `longestMatch`.
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
5f5a8010a2 feat: add ScopedEnvExtension 2020-12-03 17:04:16 -08:00
Leonardo de Moura
5064115ff1 feat: trie for hierarchical names 2020-12-03 16:40:00 -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
58dc7a791f refactor: more dynamic quot tests 2020-12-03 18:21:16 +01:00
Sebastian Ullrich
e0016662c6 refactor: test dynmaic quotations
/cc @leodemoura
2020-12-03 18:05:15 +01:00
Sebastian Ullrich
dbf9fc9799 feat: elaborate dynamic quotations 2020-12-03 17:58:30 +01: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
133ecb111b chore: remove workaround 2020-12-02 13:33:45 -08:00
Leonardo de Moura
469de09280 fix: bug at isDefEq
The new test contains a minimal example that triggers the bug.
2020-12-02 13:27:21 -08:00
Leonardo de Moura
3a08dd2771 chore: typo 2020-12-02 13:27:21 -08:00
Sebastian Ullrich
2437b1cea1 fix: support single-file packages 2020-12-02 17:29:01 +01: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
9d304df757 feat: heterogeneous Append experiment
@Kha This one required a bunch of manual fixes. The main issue is that
before we added the string interpolation feature, we created
`MessageData`s using `++` and coercions. For example, given
`(e : Expr)`, we would write
```
let msg : MessageData := "type: " ++ e
```
and rely on the coercions `String -> MessageData` and
`Expr -> MessageData`, and the instance `Append MessageData`.
However, heterogeneous operators "block" the expected type propagation downwards.
This kind of code is obsolete now since we can write a more compact
version using string interpolation
```
let msg := m!"type: {e}"
```
2020-12-01 16:32:41 -08:00
Leonardo de Moura
baabfc13e0 chore: remove occurrences of Append.append 2020-12-01 15:44:03 -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
Leonardo de Moura
d629c76f9e chore: more heterogeneous operators support 2020-12-01 12:39:45 -08:00
Sebastian Ullrich
32618b0398 chore: remove built-in prefix operators
To reappear soon
2020-12-01 11:57:20 -08:00
Sebastian Ullrich
07f25a19db chore: remove obsolete builtin delaborators 2020-12-01 11:57:20 -08:00