diff --git a/CONTRIBUTORS.markdown b/CONTRIBUTORS.markdown index e35d40033b..413ef3da70 100644 --- a/CONTRIBUTORS.markdown +++ b/CONTRIBUTORS.markdown @@ -88,3 +88,4 @@ The format for this list: name, GitHub handle * Eric Torreborre (@etorreborre) * Eduard Nicodei (@neduard) * Brian McKenna (@puffnfresh) +* Ruslan Simchuk (@SimaDovakin) diff --git a/editor-support/vim/syntax/unison.vim b/editor-support/vim/syntax/unison.vim index ec193723a7..3bd3b2ef68 100644 --- a/editor-support/vim/syntax/unison.vim +++ b/editor-support/vim/syntax/unison.vim @@ -48,7 +48,7 @@ syn match uSpecialCharError contained "\\&\|'''\+" syn region uString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=uSpecialChar syn match uCharacter "[^a-zA-Z0-9_']'\([^\\]\|\\[^']\+\|\\'\)'"lc=1 contains=uSpecialChar,uSpecialCharError syn match uCharacter "^'\([^\\]\|\\[^']\+\|\\'\)'" contains=uSpecialChar,uSpecialCharError -syn match uNumber "\<[0-9]\+\>\|\<0[xX][0-9a-fA-F]\+\>\|\<0[oO][0-7]\+\>" +syn match uNumber "\<[0-9]\+\>\|\<0[xX][0-9a-fA-F]\+\>\|\<0[oO][0-7]\+\>\|\<0[bB][01]\+\>" syn match uFloat "\<[0-9]\+\.[0-9]\+\([eE][-+]\=[0-9]\+\)\=\>" " Keyword definitions. These must be patterns instead of keywords @@ -83,7 +83,7 @@ syn region uDocDirective contained matchgroup=unisonDocDirective start="\(@ syn match uDebug "\<\(todo\|bug\|Debug.trace\)\>" -" things like +" things like " > my_func 1 3 " test> Function.tap.tests.t1 = check let " use Nat == + @@ -101,7 +101,7 @@ if version >= 508 || !exists("did_u_syntax_inits") else command -nargs=+ HiLink hi def link endif - + HiLink uWatch Debug HiLink uDocMono Delimiter HiLink unisonDocDirective Import diff --git a/parser-typechecker/src/Unison/PrintError.hs b/parser-typechecker/src/Unison/PrintError.hs index a4cf9e4b25..d39e152903 100644 --- a/parser-typechecker/src/Unison/PrintError.hs +++ b/parser-typechecker/src/Unison/PrintError.hs @@ -1428,6 +1428,18 @@ renderParseErrors s = \case <> "after the" <> Pr.group (style ErrorSite "0o" <> ".") ] + L.InvalidBinaryLiteral -> + Pr.lines + [ "This number isn't valid syntax: ", + "", + excerpt, + Pr.wrap $ + "I was expecting only binary characters" + <> "(one of" + <> Pr.group (style Code "01" <> ")") + <> "after the" + <> Pr.group (style ErrorSite "0b" <> ".") + ] L.InvalidShortHash h -> Pr.lines [ "Invalid hash: " <> style ErrorSite (fromString h), diff --git a/unison-src/transcripts/error-messages.md b/unison-src/transcripts/error-messages.md index 8490e491a2..f3b0353806 100644 --- a/unison-src/transcripts/error-messages.md +++ b/unison-src/transcripts/error-messages.md @@ -27,7 +27,7 @@ x = 1e- -- missing an exponent x = 1E+ -- missing an exponent ``` -### Hex, octal, and bytes literals +### Hex, octal, binary, and bytes literals ```unison:error x = 0xoogabooga -- invalid hex chars @@ -37,6 +37,10 @@ x = 0xoogabooga -- invalid hex chars x = 0o987654321 -- 9 and 8 are not valid octal char ``` +```unison:error +x = 0b3201 -- 3 and 2 are not valid binary chars +``` + ```unison:error x = 0xsf -- odd number of hex chars in a bytes literal ``` @@ -81,7 +85,7 @@ foo = cases ```unison:error -- Missing a '->' x = match Some a with - None -> + None -> 1 Some _ 2 diff --git a/unison-src/transcripts/error-messages.output.md b/unison-src/transcripts/error-messages.output.md index 148218a759..ebcce29e97 100644 --- a/unison-src/transcripts/error-messages.output.md +++ b/unison-src/transcripts/error-messages.output.md @@ -70,7 +70,7 @@ x = 1E+ -- missing an exponent `1e+37`. ``` -### Hex, octal, and bytes literals +### Hex, octal, binary, and bytes literals ``` unison x = 0xoogabooga -- invalid hex chars @@ -103,6 +103,22 @@ x = 0o987654321 -- 9 and 8 are not valid octal char I was expecting only octal characters (one of 01234567) after the 0o. +``` +``` unison +x = 0b3201 -- 3 and 2 are not valid binary chars +``` + +``` ucm + + Loading changes detected in scratch.u. + + This number isn't valid syntax: + + 1 | x = 0b3201 -- 3 and 2 are not valid binary chars + + I was expecting only binary characters (one of 01) after the + 0b. + ``` ``` unison x = 0xsf -- odd number of hex chars in a bytes literal @@ -244,7 +260,7 @@ foo = cases ``` unison -- Missing a '->' x = match Some a with - None -> + None -> 1 Some _ 2 diff --git a/unison-syntax/src/Unison/Syntax/Lexer/Unison.hs b/unison-syntax/src/Unison/Syntax/Lexer/Unison.hs index ac31fdcac4..7db46e5bd6 100644 --- a/unison-syntax/src/Unison/Syntax/Lexer/Unison.hs +++ b/unison-syntax/src/Unison/Syntax/Lexer/Unison.hs @@ -87,6 +87,7 @@ data Err | InvalidBytesLiteral String | InvalidHexLiteral | InvalidOctalLiteral + | InvalidBinaryLiteral | Both Err Err | MissingFractional String -- ex `1.` rather than `1.04` | MissingExponent String -- ex `1e` rather than `1e3` @@ -535,7 +536,7 @@ lexemes eof = case Bytes.fromBase16 $ Bytes.fromWord8s (fromIntegral . ord <$> s) of Left _ -> err start (InvalidBytesLiteral $ "0xs" <> s) Right bs -> pure (Bytes bs) - otherbase = octal <|> hex + otherbase = octal <|> hex <|> binary octal = do start <- posP commitAfter2 sign (lit "0o") $ \sign _ -> @@ -544,6 +545,10 @@ lexemes eof = start <- posP commitAfter2 sign (lit "0x") $ \sign _ -> fmap (num sign) LP.hexadecimal <|> err start InvalidHexLiteral + binary = do + start <- posP + commitAfter2 sign (lit "0b") $ \sign _ -> + fmap (num sign) LP.binary <|> err start InvalidBinaryLiteral num :: Maybe String -> Integer -> Lexeme num sign n = Numeric (fromMaybe "" sign <> show n)