Commit graph

551 commits

Author SHA1 Message Date
Sebastian Ullrich
8119daeb18 feat: syntax & attribute for double-quoted quotations 2021-04-27 16:38:37 -07:00
Daniel Fabian
0238bf8c33 refactor: use Ordering inside of rbmap instead of lt. 2021-04-27 07:58:58 -07:00
Sebastian Ullrich
53b0e7dde8 fix: ban tabs
Fixes #339
2021-04-25 19:55:15 -07:00
Sebastian Ullrich
01f6cece2f chore: fix parser error message 2021-04-24 21:48:12 +02:00
Sebastian Ullrich
069bcf8933 fix: restore missing invariant 2021-04-24 21:46:48 +02:00
Leonardo de Moura
a076b5b89e feat: improved error recovery for interpolated strings 2021-04-24 10:24:57 -07:00
Leonardo de Moura
09d438ca1d chore: enforce notation parameter naming convention 2021-04-19 18:54:09 -07:00
Sebastian Ullrich
61f39d6088 chore: Parser.atomic: preserve partial output 2021-04-17 23:44:45 +02:00
Sebastian Ullrich
fd42b111fb chore: always push missing on a parser error 2021-04-17 23:44:43 +02:00
Leonardo de Moura
157ef80c5a feat: match auto generalization 2021-04-16 21:48:38 -07:00
Leonardo de Moura
1c23d68c6a feat: add (generalizing := true/false) optional attribute to match 2021-04-15 17:04:25 -07:00
Leonardo de Moura
abf78e162c feat: add notation for disabling implicit lambda feature
This notation will be useful for writing macros where
implicit lambdas are not desired.
2021-04-12 22:33:23 -07:00
Daniel Selsam
d35091da56 feat: parser alias for 'declVal' 2021-04-12 16:59:54 -07:00
Leonardo de Moura
578b3b822f fix: do not use nullKind for group combinator
We use `nullKind` for the `group` parser combinator.
When pattern matching `nullKind` nodes, we check their arities.
So, error recovery often fails for parsers that use the `group`
combinator.
For example, we have the parser
```
def whereDecls := leading_parser "where " >> many1Indent (group (letRecDecl >> optional ";"))
```
If there is syntax error at `letRecDecl`, the node corresponding to
```
group (letRecDecl >> optional ";")
```
will contain only one child, and the pattern matching at
```
def expandWhereDecls (whereDecls : Syntax) (body : Syntax) : MacroM Syntax :=
  match whereDecls with
  | `(whereDecls|where $[$decls:letRecDecl $[;]?]*) => `(let rec $decls:letRecDecl,*; $body)
  | _ => Macro.throwUnsupported
```
fails, and we can't elaborate the partial syntax tree for
`letRecDecl`, and auto-completion will not work there.

We address this issue by using a new kind for the `group` combinator.
The idea is to pattern match `group` as we pattern match `node`s with
proper syntax node kinds. This change is consistent with the way we
use `group` where it mainly a convenience for saving us the trouble of
defining a new parser definition that is used only once.
2021-04-07 22:30:51 -07:00
Leonardo de Moura
2b9df7d8b9 chore: make it clear that implementation relies on the fact that both branches of the if-then-else generate a node with the same kind
Motivation: we want to change the kind used in the `group` combinator.
2021-04-07 22:02:17 -07:00
Leonardo de Moura
6c0f3c277f fix: ignore syntactically incorrect commands that do not contain any symbol
This kind of broken command does not have a position information, and
was producing a panic message in the server because it makes the
reasonable assumption that every command returned by `parserCommand`
has a position.
2021-04-07 14:46:13 -07:00
Leonardo de Moura
0717c3d0b2 chore: adding helper parser completion
I am hitting many error recovery problems. This is an attempt to make
auto-completion more robust.
For example, we currently can't auto complete inside of parentheses.
The syntax tree for the syntactically incorrect tern `(s. , 0)` is
```
(Term.paren "(" [(Term.proj `s ".")])
```
The elaborator for `paren` fails to match this partial syntax tree and
returns an error. I considered adding code to the `else` branch of
this elaborator and handle partial trees there. However, we would
still be losing information for the other elements of the tuple.
Example: no hover information for them.
The helper parser makes sure we don't lose information.
2021-04-05 18:44:01 -07:00
Leonardo de Moura
f13bdd6869 fix: error recovery at sepBy combinator 2021-04-05 18:38:57 -07:00
Leonardo de Moura
fb38955be2 feat: improve command parser error recovery
After a parser error in a command, we are "swallowing" all command
parsing errors until a command was succesfully parsed.
This was producing counterintuitive behavior in the IDEs.
2021-04-05 12:31:33 -07:00
Leonardo de Moura
d6af843683 chore: remove completion auxiliary parser 2021-04-05 11:26:13 -07:00
Leonardo de Moura
e6dec2dd79 feat: don't allow whitespaces between . and field name 2021-04-05 07:11:14 -07:00
Sebastian Ullrich
98e1baabbd refactor: make trailingNode clean up after itself
Also resolves an issue with emitting both `left` and a partial tree
containing it
2021-04-05 13:51:03 +02:00
Sebastian Ullrich
6dc3e55c54 fix: longestMatchFn: do not discard partial syntax tree of first overload 2021-04-05 10:00:47 +02:00
Sebastian Ullrich
e5be9e7dd4 chore: helpers for parser debugging 2021-04-05 10:00:47 +02:00
Sebastian Ullrich
d0996fb945 chore: improve EOI error message 2021-04-03 11:56:26 +02:00
Leonardo de Moura
caae7952cd feat: add helper parsers for auto-completion 2021-04-01 23:31:38 -07:00
Sebastian Ullrich
7bb3d10014 chore: ensure that a failing node parser creates at least one missing 2021-04-01 17:24:50 +02:00
Leonardo de Moura
2837873db5 fix: longestMatch error recovery
@kha When replacing an error with a longer one, we were keeping the
message for the longer error, but losing its node.
2021-03-31 20:09:36 -07:00
Leonardo de Moura
2fc775954c fix: error recovery
@kha We have a few parsers that invoke `tokenFn`, and return error
depending of what is on the top of the stack (e.g., `ident`).
These parsers were not restoring the stack size when reporting errord,
and messing up the error recovery. We never notice the problem because
operators such as <|> restore the stack size, and we were not trying
to elaborate syntacticly incorrect terms.
2021-03-31 17:05:34 -07:00
Leonardo de Moura
c35f96ac82 feat: avoid bizarre error message for definition without body
@kha This is a temporary hack to avoid a incomprehensible error
message. I will try to tweak the parser error recovery in another
commit.
2021-03-31 17:05:34 -07:00
Leonardo de Moura
de024274fe feat: elaborate syntactically incorrect commands 2021-03-31 17:05:34 -07:00
Sebastian Ullrich
bbf6c717fc feat: introduce arg precedence 2021-03-22 16:33:37 +01:00
Sebastian Ullrich
725c0c1911 chore: implement lhs prec 2021-03-22 16:33:37 +01:00
Sebastian Ullrich
3d90850fdd feat: add syntax for specifying LHS precedence on trailing parsers 2021-03-22 16:33:36 +01:00
Leonardo de Moura
03e3a1cc6b chore: remove hack
It produces weird error messages in some examples, and it will be
obsolete after the new precedence feature.
2021-03-19 11:09:18 -07:00
Sebastian Ullrich
54405c4543 fix: automatically wrap many/sepBy items in null nodes where necessary 2021-03-19 15:15:55 +01:00
Leonardo de Moura
9daed5e91d chore: add checkLinebreakBefore 2021-03-18 06:43:03 -07:00
Leonardo de Moura
60a1b828ad fix: fixes #348 2021-03-16 17:50:40 -07:00
Sebastian Ullrich
75a97fad94 feat: nicer token parse errors 2021-03-14 08:23:32 -07:00
Sebastian Ullrich
9f21d6fd64 fix: preserve token parse errors 2021-03-14 08:23:32 -07:00
Leonardo de Moura
1df84e3a6d feat: allow haveDecl, sufficesDecl, letRecDecls in antiquotations 2021-03-12 17:40:16 -08:00
Leonardo de Moura
bf8119a5cd chore: convert keywords to snake_case
Again `!` is only for functions that can panic.
2021-03-12 13:34:51 -08:00
Leonardo de Moura
df994fd16f fix: add checkColGe to matchAlt
@Kha this is a fix for the example that @gebner posted on Zulip.
There are other possible workarounds, but I think this one is
"intuitive".

Here is the problem description and workaround.
We currently use the `withPosition` combinator at `matchAlts`. The
original motivation was nested `match`-expressions without
parenthesis.
We also have the `checkColGt` in the application parser.

Thus, `frob 5` is not parsed as an application. That is, the term
parser after the `then` keyword stops at `frob`.
Then, we get the weird "expected 'else'" error message at `5` :)

In this commit, I add a `checkColGe` check at the beginning of each
alternative right-hand-side.

The effect on the stdlib was minimal. It basically affected old code
that used the Lean 3 workaround for partial functions
```
partial def f : N -> N | i =>
  ...
```
In Lean 4, we can use the more natural
```
partial def f (i : N) : N :=
...
```
or
```
partial def f : N -> N := fun i =>
...
```

It also affected code such as
```
instance : Repr String.Iterator where
  reprPrec | ⟨s, pos⟩, prec =>
    Repr.addAppParen ("String.Iterator.mk " ++ reprArg s ++ " " ++ reprArg pos) prec
```
This is a workaround for a missing feature. We really wanted to write
```
instance : Repr String.Iterator where
  reprPrec ⟨s, pos⟩ prec :=
    Repr.addAppParen ("String.Iterator.mk " ++ reprArg s ++ " " ++ reprArg pos) prec
```
2021-03-12 11:06:07 -08:00
Leonardo de Moura
be841a7cad chore: throwError! => throwError, throwErrorAt! => throwErrorAt
@Kha I marked the corresponding methods as `protected`.
I currently can't stand `throw_error`, and I am optimistic about
server highlighting feature you are working on :)
2021-03-11 11:59:45 -08:00
Leonardo de Moura
ffb57e661f chore: remove old notation 2021-03-11 11:24:52 -08:00
Leonardo de Moura
1112ab6eff chore: use new notation 2021-03-11 11:19:33 -08:00
Leonardo de Moura
ca0baf12b6 chore: avoid ! suffix in builtin notation 2021-03-11 10:58:06 -08:00
Leonardo de Moura
5049d92968 chore: remove let! and let* notation 2021-03-11 10:42:50 -08:00
Leonardo de Moura
a97bdd6a67 chore: add let_delayed and let_fun notation
They will replace `let*` and `let!`
2021-03-11 10:31:04 -08:00
Leonardo de Moura
164577d94e chore: remove parser! and tparser!
The new macros are called "leading_parser` and `trailing_parser`.

cc @Kha
2021-03-11 09:36:58 -08:00