### HsLet Annotation Example Source: https://github.com/alanz/ghc-exactprint/blob/master/NOTES.md Details the annotations for an 'HsLet' construct, including its source span and associated delta information. This example highlights how indentation and offsets are managed for let bindings. ```haskell ((tests/examples/LayoutLet2.hs:(7,11)-(8,34), CN "HsLet"), (Ann {ann_entry_delta = DP (0,1), ann_delta = 2}, [(G AnnLet, DP (0,1)), (G AnnIn, DP (0,1))])), ``` -------------------------------- ### Example of Indentation Change with offsetValSame Source: https://github.com/alanz/ghc-exactprint/wiki/Explanation-of-calculation-of-offset-calculation. Illustrates how offsetValSame can lead to increased indentation for subsequent lines, as seen with the 'do' block in this example. ```haskell foo x y = do c <- getChar return c ``` ```haskell bar2 x y = do c <- getChar return c ``` -------------------------------- ### Match Annotation Example Source: https://github.com/alanz/ghc-exactprint/blob/master/NOTES.md Illustrates the annotations for a 'Match' construct, showing entry delta and general delta information. This is used to track the source span of the match. ```haskell ((tests/examples/LayoutLet2.hs:(7,1)-(8,34), CN "Match"), (Ann {ann_entry_delta = DP (6,0), ann_delta = 0}, [(G AnnEqual, DP (0,1))])), ``` -------------------------------- ### Unqual Annotation Example Source: https://github.com/alanz/ghc-exactprint/blob/master/NOTES.md Shows the annotations for an 'Unqual' construct, detailing the entry delta and value delta. This annotation is associated with the start of a source span. ```haskell ((tests/examples/LayoutLet2.hs:7:1-3, CN "Unqual"), (Ann {ann_entry_delta = DP (6,0), ann_delta = 0}, (G AnnVal, DP (6,0)))), ``` -------------------------------- ### Unicode Syntax Annotation Example Source: https://github.com/alanz/ghc-exactprint/blob/master/tests/notes.txt Illustrates a specific problem in ApiAnnotation related to unicodeAnn for Annlarrowtail, showing the expected correct annotation. ```haskell unicodeAnn Annlarrowtail = AnnLarrowtailU ``` ```haskell unicodeAnn Annlarrowtail = AnnlarrowtailU ``` -------------------------------- ### Abstract Syntax Tree Representation with Layout Source: https://github.com/alanz/ghc-exactprint/blob/master/NOTES.md This example shows the abstract syntax tree (AST) generated for the Haskell code, including layout annotations. It details the column and line information for each node, demonstrating how indentation is captured. ```text (L {LayoutIn3.hs:(7,1)-(12,85)} (L {LayoutIn3.hs:7:1-3} foo (L {LayoutIn3.hs:7:5} | x (L {LayoutIn3.hs:(7,7)-(12,85)} | = (L {LayoutIn3.hs:(7,9)-(8,50)} | let in where =SYN=====(L {LayoutIn3.hs:7:13-18} | | | (L {LayoutIn3.hs:7:13-18} | | | (L {LayoutIn3.hs:7:13} | x | | (L {LayoutIn3.hs:7:17-18} | ^ = 12 | | (L {LayoutIn3.hs:(7,23)-(8,50)} | | ( ) | (L {LayoutIn3.hs:(7,24)-(8,49)} | let in | =SYN========= (L {LayoutIn3.hs:(7,28)-(8,32)} | | | (L {LayoutIn3.hs:7:28-32} | y | | (L {LayoutIn3.hs:7:28} | ^ = | | (L {LayoutIn3.hs:7:30-32} | | 3 | | (L {LayoutIn3.hs:7:32} | | | |-------------------------------------------------------------------------------- | (L {LayoutIn3.hs:8:28-32} | | | | (L {LayoutIn3.hs:8:28} | z | | (L {LayoutIn3.hs:8:30-32} | | = | | (L {LayoutIn3.hs:8:32} | | 2 | | (L {LayoutIn3.hs:8:37-49} | | | (L {LayoutIn3.hs:8:37-45} | | | (L {LayoutIn3.hs:8:37-41} | | | (L {LayoutIn3.hs:8:37} | x | | (L {LayoutIn3.hs:8:39} | * | | (L {LayoutIn3.hs:8:41} | y | | (L {LayoutIn3.hs:8:43} | * | | (L {LayoutIn3.hs:8:45} | z | | (L {LayoutIn3.hs:8:47} | * | ``` -------------------------------- ### VarPat Annotation Example Source: https://github.com/alanz/ghc-exactprint/blob/master/NOTES.md Demonstrates the annotations for a 'VarPat' (Variable Pattern) construct. It includes entry delta and general delta, indicating the position and offset of the variable pattern in the source code. ```haskell ((tests/examples/LayoutLet2.hs:7:5-7, CN "VarPat"), (Ann {ann_entry_delta = DP (0,1), ann_delta = 4}, [(G AnnVal, DP (0,1))])), ``` -------------------------------- ### Example Haskell Code Snippet Source: https://github.com/alanz/ghc-exactprint/blob/master/NOTES.md A sample Haskell code snippet used to demonstrate delta annotations. This code defines a function 'foo' with a 'let' binding. ```haskell 1 2 123456789012345678901234567890 foo xxx = let a = 1 b = 2 in xxx + a + b ``` -------------------------------- ### Download All Hackage Packages Source: https://github.com/alanz/ghc-exactprint/blob/master/ROUNDTRIP.md An alternative method to download all Hackage packages into a specified working directory. It uses `cabal list` and `cabal get` to fetch packages and then performs initial cleanup. ```shell mkdir hackage-roundtrip-work cd hackage-roundtrip-work cabal list --simple | cut -d' ' -f1 | sort | uniq | xargs -l cabal get ``` -------------------------------- ### GRHS Annotation Example Source: https://github.com/alanz/ghc-exactprint/blob/master/NOTES.md Provides annotations for the 'GRHS' (Guarded Right Hand Side) construct. This snippet shows the entry delta and general delta, with a note about a potential -1 delta value. ```haskell ((tests/examples/LayoutLet2.hs:7:9, CN "GRHS"), (Ann {ann_entry_delta = DP (0,-1), ann_delta = 8}, [])), ``` -------------------------------- ### Set up Test Directory and Previous GHC Version Source: https://github.com/alanz/ghc-exactprint/blob/master/NEW-GHC.md Initialize a temporary directory for new GHC tests and define the previous GHC version for comparison. ```bash $ mkdir /tmp/ghc-tests $ export DESTINATION=/tmp/ghc-tests $ export PREVIOUS=ghc-9.12 ``` -------------------------------- ### Configure and Build ghc-exactprint Source: https://github.com/alanz/ghc-exactprint/blob/master/ROUNDTRIP.md Configure the project with the roundtrip feature and enable tests. Then, build the project to generate necessary executables. ```shell cabal configure -froundtrip --enable-tests cabal build ``` -------------------------------- ### Prepare Hackage Packages for Roundtrip Testing Source: https://github.com/alanz/ghc-exactprint/blob/master/ROUNDTRIP.md Create a working directory and use the prepare-hackage executable to download and preprocess packages from Hackage. This includes untabifying files and removing trailing whitespace. ```shell mkdir hackage-roundtrip-work cabal exec prepare-hackage ``` -------------------------------- ### Build Static Website for Roundtrip Failures Source: https://github.com/alanz/ghc-exactprint/blob/master/ROUNDTRIP.md Generate a static web site to view the results of the roundtrip tests, including detailed information about processed files and failures. ```shell cabal exec static ``` -------------------------------- ### Rename Backup Files to .hs Extension Source: https://github.com/alanz/ghc-exactprint/blob/master/NEW-GHC.md Convert `cp` backup files (e.g., `A.hs.~1~`) into standard Haskell files by renaming them to have a `.hs` extension. Requires the `mmv` utility. ```bash $ cd tests/examples/ghc914-copied $ mmv "*.hs.~*~" "#1.#2.hs" ``` -------------------------------- ### Identify and Copy New GHC Test Files Source: https://github.com/alanz/ghc-exactprint/blob/master/NEW-GHC.md Use git diff to find Haskell test files from the previous GHC version and copy them to the destination directory. ```bash git diff --name-only $PREVIOUS | grep testsuite/tests | grep "\.hs" ``` ```bash cp -pv --parents `git diff --name-only $PREVIOUS | grep testsuite/tests | grep "\.hs"` $DESTINATION ``` -------------------------------- ### mkImport Function Signature and Implementation Source: https://github.com/alanz/ghc-exactprint/blob/master/tests/notes.txt Shows the transformation of the mkImport function signature and its implementation for handling CCallConv.PrimCallConv. ```haskell mkImport :: Located CCallConv -> Located Safety -> (Located StringLiteral, Located RdrName, LHsSigType RdrName) -> P (HsDecl RdrName) mkImport (L lc cconv) (L ls safety) (L loc (StringLiteral esrc entity), v, ty) | cconv == PrimCallConv = do let funcTarget = CFunction (StaticTarget esrc entity Nothing True) importSpec = CImport (L lc PrimCallConv) (L ls safety) Nothing funcTarget (L loc (unpackFS entity)) ``` ```haskell (L loc esrc) ``` -------------------------------- ### Simple Let Expression in Haskell Source: https://github.com/alanz/ghc-exactprint/blob/master/NOTES.md This is a basic Haskell function demonstrating a let expression. It shows how the layout of the let/in structure should adjust if variable names change length. ```haskell module LayoutLet2 where -- Simple let expression, rename xxx to something longer or shorter -- and the let/in layout should adjust accordingly -- In this case the tokens for xxx + a + b should also shift out foo xxx = let a = 1 b = 2 in xxx + a + b ``` -------------------------------- ### Run Roundtrip Test on Hackage Packages Source: https://github.com/alanz/ghc-exactprint/blob/master/ROUNDTRIP.md Execute the roundtrip test on a list of unpacked Hackage package directories. The `-N2` option is recommended to manage memory usage. ```shell cabal exec roundtrip -- clean time cabal exec roundtrip -- ./hackage-roundtrip-work/* +RTS -N2 cabal exec roundtrip -- failures +RTS -N2 ``` -------------------------------- ### Copy Haskell Files to ghc914-copied Directory Source: https://github.com/alanz/ghc-exactprint/blob/master/NEW-GHC.md Copy all Haskell files from the temporary test directory into a new directory for GHC 9.14, creating numbered backups for name clashes. ```bash $ mkdir tests/examples/ghc914-copied $ find /tmp/ghc-tests -iname "*.hs" | xargs cp --backup=numbered -t ./tests/examples/ghc914-copied/ ``` -------------------------------- ### Haskell Code with Layout Annotations Source: https://github.com/alanz/ghc-exactprint/blob/master/NOTES.md This Haskell code snippet illustrates layout rules and indentation changes within a 'let' binding. It shows how comments and nested structures affect the abstract syntax tree representation. ```haskell module LayoutIn3 where --Layout rule applies after 'where','let','do' and 'of' --In this Example: rename 'x' after 'let' to 'anotherX'. foo x = let x = 12 in (let y = 3 z = 2 in x * y * z * w) where y = 2 --there is a comment. w = x where x = let y = 5 in y + 3 ``` -------------------------------- ### AST Representation of LayoutLet2.hs Source: https://github.com/alanz/ghc-exactprint/blob/master/NOTES.md This snippet shows the abstract syntax tree (AST) representation of a Haskell code snippet from LayoutLet2.hs, illustrating nested structures and source spans. ```haskell (Unqual {OccName: b})) (False))) [] (Nothing) (GRHSs [ (L {tests/examples/LayoutLet2.hs:8:17-19} (GRHS [] (L {tests/examples/LayoutLet2.hs:8:19} (HsOverLit {HsOverLit:2}))))] (EmptyLocalBinds))))] [] (PlaceHolder) (FromSource)) (WpHole) (PlaceHolder) []))]} [])) (L {tests/examples/LayoutLet2.hs:8:24-34} (OpApp (L {tests/examples/LayoutLet2.hs:8:24-30} (OpApp (L {tests/examples/LayoutLet2.hs:8:24-26} (HsVar (Unqual {OccName: xxx}))) (L {tests/examples/LayoutLet2.hs:8:28} (HsVar (Unqual {OccName: +}))) (PlaceHolder) (L {tests/examples/LayoutLet2.hs:8:30} (HsVar (Unqual {OccName: a}))))) (L {tests/examples/LayoutLet2.hs:8:32} (HsVar (Unqual {OccName: +}))) (PlaceHolder) (L {tests/examples/LayoutLet2.hs:8:34} (HsVar (Unqual {OccName: b})))))))))] (EmptyLocalBinds))))] [] (PlaceHolder) (FromSource)) (WpHole) (PlaceHolder) [])))] (Nothing) (Nothing))) ``` -------------------------------- ### Normalized AST Structure with Layout Annotations Source: https://github.com/alanz/ghc-exactprint/blob/master/NOTES.md This snippet displays a normalized and de-duplicated AST structure, highlighting layout annotations and source spans. It serves as a reference for understanding code structure and indentation. ```text (L {LayoutLet2.hs:(7,1)-(8,34)} (L {LayoutLet2.hs:7:1-3} foo (L {LayoutLet2.hs:7:5-7} | xxx (L {LayoutLet2.hs:(7,9)-(8,34)} | | = (L {LayoutLet2.hs:(7,11)-(8,34)} | | let in ===SYN=====(L {LayoutLet2.hs:(7,15)-(8,19)} | | ^ (L {LayoutLet2.hs:7:15-19} | | | (L {LayoutLet2.hs:7:15} | | | a (L {LayoutLet2.hs:7:17-19} | | | ^ = (L {LayoutLet2.hs:7:19} | | | | 1 -------------------------------------------- (L {LayoutLet2.hs:8:15-19} | | | | (L {LayoutLet2.hs:8:15} | | | b (L {LayoutLet2.hs:8:17-19} | | | | (L {LayoutLet2.hs:8:19} | | | | (L {LayoutLet2.hs:8:24-34} | | | (L {LayoutLet2.hs:8:24-30} | | | (L {LayoutLet2.hs:8:24-26} | | | (L {LayoutLet2.hs:8:28} | | | (L {LayoutLet2.hs:8:30} | | | (L {LayoutLet2.hs:8:32} | | | (L {LayoutLet2.hs:8:34} | | | ``` -------------------------------- ### Configure Test Directories for New GHC Version Source: https://github.com/alanz/ghc-exactprint/blob/master/NEW-GHC.md Modify the `testDirs` list in `Tests.hs` to include test directories relevant to the new GHC version, such as 'ghc96-copied'. ```haskell -- | Directories to automatically find roundtrip tests testDirs :: [FilePath] testDirs = case ghcVersion of GHC710 -> ["ghc710-only","ghc710"] GHC80 -> ["ghc710", "ghc80"] GHC82 -> ["ghc710", "ghc80", "ghc82"] -- GHC84 -> ["ghc84", "ghc84-copied"] GHC96 -> ["ghc96-copied"] -- GHC84 -> ["ghc84" ``` -------------------------------- ### AST Representation of Let Expression Source: https://github.com/alanz/ghc-exactprint/blob/master/NOTES.md The Abstract Syntax Tree (AST) representation for the provided Haskell let expression. This illustrates the nested structure and location information captured for each element. ```haskell (L {tests/examples/LayoutLet2.hs:1:1} (HsModule (Just (L {tests/examples/LayoutLet2.hs:1:8-17} {ModuleName: LayoutLet2})) (Nothing) [] [ (L {tests/examples/LayoutLet2.hs:(7,1)-(8,34)} (ValD (FunBind (L {tests/examples/LayoutLet2.hs:7:1-3} (Unqual {OccName: foo})) (False) (MG [ (L {tests/examples/LayoutLet2.hs:(7,1)-(8,34)} (Match (Just ((,) (L {tests/examples/LayoutLet2.hs:7:1-3} (Unqual {OccName: foo})) (False))) [ (L {tests/examples/LayoutLet2.hs:7:5-7} (VarPat (Unqual {OccName: xxx})))] (Nothing) (GRHSs [ (L {tests/examples/LayoutLet2.hs:(7,9)-(8,34)} (GRHS [] (L {tests/examples/LayoutLet2.hs:(7,11)-(8,34)} (HsLet (HsValBinds (ValBindsIn {Bag(Located (HsBind RdrName)): [ (L {tests/examples/LayoutLet2.hs:7:15-19} (FunBind (L {tests/examples/LayoutLet2.hs:7:15} (Unqual {OccName: a})) (False) (MG [ (L {tests/examples/LayoutLet2.hs:7:15-19} (Match (Just ((,) (L {tests/examples/LayoutLet2.hs:7:15} (Unqual {OccName: a})) (False))) [] (Nothing) (GRHSs [ (L {tests/examples/LayoutLet2.hs:7:17-19} (GRHS [] (L {tests/examples/LayoutLet2.hs:7:19} (HsOverLit {HsOverLit:1}))))] (EmptyLocalBinds))))] [] (PlaceHolder) (FromSource)) (WpHole) (PlaceHolder) [])), (L {tests/examples/LayoutLet2.hs:8:15-19} (FunBind (L {tests/examples/LayoutLet2.hs:8:15} (Unqual {OccName: b})) (False) (MG [ (L {tests/examples/LayoutLet2.hs:8:15-19} (Match (Just ((,) (L {tests/examples/LayoutLet2.hs:8:15} (Unqual {OccName: b})) (False))) [] (Nothing) (GRHSs [ (L {tests/examples/LayoutLet2.hs:8:17-19} (GRHS [] (L {tests/examples/LayoutLet2.hs:8:19} (HsOverLit {HsOverLit:2}))))] (EmptyLocalBinds))))] [] (PlaceHolder) (FromSource)) (WpHole) (PlaceHolder) []) ] )) (HsEmptyLocalBinds)) (HsExpr ( (L {tests/examples/LayoutLet2.hs:8:23-34} (OpApp (L {tests/examples/LayoutLet2.hs:8:23-26} (HsVar (Unqual {OccName: xxx}))) (L {tests/examples/LayoutLet2.hs:8:27-28} {(-)}) (L {tests/examples/LayoutLet2.hs:8:29-34} (OpApp (L {tests/examples/LayoutLet2.hs:8:29-30} (HsVar (Unqual {OccName: a}))) (L {tests/examples/LayoutLet2.hs:8:31-32} {(+))}) (L {tests/examples/LayoutLet2.hs:8:33-34} (HsVar (Unqual {OccName: b})))))))))))] (EmptyLocalBinds))))] (Nothing) (Nothing))) ``` -------------------------------- ### Whitespace Cleanup for Haskell Files Source: https://github.com/alanz/ghc-exactprint/blob/master/ROUNDTRIP.md Perform additional whitespace cleanup on Haskell files within the hackage-roundtrip-work directory using a custom script and remove backup files. ```shell cd hackage-roundtrip-work/ ../emacs-ws-cleanup.sh find . -iname "*.hs~" | xargs rm ``` -------------------------------- ### Layout Information Representation Source: https://github.com/alanz/ghc-exactprint/blob/master/NOTES.md This snippet visually represents layout information, including column offsets and indentation levels, using a table-like structure with references to source code locations. ```text | (L {LayoutIn3.hs:8:49} | w| =SYN==(L {LayoutIn3.hs:(8,60)-(12,85)}======= | (L {LayoutIn3.hs:8:60} | y | (L {LayoutIn3.hs:8:62-64} | ^ | (L {LayoutIn3.hs:8:64} | | -------------------------------------------------------------------------------------------- (L {LayoutIn3.hs:(10,60)-(12,85)} | | | (L {LayoutIn3.hs:10:60} | w | (L {LayoutIn3.hs:(10,62)-(12,85)} | = | (L {LayoutIn3.hs:10:64} | x -------------------------------------------------------------------------------------- | (L {LayoutIn3.hs:12:64-85} | | (L {LayoutIn3.hs:12:64-85} | | (L {LayoutIn3.hs:12:64} | | (L {LayoutIn3.hs:12:66-85} | | (L {LayoutIn3.hs:12:68-85} | | (L {LayoutIn3.hs:12:72-76} | | (L {LayoutIn3.hs:12:72} | | (L {LayoutIn3.hs:12:74-76} | | (L {LayoutIn3.hs:12:76} | | (L {LayoutIn3.hs:12:81-85} | | (L {LayoutIn3.hs:12:81} | | (L {LayoutIn3.hs:12:83} | | (L {LayoutIn3.hs:12:85} | ``` -------------------------------- ### Clean MSDOS File Endings in Roundtrip Work Directory Source: https://github.com/alanz/ghc-exactprint/blob/master/ROUNDTRIP.md Convert MSDOS line endings to Unix-style line endings for Haskell files within the roundtrip-work directory. This ensures consistent file formatting. ```shell cd roundtrip-work find . -iname "*.hs" | grep -v "'" | xargs fromdos -b -d ``` -------------------------------- ### Test Failure Counts Source: https://github.com/alanz/ghc-exactprint/blob/master/tests/notes.txt Provides a summary of test results, including the total number of cases, tried cases, errors, and failures. ```haskell Cases: 848 Tried: 848 Errors: 2 Failures: 6 Counts {cases = 848, tried = 848, errors = 2, failures = 6} ``` -------------------------------- ### Remove 'should_fail' Directories Source: https://github.com/alanz/ghc-exactprint/blob/master/NEW-GHC.md Clean up the copied test files by removing any directories named 'should_fail'. ```bash find /tmp/ghc-tests/ -iname "should_fail" | xargs rm -fr ``` -------------------------------- ### Remove Files with Preprocessor Directives Source: https://github.com/alanz/ghc-exactprint/blob/master/ROUNDTRIP.md Remove Haskell files containing specific preprocessor directives like '#define' or '#include', as well as other patterns that might interfere with the roundtrip process. ```shell find . -iname "*.hs" -print0 | xargs -0 grep '^# *define' --files-with-matches | xargs rm find . -iname "*.hs" -print0 | xargs -0 grep '^# *include' --files-with-matches | xargs rm find . -iname "*.hs" -print0 | xargs -0 grep 'happyFail' --files-with-matches | xargs rm find . -iname "*.hs" -print0 | xargs -0 grep '^{-# LINE' --files-with-matches | xargs rm find . -iname "*.hs" -print0 | xargs -0 grep '^#! */' --files-with-matches | xargs rm find . -iname "*.hs" -print0 | xargs -0 grep '__FILE__' --files-with-matches | xargs rm find . -iname "*.hs" -print0 | xargs -0 grep '__LINE__' -- --files-with-matches | xargs rm find . -iname "*.hs" -print0 | xargs -0 grep '__TIME__' --files-with-matches | xargs rm find . -iname "*.hs" -print0 | xargs -0 grep '__DATE__' --files-with-matches | xargs rm find . -iname "*.hs" -print0 | xargs -0 grep '^#line' --files-with-matches | xargs rm ``` -------------------------------- ### AST with Modified Variable Name Length Source: https://github.com/alanz/ghc-exactprint/blob/master/NOTES.md This snippet demonstrates the impact of changing a variable name's length ('xxx' to 'xxxlonger') on the AST structure and layout. It shows how GHC Exactprint adjusts to maintain correct indentation and formatting. ```text (L {LayoutLet2.hs:(7,1)-(8,34)} (L {LayoutLet2.hs:7:1-3} foo (L {LayoutLet2.hs:7:5-7} | xxxlonger (L {LayoutLet2.hs:(7,9)-(8,34)} | | ...... = (L {LayoutLet2.hs:(7,11)-(8,34)} | | ...... let in ===SYN=====(L {LayoutLet2.hs:(7,15)-(8,19)} | | ...... ^ (L {LayoutLet2.hs:7:15-19} | | ...... | (L {LayoutLet2.hs:7:15} | | ...... | a (L {LayoutLet2.hs:7:17-19} | | ...... | ^ = (L {LayoutLet2.hs:7:19} | | ...... | | 1 -------------------------------------------- (L {LayoutLet2.hs:8:15-19} | | ...... | | (L {LayoutLet2.hs:8:15} | | ...... | b (L {LayoutLet2.hs:8:17-19} | | ...... | | (L {LayoutLet2.hs:8:19} | | ...... | | ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.