Compare commits
No commits in common. "5073fc0e254f4656c0e3e3620efd04146a595c94" and "970b658926e4a683f6c557539ddf750803cabd44" have entirely different histories.
5073fc0e25
...
970b658926
2 changed files with 1 additions and 42 deletions
30
src/Lexer.hs
30
src/Lexer.hs
|
|
@ -10,8 +10,7 @@ import Control.Monad (mfilter, void)
|
||||||
import Data.Functor (($>))
|
import Data.Functor (($>))
|
||||||
import Data.Text (Text, intercalate)
|
import Data.Text (Text, intercalate)
|
||||||
import Data.Text qualified as Text
|
import Data.Text qualified as Text
|
||||||
import Data.Char (ord, toLower)
|
import GHC.Unicode (isAlphaNum, isControl, isPrint, isSpace, isUpper)
|
||||||
import GHC.Unicode (isAlphaNum, isControl, isPrint, isSpace, isUpper, isDigit)
|
|
||||||
import ParserMonad (Parser, initialParserState)
|
import ParserMonad (Parser, initialParserState)
|
||||||
import Text.Parsec
|
import Text.Parsec
|
||||||
import Text.Parsec qualified as Parsec
|
import Text.Parsec qualified as Parsec
|
||||||
|
|
@ -93,7 +92,6 @@ lexText = go
|
||||||
, labeledLink
|
, labeledLink
|
||||||
, module_
|
, module_
|
||||||
, anchor
|
, anchor
|
||||||
, numericEntity
|
|
||||||
, textElement
|
, textElement
|
||||||
, quotes
|
, quotes
|
||||||
, birdTrack
|
, birdTrack
|
||||||
|
|
@ -256,32 +254,6 @@ bold = delimitedSymmetric "__" BoldOpen BoldClose
|
||||||
monospace :: Lexer
|
monospace :: Lexer
|
||||||
monospace = delimitedSymmetric "@" MonospaceOpen MonospaceClose
|
monospace = delimitedSymmetric "@" MonospaceOpen MonospaceClose
|
||||||
|
|
||||||
decimal :: Parser Int
|
|
||||||
decimal = read . Text.unpack <$> takeWhile1_ isDigit
|
|
||||||
|
|
||||||
hexadecimal :: Parser Int
|
|
||||||
hexadecimal = "x" *> (convert 0 . fmap (normalise . toLower) <$> many1 hexDigit)
|
|
||||||
where
|
|
||||||
normalise :: Char -> Int
|
|
||||||
normalise c
|
|
||||||
| ord '0' <= n && n <= ord '9' = n - ord '0'
|
|
||||||
| ord 'A' <= n && n <= ord 'F' = n - ord 'A' + 10
|
|
||||||
| ord 'a' <= n && n <= ord 'f' = n - ord 'a' + 10
|
|
||||||
| otherwise = error "unexpected: invalid hex number"
|
|
||||||
where
|
|
||||||
n = ord c
|
|
||||||
|
|
||||||
convert :: Int -> [Int] -> Int
|
|
||||||
convert acc [] = acc
|
|
||||||
convert acc (x : xs) = convert (acc * 16 + x) xs
|
|
||||||
|
|
||||||
numericEntity :: Lexer
|
|
||||||
numericEntity = do
|
|
||||||
x <- located $ between "&#" ";"
|
|
||||||
( NumericEntity <$> (hexadecimal <|> decimal)
|
|
||||||
)
|
|
||||||
pure [x]
|
|
||||||
|
|
||||||
other :: Lexer
|
other :: Lexer
|
||||||
other = do
|
other = do
|
||||||
pos <- getPosition
|
pos <- getPosition
|
||||||
|
|
|
||||||
13
test/Spec.hs
13
test/Spec.hs
|
|
@ -30,7 +30,6 @@ main = hspec $ do
|
||||||
it "bird tracks" birdTracks
|
it "bird tracks" birdTracks
|
||||||
it "module names" modules
|
it "module names" modules
|
||||||
it "quotes" quotes
|
it "quotes" quotes
|
||||||
it "numeric entity" numericEntity
|
|
||||||
it "ignores nesting" ignoreNesting
|
it "ignores nesting" ignoreNesting
|
||||||
|
|
||||||
describe "Parser" do
|
describe "Parser" do
|
||||||
|
|
@ -153,18 +152,6 @@ space = do
|
||||||
, (1, 2, Newline)
|
, (1, 2, Newline)
|
||||||
]
|
]
|
||||||
|
|
||||||
numericEntity :: Expectation
|
|
||||||
numericEntity = do
|
|
||||||
"A λ"
|
|
||||||
`shouldLexTo` [ (1, 1, NumericEntity 65)
|
|
||||||
, (1, 6, Space)
|
|
||||||
, (1, 7, NumericEntity 955) -- lambda
|
|
||||||
]
|
|
||||||
-- Hex
|
|
||||||
"e"
|
|
||||||
`shouldLexTo` [ (1, 1, NumericEntity 101)
|
|
||||||
]
|
|
||||||
|
|
||||||
monospace :: Expectation
|
monospace :: Expectation
|
||||||
monospace =
|
monospace =
|
||||||
"@mono@"
|
"@mono@"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue