Skip to content

Commit

Permalink
AST rework 1/2
Browse files Browse the repository at this point in the history
Fixed wrong assumption about defparams in AST
Refactored AST
Fixed garbageGeneration
Refactored garbageGeneration parameters
Fixed prettyprinter (new AST and unnoticed bugs)
Removed useless parameter in PrettyIdent as it was ignored anyways when different than softline
Added comments in prettyprinter
Added `include support to lexer and prepared for partial `define support
Reworked `line support in lexer
Token position report the whole sequence of `include, `define and `line
Parser's consify and unconst functions are moved to Utils
Fixed parser
Removed part of the parser's dangling else handling as it is wrong and will need to be fixed later
Fixed mutation

Made prettyprinter and parser follow the list order of the AST instead of reversing some parts for no apparent reason
Made prettyprinter give up splitting lines when indentation is over max line length
  • Loading branch information
qcorradi committed Feb 27, 2024
1 parent 474d8fd commit 62fa687
Show file tree
Hide file tree
Showing 14 changed files with 4,700 additions and 4,651 deletions.
1,063 changes: 696 additions & 367 deletions src/Verismith/Config.hs

Large diffs are not rendered by default.

26 changes: 0 additions & 26 deletions src/Verismith/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ module Verismith.Utils
foldrMap1,
foldrMap1',
foldrMapM1,
rmapM,
nermapM,
rmap',
rmap,
liftA4,
liftA5,
mkpair,
uncurry3,
safe,
Expand All @@ -32,7 +26,6 @@ import Control.Applicative
import Data.ByteString (ByteString, pack)
import Data.ByteString.Builder (byteStringHex, toLazyByteString)
import qualified Data.ByteString.Lazy as L
import Data.List (foldl')
import Data.List.NonEmpty (NonEmpty (..), (<|))
import qualified Data.List.NonEmpty as NE
import Data.Text (Text)
Expand All @@ -54,25 +47,6 @@ foldrMap1' d f g = nonEmpty d (foldrMap1 f g)
foldrMapM1 :: (Applicative m, Monad m) => (a -> m b) -> (a -> b -> m b) -> NonEmpty a -> m b
foldrMapM1 f g (h :| t) = nonEmpty (f h) (\x -> foldrMapM1 f g x >>= g h) t

rmapM :: Monad m => (a -> m b) -> [a] -> m [b]
rmapM f = foldl' (\acc e -> do y <- acc; x <- f e; return $ x : y) $ return []

nermapM :: Monad m => (a -> m b) -> NonEmpty a -> m (NonEmpty b)
nermapM f (x :| l) =
foldl' (\acc e -> do y <- acc; x <- f e; return $ x <| y) ((:| []) <$> f x) l

rmap' :: (a -> b) -> [b] -> [a] -> [b]
rmap' f = foldl' (\acc e -> f e : acc)

rmap :: (a -> b) -> [a] -> [b]
rmap f = rmap' f []

liftA4 :: Applicative f => (a -> b -> c -> d -> e) -> f a -> f b -> f c -> f d -> f e
liftA4 f a b c d = liftA3 f a b c <*> d

liftA5 :: Applicative f => (a -> b -> c -> d -> e -> z) -> f a -> f b -> f c -> f d -> f e -> f z
liftA5 f a b c d e = liftA4 f a b c d <*> e

mkpair :: Applicative f => f a -> f b -> f (a, b)
mkpair = liftA2 (,)

Expand Down
3 changes: 0 additions & 3 deletions src/Verismith/Verilog2005.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@ module Verismith.Verilog2005
( parseVerilog2005,
genSource,
runGarbageGeneration,
GeneratorOpts,
NumberProbability,
CategoricalProbability,
defGeneratorOpts,
Verilog2005 (..),
SourceInfo (..),
renameTopItems,
)
where
Expand Down
Loading

0 comments on commit 62fa687

Please sign in to comment.