mirror of
https://github.com/unisonweb/unison.git
synced 2024-09-11 10:35:57 +03:00
Update transcripts
This commit is contained in:
parent
19b8131777
commit
3d95906195
@ -1524,7 +1524,7 @@ renderParseErrors s = \case
|
|||||||
Nothing -> []
|
Nothing -> []
|
||||||
Just ts -> rangeForToken <$> Foldable.toList ts
|
Just ts -> rangeForToken <$> Foldable.toList ts
|
||||||
excerpt = showSource s ((\r -> (r, ErrorSite)) <$> ranges)
|
excerpt = showSource s ((\r -> (r, ErrorSite)) <$> ranges)
|
||||||
msg = L.formatTrivialError _ unexpectedTokenStrs expectedTokenStrs
|
msg = L.formatTrivialError unexpectedTokenStrs expectedTokenStrs
|
||||||
in [ ( Pr.lines
|
in [ ( Pr.lines
|
||||||
[ "I got confused here:",
|
[ "I got confused here:",
|
||||||
"",
|
"",
|
||||||
|
@ -210,10 +210,16 @@ foo = match 1 with
|
|||||||
|
|
||||||
Loading changes detected in scratch.u.
|
Loading changes detected in scratch.u.
|
||||||
|
|
||||||
offset=8:
|
I got confused here:
|
||||||
unexpected <outdent>
|
|
||||||
expecting ",", case match, or pattern guard
|
|
||||||
3 |
|
3 |
|
||||||
|
|
||||||
|
I was surprised to find an end of section here.
|
||||||
|
I was hoping for one of these instead:
|
||||||
|
|
||||||
|
* ","
|
||||||
|
* case match
|
||||||
|
* pattern guard
|
||||||
|
|
||||||
```
|
```
|
||||||
```unison
|
```unison
|
||||||
@ -250,10 +256,19 @@ x = match Some a with
|
|||||||
|
|
||||||
Loading changes detected in scratch.u.
|
Loading changes detected in scratch.u.
|
||||||
|
|
||||||
offset=16:
|
I got confused here:
|
||||||
unexpected <outdent>
|
|
||||||
expecting ",", blank, case match, false, pattern guard, or true
|
|
||||||
7 |
|
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
|
```unison
|
||||||
@ -268,11 +283,15 @@ x = match Some a with
|
|||||||
|
|
||||||
Loading changes detected in scratch.u.
|
Loading changes detected in scratch.u.
|
||||||
|
|
||||||
offset=12:
|
I got confused here:
|
||||||
unexpected ->
|
|
||||||
expecting newline or semicolon
|
|
||||||
4 | -> 2
|
4 | -> 2
|
||||||
|
|
||||||
|
|
||||||
|
I was surprised to find a -> here.
|
||||||
|
I was hoping for one of these instead:
|
||||||
|
|
||||||
|
* newline or semicolon
|
||||||
|
|
||||||
```
|
```
|
||||||
```unison
|
```unison
|
||||||
@ -286,11 +305,15 @@ x = match Some a with
|
|||||||
|
|
||||||
Loading changes detected in scratch.u.
|
Loading changes detected in scratch.u.
|
||||||
|
|
||||||
offset=12:
|
I got confused here:
|
||||||
unexpected |
|
|
||||||
expecting newline or semicolon
|
|
||||||
4 | | true -> 2
|
4 | | true -> 2
|
||||||
|
|
||||||
|
|
||||||
|
I was surprised to find a '|' here.
|
||||||
|
I was hoping for one of these instead:
|
||||||
|
|
||||||
|
* newline or semicolon
|
||||||
|
|
||||||
```
|
```
|
||||||
### Watches
|
### 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 =
|
expectedStr =
|
||||||
expectedTokens
|
expectedTokens
|
||||||
& Set.map errorItemToString
|
& Set.map errorItemToString
|
||||||
startsWithVowel :: String -> Bool
|
err = UnexpectedTokens $ formatTrivialError unexpectedStr expectedStr
|
||||||
startsWithVowel = \case
|
|
||||||
[] -> False
|
|
||||||
(ch : _) -> ch `elem` ("aeiou" :: String)
|
|
||||||
err = UnexpectedTokens $ formatTrivialError startsWithVowel unexpectedStr expectedStr
|
|
||||||
in [Token (Err err) (toPos top) (toPos top)]
|
in [Token (Err err) (toPos top) (toPos top)]
|
||||||
in errsWithSourcePos >>= errorToTokens
|
in errsWithSourcePos >>= errorToTokens
|
||||||
Right ts -> Token (Open scope) topLeftCorner topLeftCorner : tweak ts
|
Right ts -> Token (Open scope) topLeftCorner topLeftCorner : tweak ts
|
||||||
@ -322,28 +318,20 @@ lexer0' scope rem =
|
|||||||
tweak (h : t) = h : tweak t
|
tweak (h : t) = h : tweak t
|
||||||
isSigned num = all (\ch -> ch == '-' || ch == '+') $ take 1 num
|
isSigned num = all (\ch -> ch == '-' || ch == '+') $ take 1 num
|
||||||
|
|
||||||
formatTrivialError ::
|
formatTrivialError :: Set String -> Set String -> [Char]
|
||||||
(IsString s, Monoid s) =>
|
formatTrivialError unexpectedTokens expectedTokens =
|
||||||
-- | 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 =
|
|
||||||
let unexpectedMsg = case Set.toList unexpectedTokens of
|
let unexpectedMsg = case Set.toList unexpectedTokens of
|
||||||
[] -> "I found something I didn't expect."
|
[] -> "I found something I didn't expect."
|
||||||
[x] ->
|
[x] ->
|
||||||
let article =
|
let article = case x of
|
||||||
if startsWithVowel x
|
(c : _) | c `elem` ("aeiou" :: String) -> "an"
|
||||||
then "an"
|
_ -> "a"
|
||||||
else "a"
|
|
||||||
in "I was surprised to find " <> article <> " " <> x <> " here."
|
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
|
expectedMsg = case Set.toList expectedTokens of
|
||||||
[] -> Nothing
|
[] -> Nothing
|
||||||
xs -> Just $ "\nI was hoping for one of these instead:\n\n* " <> intercalateMap "\n* " id xs
|
xs -> Just $ "\nI was hoping for one of these instead:\n\n* " <> List.intercalate "\n* " xs
|
||||||
in mconcat $ catMaybes [Just unexpectedMsg, expectedMsg]
|
in concat $ catMaybes [Just unexpectedMsg, expectedMsg]
|
||||||
|
|
||||||
displayLexeme :: Lexeme -> String
|
displayLexeme :: Lexeme -> String
|
||||||
displayLexeme = \case
|
displayLexeme = \case
|
||||||
|
Loading…
Reference in New Issue
Block a user