style(lexer): make binding naming consistent

This commit is contained in:
Primrose 2025-09-24 22:22:00 +08:00
parent 326c7b681c
commit 29c015b793
Signed by: primrose
GPG key ID: 4E887A4CA9714ADA
2 changed files with 12 additions and 12 deletions

View file

@ -93,7 +93,7 @@ lexText = go
, spaceToken , spaceToken
, link , link
, labeledLink , labeledLink
, modules , module_
, anchor , anchor
, textElement , textElement
, quotes , quotes
@ -189,15 +189,15 @@ identifierChar = satisfy (\c -> isAlphaNum c || c == '_')
-- "Module.Name" -- "Module.Name"
-- "Module.Name#anchor" -- "Module.Name#anchor"
-- "Module.Name\#anchor" -- known as "old anchor". this has been deprecated for 9 years, thanks Ben -- "Module.Name\#anchor" -- known as "old anchor". this has been deprecated for 9 years, thanks Ben
modules :: Lexer module_ :: Lexer
modules = between (char '"') (char '"') inner module_ = between (char '"') (char '"') inner
where where
inner = do inner = do
module_ <- located $ Module <$> moduleNames m <- located $ Module <$> moduleNames
mAnchor <- optionMaybe (located $ anchorHash *> (Anchor <$> anchorText)) mAnchor <- optionMaybe (located $ anchorHash *> (Anchor <$> anchorText))
pure $ case mAnchor of pure $ case mAnchor of
Just anchor -> [module_, anchor] Just anc -> [m, anc]
Nothing -> [module_] Nothing -> [m]
anchorHash :: Parser Text anchorHash :: Parser Text
anchorHash = "#" <|> try "\\#" anchorHash = "#" <|> try "\\#"

View file

@ -19,8 +19,8 @@ main = hspec $ do
describe "minimal" do describe "minimal" do
it "handles unicode" unicode it "handles unicode" unicode
it "escapes" escaping it "escapes" escaping
it "maths" maths it "maths" math
it "anchors" anchors it "anchors" anchor
it "space chars" space it "space chars" space
it "bare string" someString it "bare string" someString
it "emphasis" emphatic it "emphasis" emphatic
@ -84,14 +84,14 @@ labeledLink =
, (1, 35, LabeledLinkClose) , (1, 35, LabeledLinkClose)
] ]
anchors :: Expectation anchor :: Expectation
anchors = anchor =
"#myAnchor#" "#myAnchor#"
`shouldLexTo` [ (1, 1, Anchor "myAnchor") `shouldLexTo` [ (1, 1, Anchor "myAnchor")
] ]
maths :: IO () math :: IO ()
maths = do math = do
"\\[some math\\]" "\\[some math\\]"
`shouldLexTo` [ (1, 1, MathMultilineOpen) `shouldLexTo` [ (1, 1, MathMultilineOpen)
, (1, 3, Token "some math") , (1, 3, Token "some math")