mirror of
https://github.com/unisonweb/unison.git
synced 2024-08-15 13:30:27 +03:00
Update transcripts
This commit is contained in:
parent
19b8131777
commit
3d95906195
@ -1524,7 +1524,7 @@ renderParseErrors s = \case
|
||||
Nothing -> []
|
||||
Just ts -> rangeForToken <$> Foldable.toList ts
|
||||
excerpt = showSource s ((\r -> (r, ErrorSite)) <$> ranges)
|
||||
msg = L.formatTrivialError _ unexpectedTokenStrs expectedTokenStrs
|
||||
msg = L.formatTrivialError unexpectedTokenStrs expectedTokenStrs
|
||||
in [ ( Pr.lines
|
||||
[ "I got confused here:",
|
||||
"",
|
||||
|
@ -210,10 +210,16 @@ foo = match 1 with
|
||||
|
||||
Loading changes detected in scratch.u.
|
||||
|
||||
offset=8:
|
||||
unexpected <outdent>
|
||||
expecting ",", case match, or pattern guard
|
||||
I got confused here:
|
||||
|
||||
3 |
|
||||
|
||||
I was surprised to find an end of section here.
|
||||
I was hoping for one of these instead:
|
||||
|
||||
* ","
|
||||
* case match
|
||||
* pattern guard
|
||||
|
||||
```
|
||||
```unison
|
||||
@ -250,10 +256,19 @@ x = match Some a with
|
||||
|
||||
Loading changes detected in scratch.u.
|
||||
|
||||
offset=16:
|
||||
unexpected <outdent>
|
||||
expecting ",", blank, case match, false, pattern guard, or true
|
||||
I got confused here:
|
||||
|
||||
7 |
|
||||
|
||||
I was surprised to find an end of section here.
|
||||
I was hoping for one of these instead:
|
||||
|
||||
* ","
|
||||
* blank
|
||||
* case match
|
||||
* false
|
||||
* pattern guard
|
||||
* true
|
||||
|
||||
```
|
||||
```unison
|
||||
@ -268,11 +283,15 @@ x = match Some a with
|
||||
|
||||
Loading changes detected in scratch.u.
|
||||
|
||||
offset=12:
|
||||
unexpected ->
|
||||
expecting newline or semicolon
|
||||
I got confused here:
|
||||
|
||||
4 | -> 2
|
||||
|
||||
|
||||
I was surprised to find a -> here.
|
||||
I was hoping for one of these instead:
|
||||
|
||||
* newline or semicolon
|
||||
|
||||
```
|
||||
```unison
|
||||
@ -286,11 +305,15 @@ x = match Some a with
|
||||
|
||||
Loading changes detected in scratch.u.
|
||||
|
||||
offset=12:
|
||||
unexpected |
|
||||
expecting newline or semicolon
|
||||
I got confused here:
|
||||
|
||||
4 | | true -> 2
|
||||
|
||||
|
||||
I was surprised to find a '|' here.
|
||||
I was hoping for one of these instead:
|
||||
|
||||
* newline or semicolon
|
||||
|
||||
```
|
||||
### Watches
|
||||
|
26
unison-src/transcripts/generic-parse-errors.md
Normal file
26
unison-src/transcripts/generic-parse-errors.md
Normal file
@ -0,0 +1,26 @@
|
||||
Just a bunch of random parse errors to test the error formatting.
|
||||
|
||||
```unison:error
|
||||
x =
|
||||
foo.123
|
||||
```
|
||||
|
||||
```unison:error
|
||||
namespace.blah = 1
|
||||
```
|
||||
|
||||
```unison:error
|
||||
x = 1 ]
|
||||
```
|
||||
|
||||
```unison:error
|
||||
x = a.#abc
|
||||
```
|
||||
|
||||
```unison:error
|
||||
x = "hi
|
||||
```
|
||||
|
||||
```unison:error
|
||||
y : a
|
||||
```
|
107
unison-src/transcripts/generic-parse-errors.output.md
Normal file
107
unison-src/transcripts/generic-parse-errors.output.md
Normal file
@ -0,0 +1,107 @@
|
||||
Just a bunch of random parse errors to test the error formatting.
|
||||
|
||||
```unison
|
||||
x =
|
||||
foo.123
|
||||
```
|
||||
|
||||
```ucm
|
||||
|
||||
Loading changes detected in scratch.u.
|
||||
|
||||
I got confused here:
|
||||
|
||||
2 | foo.123
|
||||
|
||||
|
||||
I was surprised to find a 1 here.
|
||||
I was hoping for one of these instead:
|
||||
|
||||
* end of input
|
||||
* hash (ex: #af3sj3)
|
||||
* identifier (ex: abba1, snake_case, .foo.bar#xyz, .foo.++#xyz, or 🌻)
|
||||
|
||||
```
|
||||
```unison
|
||||
namespace.blah = 1
|
||||
```
|
||||
|
||||
```ucm
|
||||
|
||||
Loading changes detected in scratch.u.
|
||||
|
||||
The identifier used here isn't allowed to be a reserved keyword:
|
||||
|
||||
1 | namespace.blah = 1
|
||||
|
||||
|
||||
```
|
||||
```unison
|
||||
x = 1 ]
|
||||
```
|
||||
|
||||
```ucm
|
||||
|
||||
Loading changes detected in scratch.u.
|
||||
|
||||
I found a closing ']' here without a matching '['.
|
||||
|
||||
1 | x = 1 ]
|
||||
|
||||
|
||||
```
|
||||
```unison
|
||||
x = a.#abc
|
||||
```
|
||||
|
||||
```ucm
|
||||
|
||||
Loading changes detected in scratch.u.
|
||||
|
||||
I got confused here:
|
||||
|
||||
1 | x = a.#abc
|
||||
|
||||
|
||||
I was surprised to find a '.' here.
|
||||
|
||||
```
|
||||
```unison
|
||||
x = "hi
|
||||
```
|
||||
|
||||
```ucm
|
||||
|
||||
Loading changes detected in scratch.u.
|
||||
|
||||
I got confused here:
|
||||
|
||||
2 |
|
||||
|
||||
I was surprised to find an end of input here.
|
||||
I was hoping for one of these instead:
|
||||
|
||||
* "
|
||||
* \s
|
||||
* literal character
|
||||
|
||||
```
|
||||
```unison
|
||||
y : a
|
||||
```
|
||||
|
||||
```ucm
|
||||
|
||||
Loading changes detected in scratch.u.
|
||||
|
||||
I got confused here:
|
||||
|
||||
2 |
|
||||
|
||||
I was surprised to find an end of section here.
|
||||
I was hoping for one of these instead:
|
||||
|
||||
* ->
|
||||
* newline or semicolon
|
||||
|
||||
```
|
@ -282,11 +282,7 @@ lexer0' scope rem =
|
||||
expectedStr =
|
||||
expectedTokens
|
||||
& Set.map errorItemToString
|
||||
startsWithVowel :: String -> Bool
|
||||
startsWithVowel = \case
|
||||
[] -> False
|
||||
(ch : _) -> ch `elem` ("aeiou" :: String)
|
||||
err = UnexpectedTokens $ formatTrivialError startsWithVowel unexpectedStr expectedStr
|
||||
err = UnexpectedTokens $ formatTrivialError unexpectedStr expectedStr
|
||||
in [Token (Err err) (toPos top) (toPos top)]
|
||||
in errsWithSourcePos >>= errorToTokens
|
||||
Right ts -> Token (Open scope) topLeftCorner topLeftCorner : tweak ts
|
||||
@ -322,28 +318,20 @@ lexer0' scope rem =
|
||||
tweak (h : t) = h : tweak t
|
||||
isSigned num = all (\ch -> ch == '-' || ch == '+') $ take 1 num
|
||||
|
||||
formatTrivialError ::
|
||||
(IsString s, Monoid s) =>
|
||||
-- | A function that returns True if the given string starts with a vowel,
|
||||
-- Used for selecting the correct article.
|
||||
(s -> Bool) ->
|
||||
Set s ->
|
||||
Set s ->
|
||||
s
|
||||
formatTrivialError startsWithVowel unexpectedTokens expectedTokens =
|
||||
formatTrivialError :: Set String -> Set String -> [Char]
|
||||
formatTrivialError unexpectedTokens expectedTokens =
|
||||
let unexpectedMsg = case Set.toList unexpectedTokens of
|
||||
[] -> "I found something I didn't expect."
|
||||
[x] ->
|
||||
let article =
|
||||
if startsWithVowel x
|
||||
then "an"
|
||||
else "a"
|
||||
let article = case x of
|
||||
(c : _) | c `elem` ("aeiou" :: String) -> "an"
|
||||
_ -> "a"
|
||||
in "I was surprised to find " <> article <> " " <> x <> " here."
|
||||
xs -> "I was surprised to find these:\n\n* " <> intercalateMap "\n* " id xs
|
||||
xs -> "I was surprised to find these:\n\n* " <> List.intercalate "\n* " xs
|
||||
expectedMsg = case Set.toList expectedTokens of
|
||||
[] -> Nothing
|
||||
xs -> Just $ "\nI was hoping for one of these instead:\n\n* " <> intercalateMap "\n* " id xs
|
||||
in mconcat $ catMaybes [Just unexpectedMsg, expectedMsg]
|
||||
xs -> Just $ "\nI was hoping for one of these instead:\n\n* " <> List.intercalate "\n* " xs
|
||||
in concat $ catMaybes [Just unexpectedMsg, expectedMsg]
|
||||
|
||||
displayLexeme :: Lexeme -> String
|
||||
displayLexeme = \case
|
||||
|
Loading…
Reference in New Issue
Block a user