Added expression eval; adjusted birdtrack, added sol combinator.
All checks were successful
Haskell CI / build (pull_request) Successful in 2m37s
Haskell CI / test (pull_request) Successful in 2m31s
Haskell CI / fourmolu (pull_request) Successful in 6s
Haskell CI / hlint (pull_request) Successful in 5s

This commit is contained in:
Igor Ranieri 2025-09-28 21:55:02 +02:00
parent 449b7c8ca7
commit f5a9dec3d6
3 changed files with 100 additions and 8 deletions

48
sp Normal file
View file

@ -0,0 +1,48 @@
2025-09-28T19:31:53.102437Z | Info | haskell-language-server version: 2.11.0.0 (GHC: 9.10.2) (PATH: /Users/igor/.ghcup/hls/2.11.0.0/lib/haskell-language-server-2.11.0.0/bin/haskell-language-server-9.10.2)
2025-09-28T19:31:53.103002Z | Info | Directory: /Users/igor/dev/haddock2
2025-09-28T19:31:53.103169Z | Info | Logging heap statistics every 60.00s
2025-09-28T19:31:53.107534Z | Info | Cradle path: src/Parser.hs
2025-09-28T19:31:53.107609Z | Warning | No [cradle](https://github.com/mpickering/hie-bios#hie-bios) found for src/Parser.hs.
Proceeding with [implicit cradle](https://hackage.haskell.org/package/implicit-hie).
You should ignore this message, unless you see a 'Multi Cradle: No prefixes matched' error.
2025-09-28T19:31:53.107865Z | Info | invoking build tool to determine build flags (this may take some time depending on the cache)
2025-09-28T19:31:53.217226Z | Info | Load cabal cradle using single file
2025-09-28T19:31:53.306920Z | Info | cabal --builddir=/Users/igor/.cache/hie-bios/dist-haddock2-46ec6b456aa9d4df12c3c8dec8c82e6e v2-repl --with-compiler /Users/igor/.cache/hie-bios/wrapper-b54f81dea4c0e6d1626911c526bc4e36 /Users/igor/dev/haddock2/src/Parser.hs
Environment Variables
HIE_BIOS_OUTPUT: /private/var/folders/9h/3j3xz6k52s95nrz7fkscvxph0000gs/T/HIE_BIOS_OUTPUT74985-0
HIE_BIOS_GHC: /Users/igor/.ghcup/bin/ghc
HIE_BIOS_GHC_ARGS: -B/Users/igor/.ghcup/ghc/9.10.2/lib/ghc-9.10.2/lib
2025-09-28T19:31:54.614435Z | Info | Interface files cache directory: /Users/igor/.cache/ghcide/haddock2-0.1.0.0-inplace-haddock2-lib-94626af6e87fa2a1c5fe808fee1ff90470339b17
2025-09-28T19:31:54.616421Z | Info | Making new HscEnv. In-place unit ids: [haddock2-0.1.0.0-inplace-haddock2-lib]
2025-09-28T19:31:54.624755Z | Info | Cradle path: app/Main.hs
2025-09-28T19:31:54.625170Z | Warning | No [cradle](https://github.com/mpickering/hie-bios#hie-bios) found for app/Main.hs.
Proceeding with [implicit cradle](https://hackage.haskell.org/package/implicit-hie).
You should ignore this message, unless you see a 'Multi Cradle: No prefixes matched' error.
2025-09-28T19:31:54.625483Z | Info | invoking build tool to determine build flags (this may take some time depending on the cache)
2025-09-28T19:31:54.738862Z | Info | Load cabal cradle using single file
2025-09-28T19:31:54.831553Z | Info | cabal --builddir=/Users/igor/.cache/hie-bios/dist-haddock2-46ec6b456aa9d4df12c3c8dec8c82e6e v2-repl --with-compiler /Users/igor/.cache/hie-bios/wrapper-b54f81dea4c0e6d1626911c526bc4e36 /Users/igor/dev/haddock2/app/Main.hs
Environment Variables
HIE_BIOS_OUTPUT: /private/var/folders/9h/3j3xz6k52s95nrz7fkscvxph0000gs/T/HIE_BIOS_OUTPUT74985-1
HIE_BIOS_GHC: /Users/igor/.ghcup/bin/ghc
HIE_BIOS_GHC_ARGS: -B/Users/igor/.ghcup/ghc/9.10.2/lib/ghc-9.10.2/lib
2025-09-28T19:31:55.143536Z | Info | Interface files cache directory: /Users/igor/.cache/ghcide/haddock2-0.1.0.0-inplace-haddock2-9922c59f82c27147a754c9396574cd2314aa3d19
2025-09-28T19:31:55.143714Z | Info | Interface files cache directory: /Users/igor/.cache/ghcide/haddock2-0.1.0.0-inplace-haddock2-lib-9922c59f82c27147a754c9396574cd2314aa3d19
2025-09-28T19:31:55.145930Z | Info | Making new HscEnv. In-place unit ids: [ haddock2-0.1.0.0-inplace-haddock2
, haddock2-0.1.0.0-inplace-haddock2-lib ]
2025-09-28T19:31:55.158809Z | Info | Cradle path: test/Spec.hs
2025-09-28T19:31:55.158933Z | Warning | No [cradle](https://github.com/mpickering/hie-bios#hie-bios) found for test/Spec.hs.
Proceeding with [implicit cradle](https://hackage.haskell.org/package/implicit-hie).
You should ignore this message, unless you see a 'Multi Cradle: No prefixes matched' error.
2025-09-28T19:31:55.159193Z | Info | invoking build tool to determine build flags (this may take some time depending on the cache)
2025-09-28T19:31:55.275847Z | Info | Load cabal cradle using single file
2025-09-28T19:31:55.368454Z | Info | cabal --builddir=/Users/igor/.cache/hie-bios/dist-haddock2-46ec6b456aa9d4df12c3c8dec8c82e6e v2-repl --with-compiler /Users/igor/.cache/hie-bios/wrapper-b54f81dea4c0e6d1626911c526bc4e36 /Users/igor/dev/haddock2/test/Spec.hs
Environment Variables
HIE_BIOS_OUTPUT: /private/var/folders/9h/3j3xz6k52s95nrz7fkscvxph0000gs/T/HIE_BIOS_OUTPUT74985-2
HIE_BIOS_GHC: /Users/igor/.ghcup/bin/ghc
HIE_BIOS_GHC_ARGS: -B/Users/igor/.ghcup/ghc/9.10.2/lib/ghc-9.10.2/lib
2025-09-28T19:31:57.159162Z | Info | Interface files cache directory: /Users/igor/.cache/ghcide/haddock2-0.1.0.0-inplace-haddock2-test-c33b0758a00798820f56b5dde448009132dfd22d
2025-09-28T19:31:57.159344Z | Info | Interface files cache directory: /Users/igor/.cache/ghcide/haddock2-0.1.0.0-inplace-haddock2-c33b0758a00798820f56b5dde448009132dfd22d
2025-09-28T19:31:57.159444Z | Info | Interface files cache directory: /Users/igor/.cache/ghcide/haddock2-0.1.0.0-inplace-haddock2-lib-c33b0758a00798820f56b5dde448009132dfd22d
2025-09-28T19:31:57.171150Z | Info | Making new HscEnv. In-place unit ids: [ haddock2-0.1.0.0-inplace-haddock2
, haddock2-0.1.0.0-inplace-haddock2-lib
, haddock2-0.1.0.0-inplace-haddock2-test ]

View file

@ -42,6 +42,7 @@ data Token
| Escape | Escape
| EmphasisOpen | EmphasisOpen
| EmphasisClose | EmphasisClose
| Expression
| Header Level | Header Level
| MonospaceOpen | MonospaceOpen
| MonospaceClose | MonospaceClose
@ -101,6 +102,7 @@ lexText = go
, try module_ , try module_
, quotes , quotes
, try expression
, birdTrack , birdTrack
-- starts with "\" -- starts with "\"
@ -158,16 +160,26 @@ delimited openP closeP openTok closeTok = asList <$> delimitedAsTuple (openTok <
asList (a, tok, b) = [a, tok, b] asList (a, tok, b) = [a, tok, b]
delimitedNoTrailing :: Parser open -> Parser close -> Token -> Parser [LocatedToken] delimitedNoTrailing :: Parser open -> Parser close -> Token -> Parser [LocatedToken]
delimitedNoTrailing openP closeP openTok = asList <$> delimitedAsTuple (openTok <$ openP) (void closeP) delimitedNoTrailing openP closeP openTok =
asList <$> delimitedAsTuple (openTok <$ openP) (void closeP)
where where
asList (a, tok, _) = [a, tok] asList (a, tok, _) = [a, tok]
delimitedSymmetric :: Parser a -> Token -> Token -> Parser [LocatedToken] delimitedSymmetric :: Parser a -> Token -> Token -> Parser [LocatedToken]
delimitedSymmetric s = delimited s s delimitedSymmetric s = delimited s s
--- End of line // end of file
eol :: Parser () eol :: Parser ()
eol = void "\n" <|> void "\r\n" <|> Parsec.eof eol = void "\n" <|> void "\r\n" <|> Parsec.eof
-- Start of line // start of file
sol :: Parser ()
sol = do
p <- getPosition
if sourceLine p == 1 && sourceColumn p == 1
then pure ()
else fail "Not at start of line/document"
header1 :: Lexer header1 :: Lexer
header1 = delimitedNoTrailing "= " eol (Header One) header1 = delimitedNoTrailing "= " eol (Header One)
@ -256,7 +268,13 @@ mathInline = delimited "\\(" "\\)" MathInlineOpen MathInlineClose
-- TODO: make sure this starts at column 0? -- TODO: make sure this starts at column 0?
birdTrack :: Lexer birdTrack :: Lexer
birdTrack = delimitedNoTrailing ">> " eol BirdTrack birdTrack = delimitedNoTrailing (sol <* "> ") eol BirdTrack
-- TODO: also match following lines iff:
-- they start with alphanum
-- they're not empty
expression :: Lexer
expression = delimitedNoTrailing (sol <* ">>> ") eol Expression
escape :: Lexer escape :: Lexer
escape = delimitedNoTrailing "\\" eol Escape escape = delimitedNoTrailing "\\" eol Escape

View file

@ -18,7 +18,7 @@ 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" math it "maths" maths
it "anchors" anchor it "anchors" anchor
it "space chars" space it "space chars" space
it "bare string" someString it "bare string" someString
@ -29,6 +29,7 @@ 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 "expressions" expressions
it "numeric entity" numericEntity it "numeric entity" numericEntity
it "ignores nesting" ignoreNesting it "ignores nesting" ignoreNesting
@ -91,8 +92,8 @@ anchor =
`shouldLexTo` [ (1, 1, Anchor "myAnchor") `shouldLexTo` [ (1, 1, Anchor "myAnchor")
] ]
math :: IO () maths :: IO ()
math = do maths = do
"\\[some math\\]" "\\[some math\\]"
`shouldLexTo` [ (1, 1, MathMultilineOpen) `shouldLexTo` [ (1, 1, MathMultilineOpen)
, (1, 3, Token "some math") , (1, 3, Token "some math")
@ -128,10 +129,35 @@ ignoreNesting =
] ]
birdTracks :: Expectation birdTracks :: Expectation
birdTracks = birdTracks = do
">> code" "> code line"
`shouldLexTo` [ (1, 1, BirdTrack) `shouldLexTo` [ (1, 1, BirdTrack)
, (1, 4, Token "code") , (1, 3, Token "code line")
]
" > not code"
`shouldLexTo` [ (1, 1, Space)
, (1, 2, Token ">")
, (1, 3, Space)
, (1, 4, Token "not")
, (1, 7, Space)
, (1, 8, Token "code")
]
expressions :: Expectation
expressions = do
">>> eval this"
`shouldLexTo` [ (1, 1, Expression)
, (1, 5, Token "eval this")
]
" >>> not eval this"
`shouldLexTo` [ (1, 1, Space)
, (1, 2, Token ">>>")
, (1, 5, Space)
, (1, 6, Token "not")
, (1, 9, Space)
, (1, 10, Token "eval")
, (1, 14, Space)
, (1, 15, Token "this")
] ]
quotes :: Expectation quotes :: Expectation