Fixed the infinite loop

This commit is contained in:
VegOwOtenks 2025-02-13 23:39:17 +01:00
parent b87917dc2e
commit c12458a2bf
3 changed files with 8 additions and 7 deletions

View file

@ -6,4 +6,4 @@ main :: IO ()
main = do main = do
text <- getContents text <- getContents
print $ Parsec.parse (File.parse <* Parsec.eof) "<stdin>" text print $ Parsec.parse (File.parse "<stdin>" <* Parsec.eof) "<stdin>" text

View file

@ -19,7 +19,7 @@ import qualified Ubc.Parse.Syntax.Struct as Struct
import qualified Ubc.Parse.Syntax.Function as Function import qualified Ubc.Parse.Syntax.Function as Function
import qualified Ubc.Parse.Syntax.Statement as Statement import qualified Ubc.Parse.Syntax.Statement as Statement
import qualified Ubc.Parse.Syntax.Enumeration as Enumeration import qualified Ubc.Parse.Syntax.Enumeration as Enumeration
import GHC.Generics (Generic) import GHC.Generics (Generic, Generically(..))
import Data.Functor ((<&>)) import Data.Functor ((<&>))
data File = File data File = File
@ -35,10 +35,11 @@ data FileBody = FileBody
, enumerations :: [Enumeration] , enumerations :: [Enumeration]
} }
deriving stock (Show, Generic) deriving stock (Show, Generic)
deriving (Semigroup, Monoid) via FileBody deriving (Semigroup, Monoid) via Generically FileBody
-- dont use `deriving ... via FileBody` because that leads to a loop, somehow
parse :: Monad m => ParsecT String u m File parse :: Monad m => String -> ParsecT String u m File
parse = File "" <$!> mconcat <$!> many fileMember parse source = File source <$!> mconcat <$!> many fileMember
fileMember :: Monad m => ParsecT String u m FileBody fileMember :: Monad m => ParsecT String u m FileBody
fileMember = choice fileMember = choice

View file

@ -7,7 +7,7 @@ module Ubc.Parse.Syntax.Struct
where where
-- yay, explicit dependency on ghc -- yay, explicit dependency on ghc
import GHC.Generics (Generic) import GHC.Generics (Generic, Generically(..))
import Control.Monad ((<$!>)) import Control.Monad ((<$!>))
@ -39,7 +39,7 @@ data StructBody = StructBody
, functions :: [Function] , functions :: [Function]
} }
deriving stock (Generic, Show) deriving stock (Generic, Show)
deriving (Semigroup, Monoid) via StructBody deriving (Semigroup, Monoid) via Generically StructBody
parse :: Monad m => ParsecT String u m Struct parse :: Monad m => ParsecT String u m Struct
parse = do parse = do