source code congruency

This commit is contained in:
crumbtoo
2023-12-29 19:02:37 -07:00
parent c7aed71db5
commit baf9d79285
3 changed files with 23 additions and 12 deletions

View File

@@ -1,13 +1,17 @@
{-# LANGUAGE OverloadedStrings, LambdaCase #-}
module CoreSyntax
(
( ProgramSrc(..)
, (~==)
, congruentSrc
)
where
----------------------------------------------------------------------------------
import Core.Syntax
import Compiler.JustRun (justParseSrc)
import Control.Arrow ((>>>), (&&&))
import Control.Monad
import Data.List (intersperse)
import Data.Coerce (coerce)
import Data.Text (Text)
import Data.Text qualified as T
import Test.QuickCheck
@@ -192,3 +196,14 @@ ws = elements [""," ", " "]
ws1 :: (IsString a) => Gen a
ws1 = elements [" ", " "]
----------------------------------------------------------------------------------
-- | Two bodies of source code are considered congruent iff the parser produces
-- identical ASTs for both.
(~==) :: ProgramSrc -> ProgramSrc -> Bool
(~==) = (==) `on` (justParseSrc . T.unpack . coerce)
-- | Prefix synonym for @(~==)@
congruentSrc :: ProgramSrc -> ProgramSrc -> Bool
congruentSrc = (~==)