@@ -20,7 +20,10 @@ module Data.Syntax.Char (
23− endOfLine
23+ endOfLine,
26import Control.Lens.SemiIso
29import Control.Lens.SemiIso
@@ -68,3 +71,27 @@ spaces1 = constant (opoint ' ') /$/ takeWhile1 isSpace
68-- | Accepts a single newline. Generates a newline.
71-- | Accepts a single newline. Generates a newline.
69endOfLine :: SyntaxChar syn seq => syn ()
72endOfLine :: SyntaxChar syn seq => syn ()
70endOfLine = char '\n'
73endOfLine = char '\n'
76+digitDec :: SyntaxChar syn seq => syn Int
77+digitDec = semiIso toChar toInt /$/ anyChar
78+ where toInt c | isDigit c = Right (digitToInt c)
79+ | otherwise = Left ("Expected a decimal digit, got " ++ [c])
80+ toChar i | i >= 0 && i <= 9 = Right (intToDigit i)
81+ | otherwise = Left ("Expected a decimal digit, got number " ++ show i)
84+digitOct :: SyntaxChar syn seq => syn Int
85+digitOct = semiIso toChar toInt /$/ anyChar
86+ where toInt c | isOctDigit c = Right (digitToInt c)
87+ | otherwise = Left ("Expected an octal digit, got " ++ [c])
88+ toChar i | i >= 0 && i <= 7 = Right (intToDigit i)
89+ | otherwise = Left ("Expected an octal digit, got number " ++ show i)
92+digitHex :: SyntaxChar syn seq => syn Int
93+digitHex = semiIso toChar toInt /$/ anyChar
94+ where toInt c | isHexDigit c = Right (digitToInt c)
95+ | otherwise = Left ("Expected a hex digit, got " ++ [c])
96+ toChar i | i >= 0 && i <= 15 = Right (intToDigit i)
97+ | otherwise = Left ("Expected a hex digit, got number " ++ show i)