Commit graph

61 commits

Author SHA1 Message Date
Leonardo de Moura
2563d03ae2 feat: add notFollowedBy 2020-08-31 15:37:41 -07:00
Sebastian Ullrich
a6d29dbf9e fix: lookahead.parenthesizer 2020-08-31 14:24:31 +02:00
Leonardo de Moura
3a9cfeb9fb fix: lookahead.formatter 2020-08-30 08:37:51 -07:00
Leonardo de Moura
5ffbada3df feat: add Lean.MonadEnv, Lean.MonadError, and Lean.MonadOptions
This is the first set of polymorphic methods. I will add more later,
and keep reducing code duplication.

cc @Kha
2020-08-22 16:00:43 -07:00
Leonardo de Moura
003966a9e9 refactor: simpler monad stack for FormatterM and ParenthesizerM
Motivation: make sure the code base is more uniform and will simplify
other code reorgs we want to do.

cc @Kha
2020-08-22 13:30:20 -07:00
Leonardo de Moura
916b395d1b chore: cleanup 2020-08-21 09:29:09 -07:00
Sebastian Ullrich
14211cc932 refactor: more core 2020-08-21 15:51:37 +02:00
Sebastian Ullrich
786d90ac80 refactor: move parenthesizer and formatter into CoreM
/cc @leodemoura
2020-08-21 14:23:58 +02:00
Sebastian Ullrich
7a44ba7bdd fix: pretty printer knot arity 2020-08-21 10:27:43 +02:00
Leonardo de Moura
05a0e7f6d0 refactor: build all main monads on top of ECoreM 2020-08-20 18:36:04 -07:00
Sebastian Ullrich
ea266e48ab feat: unicodeSymbol.formatter: prefer symbol used in syntax tree 2020-08-20 18:57:08 +02:00
Sebastian Ullrich
95742ca17b fix: parenthesizer: take minimum of successive precedence checks for contPrec as well
Otherwise, we would parenthesize `1 + 2 + 3` as `(1 + 2) + 3` since in
```
@[builtinTermParser] def add   := tparser! infixL " + "  65
```
there is an additional `checkPrec 1024` implied by `tparser!`. Now `contPrec` of this parser is (min 1024 65 = 65).
2020-08-20 18:36:04 +02:00
Sebastian Ullrich
c2fbb3d307 fix: parenthesizer: parenthesize only because of subsequent parser if in same syntax category
Otherwise, we would parenthesize `... : α → β := ...` as `... : (α → β) := ...` since in
```
def declValSimple    := parser! " := " >> termParser
```
there is an implicit `checkPrec 1024` from `parser!`.
2020-08-20 18:36:04 +02:00
Sebastian Ullrich
4f5d1cf369 chore: finish formatter refactoring 2020-08-20 15:47:43 +02:00
Sebastian Ullrich
aa452b795d refactor: make formatter precompiled as well 2020-08-20 15:29:33 +02:00
Sebastian Ullrich
68b9a8e1d1 refactor: move parenthesizer compiler into separate file, generalize 2020-08-20 13:22:57 +02:00
Sebastian Ullrich
9fa6795a73 feat: add [combinatorFormatter] attribute 2020-08-20 11:21:01 +02:00
Sebastian Ullrich
1840b4b1ff fix: pretty printer with new syntax 2020-08-19 09:56:23 -07:00
Sebastian Ullrich
ed7edf5661 feat: add checkInsideQuot/checkOutsideQuot/toggleInsideQuot parsers
One use case is to obtain fine-grained control over at what stage changed syntax is activated
2020-08-19 09:56:23 -07:00
Leonardo de Moura
5605735137 feat: remove outparam from MonadState
We add helper classes with `outParam`.

@Kha This is similar to the `MonadExceptOf` modification.
Motivation: the new `StateRefT` (state monad implemented using
`IO.Ref`) makes is it quite cheap to have multiple states on the
stack. But, we need a mechanism for accessing the different states in
a convenient way.
Note that, I did not add a `MonadStateOf` class, but helper classes
such as `HasGet` which uses `outParam`. I will do the same for `MonadExcept`.

Summary:
- `get` gets the state on the top of the Monad stack
- `getThe σ` gets the state with type `σ`
- `modify f` modifies the state on the top of the Monad stack.
   We use `modify fun s => { s with ... }` quite often, and we cannot
   infer type of `s` here.
- `modifyThe σ f` allows us to select which state on the stack we are modifying.
- I didn't add `setThe`, since we usually can infer the state type at
  `set s`. In the whole codebase, we have only one instance where this
  is not true.
