Compare commits

..

7 commits

Author SHA1 Message Date
6c0b4a4288
doc(lexer): explain the use of incSourceColumn
I think it is clearer to phrase it this way so it is clear that we are
not unconsuming (i.e. changing the state of the parser).
2025-09-24 21:25:46 +08:00
75c4817166
style(lexer): pluralize moduleNames parser 2025-09-24 21:25:46 +08:00
7ceb9b0277
ref(moduleName): break into multiple smaller functions
upperId has been changed to only use isUpper because an non alphabetical
character would be false anyway
2025-09-24 21:25:46 +08:00
368e5bc9a0
ref(lexer): simplify anchor 2025-09-24 21:25:46 +08:00
d6087ec3d6
ref(lexer): simplify delimited logic 2025-09-24 21:25:46 +08:00
fdb9070e99
fix(lexer): handle crlf in newline
Do we support windows 🤔
2025-09-24 21:25:46 +08:00
39cfe2035d test: freeze the callstack for better failure messages (#1)
This would make the function `shouldLexTo` be transparent in the error reporting! Before all errors would point to this line.

Reviewed-on: #1
Co-authored-by: Léana 江 <leana.jiang+git@icloud.com>
Co-committed-by: Léana 江 <leana.jiang+git@icloud.com>
2025-09-24 11:01:52 +00:00
2 changed files with 3 additions and 1 deletions

View file

@ -221,7 +221,7 @@ link :: Lexer
link = do
pos <- getPosition
l <- linkRaw
-- "unconsume" the last token
-- register the position of the last token
pos' <- flip incSourceColumn (-1) <$> getPosition
pure $ (pos, LinkOpen) : l <> [(pos', LinkClose)]

View file

@ -11,6 +11,7 @@ import Types
import Data.String (IsString (..))
import Data.Text (Text)
import Text.Parsec.Pos
import GHC.Stack
main :: IO ()
main = hspec $ do
@ -186,6 +187,7 @@ instance IsString (Doc String) where
shouldLexTo :: String -> [(Int, Int, Token)] -> Expectation
shouldLexTo input expected =
withFrozenCallStack $
case lexer input of
Right tokens -> do
let actual = map (\(pos, tok) -> (sourceLine pos, sourceColumn pos, tok)) tokens