merge comments parser into Utils.SteParser.Lex

fogti
Aug 26, 2024, 4:42 PM
7KZ6F5OCRNJEUS6YBBNGW77EAWTLRMUPHP7I6Y7MDVD5ZYY2R5XAC

Dependencies

  • [2] HQ2ZYTX5 add comment lexing and remove references stuff
  • [3] 6XMVEBZA add simple stuff (e.g. haskell basics)
  • [4] GMGXNJEP add back more stuff from yanais
  • [5] JDF4JUMS some attempts at abstract syntax

Change contents

  • file deletion: Comments.hs (----------)
    [3.2678][2.0:35](),[2.35][2.36:36]()
    module GardGround.Utils.SteParser.Comments (
    lexeComments,
    ) where
    import qualified Data.HashMap.Strict as H
    import GardGround.Utils.SteParser.Lex (HandleTree(..), Parser', eats, skipWhiteSpace, tryOne)
    data LevelDelta = LevelIncr | LevelDecr
    lvladj :: LevelDelta -> Integer -> Integer
    lvladj LevelDecr lvl = lvl - 1
    lvladj LevelIncr lvl = lvl + 1
    lexeCommentsTreeInit :: HandleTree LevelDelta
    lexeCommentsTreeInit = HandleTree (H.fromList l1) Nothing
    where
    l1 = [('(' {- ) -}, HandleTree (H.fromList l2) Nothing)]
    l2 = [('*', Htleaf LevelIncr)]
    lexeCommentsTree :: HandleTree LevelDelta
    lexeCommentsTree = HandleTree (H.fromList l1) Nothing
    where
    -- (* ... comment start; *) ... comment end
    l1 = [('(' {- ) -}, HandleTree (H.fromList l2) Nothing)
    ,('*', HandleTree (H.fromList l3) Nothing)]
    l2 = [('*', Htleaf LevelIncr)]
    l3 = [({- ( -} ')', Htleaf LevelDecr)]
    lexeComments :: Integer -> Parser' e ()
    lexeComments (-1) = error "lexeComments invalid index"
    lexeComments lvl = do
    (if lvl <= 0 then skipWhiteSpace else pure ())
    fi <- eats (if lvl <= 0 then lexeCommentsTreeInit else lexeCommentsTree)
    case fi of
    Just ld -> lexeComments $ lvladj ld lvl
    -- we either can abort searching for comment contents (lvl == 0)
    -- or we skip over a single character and continue
    Nothing -> if lvl <= 0 then pure () else tryOne (\_ -> Just ()) >> lexeComments lvl
  • edit in core/lib/GardGround/Utils/SteParser/Lex.hs at line 30
    [3.4192]
    [3.4192]
    -- concrete parsers
    skipComments,
  • edit in core/lib/GardGround/Utils/SteParser/Lex.hs at line 243
    [3.10703]
    -- | usually called as `skipComments 0`, skips over comments delimited by `(*` and `*)`
    skipComments :: Integer -> Parser' e ()
    skipComments (-1) = error "lexeComments invalid index"
    skipComments lvl = do
    (if lvl <= 0 then skipWhiteSpace else pure ())
    fi <- eats (if lvl <= 0 then lexeCommentsTreeInit else lexeCommentsTree)
    case fi of
    Just ld -> skipComments $ lvl + ld
    -- we either can abort searching for comment contents (lvl == 0)
    -- or we skip over a single character and continue
    Nothing -> if lvl <= 0 then pure () else tryOne (\_ -> Just ()) >> skipComments lvl
    where
    lexeCommentsTreeInit :: HandleTree Integer
    lexeCommentsTreeInit = HandleTree (H.fromList l1) Nothing
    where
    l1 = [('(' {- ) -}, HandleTree (H.fromList l2) Nothing)]
    l2 = [('*', Htleaf 1)]
    lexeCommentsTree :: HandleTree Integer
    lexeCommentsTree = HandleTree (H.fromList l1) Nothing
    where
    -- (* ... comment start; *) ... comment end
    l1 = [('(' {- ) -}, HandleTree (H.fromList l2) Nothing)
    ,('*', HandleTree (H.fromList l3) Nothing)]
    l2 = [('*', Htleaf 1)]
    l3 = [({- ( -} ')', Htleaf (-1))]
  • edit in core/gardground-core.cabal at line 24
    [3.10877][2.1487:1531]()
    GardGround.Utils.SteParser.Comments