From d7ad6915d22dbc26953150aca139ad37722ef723 Mon Sep 17 00:00:00 2001 From: mariari <32526923+mariari@users.noreply.github.com> Date: Mon, 18 Jul 2022 19:32:43 +0800 Subject: [PATCH] Widens the accepted symbol list (#1385) * Changed the valid symbols from inclusvie to exclusive * Add test using the new valid symbols --- src/Juvix/Syntax/Concrete/Lexer.hs | 16 ++++----------- test/Scope/Positive.hs | 7 ++++++- tests/positive/Symbols.juvix | 31 ++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 13 deletions(-) create mode 100644 tests/positive/Symbols.juvix diff --git a/src/Juvix/Syntax/Concrete/Lexer.hs b/src/Juvix/Syntax/Concrete/Lexer.hs index 47e49b2204..f8f359e9b3 100644 --- a/src/Juvix/Syntax/Concrete/Lexer.hs +++ b/src/Juvix/Syntax/Concrete/Lexer.hs @@ -118,19 +118,11 @@ validTailChar :: Char -> Bool validTailChar c = isAlphaNum c || validFirstChar c +reservedSymbols :: [Char] +reservedSymbols = "\";(){}[].≔λ\\" + validFirstChar :: Char -> Bool -validFirstChar c = - or - [ isLetter c, - cat == MathSymbol, - cat == CurrencySymbol, - cat == ModifierLetter, - c `elem` extraAllowedChars - ] - where - extraAllowedChars :: [Char] - extraAllowedChars = "_'-*,&" - cat = generalCategory c +validFirstChar c = not $ isNumber c || isSpace c || (c `elem` reservedSymbols) dot :: forall e m. MonadParsec e Text m => m Char dot = P.char '.' diff --git a/test/Scope/Positive.hs b/test/Scope/Positive.hs index 24f703c0fc..9cf8be0788 100644 --- a/test/Scope/Positive.hs +++ b/test/Scope/Positive.hs @@ -199,5 +199,10 @@ tests = "Import embedded standard library" "StdlibImport" StdlibInclude - "StdlibImport.juvix" + "StdlibImport.juvix", + PosTest + "Check Valid Symbols" + "" + StdlibInclude + "Symbols.juvix" ] diff --git a/tests/positive/Symbols.juvix b/tests/positive/Symbols.juvix new file mode 100644 index 0000000000..c7539bcd08 --- /dev/null +++ b/tests/positive/Symbols.juvix @@ -0,0 +1,31 @@ +module Symbols; + + open import Stdlib.Data.Nat; + + ╘⑽╛ : ℕ; + ╘⑽╛ ≔ suc nine; + + -- no - function!? + - : ℕ -> ℕ -> ℕ; + - ≔ (+); + + (-) : ℕ -> ℕ -> ℕ; + (-) ≔ (-); + + (*) : ℕ -> ℕ -> ℕ; + (*) ≔ (*); + + infixl 6 -; + - : ℕ -> ℕ -> ℕ; + - ≔ (-); + + infixl 7 ·; + · : ℕ -> ℕ -> ℕ; + · ≔ (*); + + (0) : ℕ; + (0) ≔ ╘⑽╛ - ╘⑽╛ · zero; + + 主功能 : ℕ; + 主功能 ≔ (0); +end; \ No newline at end of file