2020-08-18 15:15:31 -07:00
Sebastian Ullrich
eeaf20080c refactor: register parenthesizer compiler as hook
/cc @leodemoura
2020-08-18 16:02:33 +02:00
Leonardo de Moura
d85a41a4d7 chore: reduce number of dependencies
@Kha Please try to avoid importing `Lean.Meta`, it is huge, and any
change there was forcing a bunch of files to be recompiled since
`Parser.Extension` depends on `Parenthesizer`
2020-08-14 10:59:00 -07:00
Sebastian Ullrich
0df6445be6 fix: relax [builtinParenthesizer] check 2020-08-14 19:05:02 +02:00
Sebastian Ullrich
92162ffb7f feat: check parenthesizer attribute arguments 2020-08-14 19:05:02 +02:00
Sebastian Ullrich
72310a4aee fix: parenthesizer: ParserDescr.parsers should not be assumed to be a registered parser, or even one with a kind 2020-08-14 19:05:02 +02:00
Sebastian Ullrich
64631609cc feat: use [categoryParenthesizer] to parenthesize syntax parsers correctly 2020-08-14 14:42:44 +02:00
Sebastian Ullrich
09c70320ef feat: add [categoryParenthesizer] 2020-08-14 11:00:18 +02:00
Sebastian Ullrich
46f5670ba3 chore: Lean.Parser.Parser ~> Lean.Parser.Basic 2020-08-13 18:44:13 +02:00
Sebastian Ullrich
a0f825f67f refactor: move Lean.PrettyPrinter.Parenthesizer in between Lean.Parser.Parser and Lean.Parser.Extension 2020-08-13 18:44:13 +02:00
Leonardo de Moura
d7add53229 feat: add MonadExceptCore 2020-08-13 09:19:26 -07:00
Sebastian Ullrich
541d77da8b refactor: custom implementation for [combinatorParenthesizer], revert KeyedDeclsAttribute changes
/cc @leodemoura
2020-08-13 15:32:16 +02:00
Sebastian Ullrich
61a706d8cd chore: adjust parenthesizer docs
/cc @leodemoura
2020-08-13 12:27:25 +02:00
Sebastian Ullrich
aefe710caf feat: close the loop 2020-08-12 09:15:59 -07:00
Sebastian Ullrich
f4e59070c4 feat: support interpreting parenthesizers from ParserDescr 2020-08-12 09:15:59 -07:00
Sebastian Ullrich
1f4cc130b7 feat: precompile parenthesizers instead of interpreting them 2020-08-12 09:15:59 -07:00
Sebastian Ullrich
60e548bf7b feat: add [combinatorParenthesizer] attribute 2020-08-12 09:15:59 -07:00
Leonardo de Moura
f934a86646 feat: add (ref : Syntax) to Meta.Exception.other
@Kha The Syntax is here just to provide possition information. The
goal is to improve error message location information in code such as `DepElim`.
2020-08-06 09:40:16 -07:00
Sebastian Ullrich
3f6de2af06 refactor: simplify processing of antiquotations in pretty-printer 2020-08-06 09:27:12 -07:00
Sebastian Ullrich
eded953022 feat: formatter: escape identifiers 2020-08-06 09:27:12 -07:00
Sebastian Ullrich
093f0553e7 chore: add formatter module docstring 2020-08-06 09:27:12 -07:00
Sebastian Ullrich
75b41af122 fix: formatter: further fixes 2020-08-06 09:27:12 -07:00
Sebastian Ullrich
5f4d991a17 fix: formatter: backtracking on identifiers 2020-08-06 09:27:12 -07:00
Sebastian Ullrich
1d725f7c83 feat: almost activate new pretty printer by default 2020-08-06 09:27:12 -07:00
Sebastian Ullrich
e8ca2e3f62 feat: formatter: push space at checkWsBefore 2020-08-06 09:27:12 -07:00
Sebastian Ullrich
07928f301f feat: formatter: separate tokens where necessary 2020-08-06 09:27:12 -07:00
Sebastian Ullrich
33a963d82b refactor: make formatter stack-based, much like the parser 2020-08-06 09:27:12 -07:00
Sebastian Ullrich
37d890b950 fix: atoms might need backtracking as well, e.g. in fieldIdx <|> ident 2020-08-06 09:27:12 -07:00
Sebastian Ullrich
c9d6636eae feat: first, trivial formatter implementation
No actual token separation yet
2020-08-06 09:27:12 -07:00
Sebastian Ullrich
b6b5f4c9c9 refactor: move whnf-eval functions into Lean.Meta.ReduceEval 2020-08-06 09:27:12 -07:00
Sebastian Ullrich
1ceadd9f3d feat: add [formatter] attribute 2020-07-29 18:02:57 +02:00