Commit graph

13374 commits

Author SHA1 Message Date
Leonardo de Moura
36bddc91cb chore: remove checkWsBeforeIfSymbol hack
Now the `app` parsing rule always require some whitespace before the
first argument.

cc @Kha
2020-06-11 14:58:29 -07:00
Leonardo de Moura
f0ebf426b7 chore: longestMatchFn parsers must produce exactly one Syntax node
Before this commit, we were handling the following two abnormal cases:

1- `p` did not produce any `Syntax` node. `runLongestMatchParser`
would insert a `Syntax.missing`.

2- `p` produced more than one `Syntax` node on the
stack. `runLongestMatchParser` would combine all of them using a
`nullKind` node.

This feature was never used since we only use `longestMatchFn` to
process leading and trailing parsers. In both case, we create a node.
Moreover, if a bad parser is manually created, I think it is better to
fail than accept using `Syntax.missing` or a `nullKind` node. We would
only be postponing the problem since we don't have elaboration
functions for them.

cc @Kha
2020-06-11 12:38:55 -07:00
Leonardo de Moura
8e4dc5bcf6 fix: longestMatchFn
Several combinators (e.g., `checkNoWsBefore`) access the "leading
term" by retrieving the element on the top of the syntax stack.
However, the `longestMatchFn` was accumulating successful matches on
the syntax stack too. This commit makes sure the `longestMatchFn`
always push the "leading term" before trying a parser.

This commit also eliminates the `orelseFn` hack at `trailingLoopStep`.
Now, we use `longestMatchFn` for all parsers. Note that we have to add
a new combinator (`checkWsBeforeIfSymbol`) to make sure that `a[i]`
cannot be parsed by the `app` parsing rule.
Before removing the hack from `trailingLoopStep`,
`a[i]` was correctly parsed as an `arrayRef`. After the change,
the `app` parser is tried and it succeeds (IF we don't use
`checkWsBeforeIfSymbol`). It is an application using the list literal
`[i]`.
The `checkWsBeforeIfSymbol` ensures that `a[i]` is not a valid `app`.

cc @Kha
2020-06-11 12:21:16 -07:00
Leonardo de Moura
77ce102baf chore: use notationItem to remove $noprec* hack 2020-06-10 16:59:44 -07:00
Leonardo de Moura
de0a2fefa0 feat: add notationItem 2020-06-10 16:54:46 -07:00
Leonardo de Moura
610ced2de5 chore: appPrec => maxPrec 2020-06-10 16:50:09 -07:00
Leonardo de Moura
f838b80e03 fix: elaboration functions for parser! and tparser! 2020-06-10 16:42:42 -07:00
Leonardo de Moura
7269a721ff fix: parser! and tparser! syntax in the new frontend 2020-06-10 16:20:48 -07:00
Leonardo de Moura
1307405300 chore: make sure parser! and tparser! use a syntax similar to the one used at syntax for setting precedences
cc @Kha
2020-06-10 16:09:13 -07:00
Leonardo de Moura
243cda497e chore: remove leadingNodePrec and trailingNodePrec 2020-06-10 15:07:41 -07:00
Leonardo de Moura
cdc2dbe28d chore: use leadingNode and trailingNode in the old frontend 2020-06-10 15:05:22 -07:00
Leonardo de Moura
1c09e63a29 chore: update trailingNode and leadingNode API 2020-06-10 15:02:12 -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
2125687d9c chore: remove unnecessary [appPrec] annotations 2020-06-10 14:44:54 -07:00
Leonardo de Moura
ca018d561e chore: update parser! and tparser! macros in the old frontend 2020-06-10 14:39:33 -07:00
Leonardo de Moura
77e1260ed2 chore: simplify checkPrec 2020-06-10 14:34:58 -07:00
Leonardo de Moura
6d3aff97d5 chore: lbp and rbp ==> prec 2020-06-10 13:41:10 -07:00
Leonardo de Moura
f0a9e54a69 chore: make sure leading and trailing parsers use the same kind of check 2020-06-10 13:41:10 -07:00
Sebastian Ullrich
6019c30a37 chore: remove obsolete MinGW-specific flag 2020-06-10 21:30:38 +02:00
Sebastian Ullrich
40463a3ab8 chore: building static executables is hopeless, do mostly static instead 2020-06-10 21:30:38 +02:00
Leonardo de Moura
f23780a334 chore: add hack for allowing old and new frontends to parse Core.lean 2020-06-09 14:11:34 -07:00
Leonardo de Moura
e62e30ad0f chore: remove whitespace 2020-06-09 14:11:34 -07:00
Leonardo de Moura
85320d9cf0 chore: add support for old syntax 2020-06-09 14:11:34 -07:00
Leonardo de Moura
7ec23f9401 fix: macro command syntax 2020-06-09 14:11:34 -07:00
Leonardo de Moura
a4f19aac32 fix: macro command 2020-06-09 14:11:34 -07:00
Leonardo de Moura
7fce8b5d1f fix: notation command
@Kha Note that I had to write the weird pattern

```
match_syntax stx with
| `(notation:$prec $items* => $rhs)    => expandNotationAux stx prec items rhs
| `(notation $noprec* $items* => $rhs) => expandNotationAux stx none items rhs
| _ => Macro.throwUnsupported
```

