phino 0.0.0.6 → 0.0.0.7
raw patch · 3 files changed
+30/−3 lines, 3 files
Files
- phino.cabal +1/−1
- src/Parser.hs +27/−1
- test/ParserSpec.hs +2/−1
phino.cabal view
@@ -1,7 +1,7 @@ cabal-version: 3.0 name: phino-version: 0.0.0.6+version: 0.0.0.7 license: MIT synopsis: Command-Line Manipulator of 𝜑-Calculus Expressions description: Please see the README on GitHub at <https://github.com/objectionary/phino#readme>
src/Parser.hs view
@@ -23,7 +23,9 @@ import Data.Sequence (mapWithIndex) import Data.Text.Internal.Fusion.Size (lowerBound) import Data.Void+import GHC.Char (chr) import Misc (numToHex, strToHex, withVoidRho)+import Numeric (readHex) import Text.Megaparsec import Text.Megaparsec.Char (alphaNumChar, char, digitChar, hexDigitChar, letterChar, lowerChar, space1, string, upperChar) import qualified Text.Megaparsec.Char.Lexer as L@@ -73,6 +75,30 @@ rest <- many (satisfy (`notElem` " \r\n\t,.|':;!?][}{)(⟧⟦") <?> "allowed character") return (first : rest) +escapedChar :: Parser Char+escapedChar = do+ _ <- char '\\'+ c <- oneOf ['\\', '"', 'n', 'r', 't', 'b', 'f', 'u']+ case c of+ '\\' -> return '\\'+ '"' -> return '"'+ 'n' -> return '\n'+ 'r' -> return '\r'+ 't' -> return '\t'+ 'b' -> return '\b'+ 'f' -> return '\f'+ 'u' -> unicodeEscape+ _ -> fail $ "Unknown escape: \\" ++ [c]++unicodeEscape :: Parser Char+unicodeEscape = do+ hexDigits <- count 4 hexDigitChar+ case readHex hexDigits of+ [(n, "")] ->+ if (n >= 0 && n <= 0x10FFFF) && not (n >= 0xD800 && n <= 0xDFFF)+ then return (chr n)+ else fail ("Invalid Unicode code point: \\u" ++ hexDigits)+ function :: Parser String function = lexeme $ do first <- oneOf ['A' .. 'Z']@@ -298,7 +324,7 @@ return (dataExpression "number" (numToHex num)), lexeme $ do _ <- char '"'- str <- manyTill L.charLiteral (char '"')+ str <- manyTill (choice [escapedChar, noneOf ['\\', '"']]) (char '"') return (dataExpression "string" (strToHex str)), try (ExMeta <$> meta' 'e' "𝑒"), ExDispatch ExThis <$> fullAttribute
test/ParserSpec.hs view
@@ -240,7 +240,8 @@ "[[\n x -> \"Hi\",\n y -> 42\n]]", "[[x -> -42, y -> +34]]", "⟦x ↦ Φ.org.eolang(z ↦ ξ.f, x ↦ α0, φ ↦ ρ, t ↦ φ, first ↦ ⟦ λ ⤍ Function_name, Δ ⤍ 42- ⟧)⟧",- "[[x -> 1.00e+3, y -> 2.32e-4]]"+ "[[x -> 1.00e+3, y -> 2.32e-4]]",+ "[[ x -> \"\\u0001\\u0001\"]]" ] (\expr -> it expr (parseExpression expr `shouldSatisfy` isRight))