Commit graph

10 commits

Author SHA1 Message Date
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
7a323a0c7b feat: allow parser! and tparser! to set the parser precedence 2020-06-03 18:11:13 -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
Leonardo de Moura
5dffa0093a feat: retrieve implicit lbp from Environment at syntax command
@Kha It is not clear to me why I had to change the following line
```
-syntax term ">>>" term : foo
+syntax term:1 ">>>":1 term : foo
```
The test breaks without it.
2020-05-27 17:11:57 -07:00
Leonardo de Moura
dbe4aa447e chore: explicit lbp at ParserDescr.symbol 2020-05-27 16:12:53 -07:00
Leonardo de Moura
6e5cd5fcc0 chore: change coercion from String to Parser
@Kha
I kept `TokenInfo` as is. That is, the `lbp` field is still `Option Nat`.
I changed my mind because we have the combinator `NonReservedSymbol`.
It feels weird to have a combinator that does not create a keyword,
but sets the `lbp`. Recall that it is used at `Lean/Parser/Tactic.lean`.

Other observations:

- We use symbols in auxiliary constructions (e.g., `mkAntiquot`). It
feels weird to set their `lbp` there.

- It felt weird to specify the `lbp` in places such as
```
def structCtor := parser! ident >> optional inferMod >> symbol " :: " 67
```

- We have a few parsing rules where the same symbol appears twice.
It is funny to set the `lbp` twice. Note that the approach we
discussed yesterday (retrieving the `lbp` from the `Environment`)
would not work here.
2020-05-27 15:59:12 -07:00
Leonardo de Moura
4ccc3fef52 chore: move Init.Lean files to Lean package 2020-05-26 15:04:35 -07:00
Renamed from src/Init/Lean/Parser/Parser.lean (Browse further)