with the weird `$noprec*` to match the case where the optional
precedence is not provided. I realized this is not a bug, but
I guess most users will be puzzled by this behavior. If we had a kind
for `notationItem`, I would be able to write
```
`(notation $items:notationItems* => $rhs)
```
2020-06-09 14:11:34 -07:00
Sebastian Ullrich
a78ceb8121 fix: parenthesizer 2020-06-09 11:26:00 +02:00
Sebastian Ullrich
c8ee21747b chore: remove obsolete symbolAux, symbolNoWsAux 2020-06-09 10:37:00 +02:00
Leonardo de Moura
aa49b3cdb1 feat: elaborate new syntax command 2020-06-08 16:12:06 -07:00
Leonardo de Moura
8972c7e666 feat: revised syntax commands 2020-06-08 16:12:06 -07:00
Leonardo de Moura
d2c2d95c47 chore: remove symbolAux 2020-06-08 16:12:06 -07:00
Leonardo de Moura
dd1aa2f271 chore: improve error message
cc @Kha
2020-06-08 16:12:05 -07:00
Leonardo de Moura
c6ea675cae chore: fix test
@Kha The error message changed. Not sure the new one is expected. It
is due to the change in `trailingLoop`. We can discuss it in the next
meeting.
2020-06-08 16:12:05 -07:00
Leonardo de Moura
400aa435f3 fix: add missing precedence to liftMethod and remove unnecessary precedence from doLet 2020-06-08 16:12:05 -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
906e1b9d91 fix: reset should only be performed at trailingLoop 2020-06-08 16:12:05 -07:00
Leonardo de Moura
5f1831812a chore: missing [inline]s and typo 2020-06-08 16:12:05 -07:00
Leonardo de Moura
5765a1160d fix: Parser ==> TrailingParser 2020-06-08 16:12:05 -07:00
Leonardo de Moura
fa2e943c27 fix tokenFnAux 2020-06-08 16:12:05 -07:00
Leonardo de Moura
8dde9715a9 refactor: associate precedences to parsers instead of tokens
@Kha This is working in progress.
I am convinced we should associated the precedence to parsers. A lot
of weird stuff is gone :)
2020-06-08 16:12:05 -07:00
Leonardo de Moura
52c7709cb3 fix: longestMatch at trailing parsers
Before this commit, if we execut `longestMatch [p1, p2]` in a
trailing parser where both `p1` and `p2` succeed, then an incorrect
syntax tree is generated by `p2`. The issue is that before executing
`p2`, the trailing stack is of the form
`#[..., left, syntax-by-p1]`
Then, the trailing parser `p2` incorrectly assumes that `syntax-by-p1`
was the "left" syntax node.
This commit fix this issue by storing the `left` node at the
`ParserContext` at `trailingLoop`

@Kha This bug was introduced when we unified leading and trailing
parsers. I think this is the simplest solution.
We can observe the bug before this commit by using
```
set_option syntaxMaxDepth 1000
set_option trace.Elab true
```
at `choiceMacroRules.lean`.

It is funny the correct result was produced even with the bug.
It was working because the `macro_rules` was matching the
buggy syntax with the nested `syntax-by-p1` there :)
2020-06-08 14:34:50 -07:00
Leonardo de Moura
8b1cb0fcb8 doc: errToSorry field 2020-06-08 14:28:50 -07:00
Leonardo de Moura
62cf913d6a fix: interaction between errToSorry and observing.
@Kha I implemented the solution 1 I described at Zulip.
I also tried to document the issue, and made sure test
`choiceMacroRules` fail if the bug is reintroduced.
2020-06-08 12:37:43 -07:00
Leonardo de Moura
7a323a0c7b feat: allow parser! and tparser! to set the parser precedence 2020-06-03 18:11:13 -07:00
Leonardo de Moura
947369b4ce chore: Parenthesizer issues after removing sortApp
@Kha Could you please double check these modifications.

I added a no-op for `checkRbpLt`. It is used at the `Sort` and `Type`
parsers.
As I described in previous commits, the `checkRBPGreater` comment and
implementation were misleading. It was actually succeeding when the
rbp was less than or equal to the given parameter. So, it was renamed
to `checkRbpLe`. So, is the depArrow parenthesizer ok? I did not check.

I updated the PPRoundtrip.lean.expected.out to make sure the tests
succeed, but we should revise it if there is a problem with the
modifications at Parenthesizer.lean
2020-06-03 15:46:33 -07:00
Leonardo de Moura
5f0dae3fcb fix: elabSort and elabTypeStx 2020-06-03 15:27:09 -07:00
Leonardo de Moura
9a349a913a chore: remove sortApp
@Kha Note that `checkRBPGreater` comment and name were incorrect. It
was actually checking whether the RBP <= lower
2020-06-03 15:18:16 -07:00
Leonardo de Moura
e252446432 doc: cite "Generalizing Monads to Arrows"
cc @Kha
2020-06-01 08:02:32 -07:00
Sebastian Ullrich
c81f4605e3 doc: Parser.lean 2020-06-01 07:53:09 -07:00
Sebastian Ullrich
6614b4d6e3 fix: use exact instead of prefix token match when inheriting precedence
/cc @leodemoura :)
2020-05-28 14:14:52 +02:00