aihc-parser 7.0.0.0 → 7.1.0.0
raw patch · 8 files changed
+83/−15 lines, 8 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Aihc.Parser.Syntax: applyExtensionSettings :: [Extension] -> [ExtensionSetting] -> [Extension]
Files
- CHANGELOG.md +18/−0
- aihc-parser.cabal +1/−1
- docs/aihc-parser-supported-extensions.md +6/−5
- src/Aihc/Parser/Lex.hs +1/−1
- src/Aihc/Parser/Syntax.hs +21/−4
- src/Aihc/Parser/Types.hs +2/−2
- test/Spec.hs +15/−1
- test/Test/ExtensionMapping/Suite.hs +19/−1
CHANGELOG.md view
@@ -6,6 +6,24 @@ ## [Unreleased] +## [7.1.0.0] - 2026-11-27++### Fixed++- `effectiveExtensions` applies only the implications of the extension that+ a setting enables, as GHC does. Before, each enable applied the+ implications of all extensions in the set again. Thus, with+ `TypeFamilies`, `NoMonoLocalBinds`, and then `ViewPatterns`,+ `MonoLocalBinds` was on again. Now it stays off.+- The lexer applies the `LANGUAGE` pragmas of a module header in source+ order. Before, it applied them in reverse order. Thus, with `MagicHash`+ and then `NoMagicHash`, `MagicHash` was on.++### Added++- `applyExtensionSettings` applies extension settings to a set of+ extensions from left to right, with the implications of each enable.+ ## [7.0.0.0] - 2026-11-27 ### Added
aihc-parser.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.8 name: aihc-parser-version: 7.0.0.0+version: 7.1.0.0 build-type: Simple license: Unlicense license-file: LICENSE
docs/aihc-parser-supported-extensions.md view
@@ -2,8 +2,8 @@ ## Summary -- Total Extensions: 84-- Supported: 84+- Total Extensions: 85+- Supported: 85 - In Progress: 0 ## Extension Status@@ -51,8 +51,9 @@ | LinearTypes | 🟢 | 15/15 | | MagicHash | 🟢 | 24/24 | | MultiParamTypeClasses | 🟢 | 24/24 |-| MultiWayIf | 🟢 | 22/22 |+| MultiWayIf | 🟢 | 23/23 | | MultilineStrings | 🟢 | 6/6 |+| NPlusKPatterns | 🟢 | 4/4 | | NamedFieldPuns | 🟢 | 6/6 | | NamedWildCards | 🟢 | 5/5 | | NegativeLiterals | 🟢 | 1/1 |@@ -76,13 +77,13 @@ | RequiredTypeArguments | 🟢 | 4/4 | | RoleAnnotations | 🟢 | 7/7 | | Safe | 🟢 | 2/2 |-| ScopedTypeVariables | 🟢 | 19/19 |+| ScopedTypeVariables | 🟢 | 20/20 | | StandaloneDeriving | 🟢 | 18/18 | | StandaloneKindSignatures | 🟢 | 12/12 | | StarIsType | 🟢 | 4/4 | | TemplateHaskell | 🟢 | 69/69 | | TemplateHaskellQuotes | 🟢 | 14/14 |-| TransformListComp | 🟢 | 18/18 |+| TransformListComp | 🟢 | 20/20 | | TupleSections | 🟢 | 4/4 | | TypeAbstractions | 🟢 | 5/5 | | TypeApplications | 🟢 | 15/15 |
src/Aihc/Parser/Lex.hs view
@@ -97,7 +97,7 @@ lexTextWithExtensions True sourceName effectiveExts input where headerSettings = readModuleHeaderExtensions input- effectiveExts = applyImpliedExtensions (foldr applyExtensionSetting baseExts headerSettings)+ effectiveExts = applyExtensionSettings (applyImpliedExtensions baseExts) headerSettings lexTextWithExtensions :: Bool -> FilePath -> [Extension] -> Text -> [LexToken] lexTextWithExtensions enableModuleLayout sourceName exts input =
src/Aihc/Parser/Syntax.hs view
@@ -121,6 +121,7 @@ ValueDecl (..), allKnownExtensions, applyExtensionSetting,+ applyExtensionSettings, applyImpliedExtensions, binderHeadForm, binderHeadName,@@ -721,10 +722,26 @@ -- immediately after each enable, so a later explicit disable can override an -- implication instead of having it resurrected by a final implication pass. effectiveExtensions :: LanguageEdition -> [ExtensionSetting] -> [Extension]-effectiveExtensions edition = List.foldl' applyOne (languageEditionExtensions edition)- where- applyOne extensions setting@(EnableExtension _) = applyImpliedExtensions (applyExtensionSetting setting extensions)- applyOne extensions setting@(DisableExtension _) = applyExtensionSetting setting extensions+effectiveExtensions edition = applyExtensionSettings (languageEditionExtensions edition)++-- | Apply extension settings left to right to a set of extensions, as GHC+-- does. To enable an extension also applies the implications of that+-- extension, and the implications of each extension that they enable. It+-- does not apply the implications of the other extensions in the set. Thus,+-- with @TypeFamilies@, @NoMonoLocalBinds@, and then @ViewPatterns@,+-- @MonoLocalBinds@ stays off. To disable an extension does not change its+-- implications.+applyExtensionSettings :: [Extension] -> [ExtensionSetting] -> [Extension]+applyExtensionSettings = List.foldl' (flip applyWithImplications)++-- | Apply one extension setting and, for an enable, the implications of the+-- extension that it enables.+applyWithImplications :: ExtensionSetting -> [Extension] -> [Extension]+applyWithImplications setting extensions =+ case setting of+ EnableExtension ext ->+ List.foldl' (flip applyWithImplications) (applyExtensionSetting setting extensions) (Map.findWithDefault [] ext impliedExtensionMap)+ DisableExtension _ -> applyExtensionSetting setting extensions -- | Source location metadata for parsed syntax, such as the token range for -- @map@ in @map f xs@.
src/Aihc/Parser/Types.hs view
@@ -42,7 +42,7 @@ readModuleHeaderExtensions, scanAllTokens, )-import Aihc.Parser.Syntax (Extension, ExtensionSet, SourceSpan, applyExtensionSetting, applyImpliedExtensions, mkExtensionSet, sourceSpanEndCol, sourceSpanEndLine, sourceSpanEndOffset, sourceSpanSourceName, sourceSpanStartCol, sourceSpanStartLine, sourceSpanStartOffset, pattern SourceSpan)+import Aihc.Parser.Syntax (Extension, ExtensionSet, SourceSpan, applyExtensionSettings, applyImpliedExtensions, mkExtensionSet, sourceSpanEndCol, sourceSpanEndLine, sourceSpanEndOffset, sourceSpanSourceName, sourceSpanStartCol, sourceSpanStartLine, sourceSpanStartOffset, pattern SourceSpan) import Control.DeepSeq (NFData (..)) import Data.Text (Text) import Data.Text qualified as T@@ -202,7 +202,7 @@ Nothing where headerSettings = readModuleHeaderExtensions input- effectiveExts = applyImpliedExtensions (foldr applyExtensionSetting baseExts headerSettings)+ effectiveExts = applyExtensionSettings (applyImpliedExtensions baseExts) headerSettings -- | Create a TokStream from pre-lexed tokens (for testing/compatibility). -- Layout tokens must already be inserted in the token list.
test/Spec.hs view
@@ -7,7 +7,7 @@ import Aihc.Cpp (resultOutput) import Aihc.Parser import Aihc.Parser.Internal.Common (TokParser, lazy)-import Aihc.Parser.Lex (LexToken (..), LexTokenKind (..), lexTokens, lexTokensWithExtensions)+import Aihc.Parser.Lex (LexToken (..), LexTokenKind (..), lexModuleTokensWithExtensions, lexTokens, lexTokensWithExtensions) import Aihc.Parser.Parens (addDeclParens, addExprParens, addTypeParens) import Aihc.Parser.Pretty () import Aihc.Parser.Shorthand (Shorthand (shorthand))@@ -246,6 +246,7 @@ testCase "skips mid-stream shebang lines as trivia" test_midStreamShebangIsSkipped, testCase "does not misclassify line-start #) as a directive" test_lineStartHashTokenIsNotDirective, testCase "lexes overloaded labels as single tokens" test_overloadedLabelLexesAsSingleToken,+ testCase "applies module header LANGUAGE pragmas in source order" test_headerPragmasApplyInSourceOrder, testCase "preserves bundled export wildcard position" test_bundledExportWildcardPosition, testCase "parses associated data family operator names" test_associatedDataFamilyOperatorName, testCase "parses infix associated data family operator names" test_associatedDataFamilyInfixOperatorName,@@ -497,6 +498,19 @@ LexToken {lexTokenKind = TkEOF} ] -> pure () other -> assertFailure ("expected line-start #) to lex as an unboxed tuple token, got: " <> show other)++test_headerPragmasApplyInSourceOrder :: Assertion+test_headerPragmasApplyInSourceOrder =+ case [kind | LexToken {lexTokenKind = kind} <- lexModuleTokensWithExtensions [] source, isMagicHashCandidate kind] of+ [TkVarId "y", TkVarSym "#"] -> pure ()+ other -> assertFailure ("expected NoMagicHash to win over the earlier MagicHash, got: " <> show other)+ where+ source = "{-# LANGUAGE MagicHash #-}\n{-# LANGUAGE NoMagicHash #-}\nmodule M where\nx = y#\n"+ isMagicHashCandidate kind =+ case kind of+ TkVarId name -> name == "y" || name == "y#"+ TkVarSym _ -> True+ _ -> False test_overloadedLabelLexesAsSingleToken :: Assertion test_overloadedLabelLexesAsSingleToken =
test/Test/ExtensionMapping/Suite.hs view
@@ -4,6 +4,7 @@ where import Aihc.Parser.Syntax qualified as Syntax+import Control.Monad (unless, when) import Data.List (intercalate, sort) import Data.Maybe (isNothing) import Data.Set qualified as Set@@ -27,8 +28,25 @@ testCase "Haskell2010 extensions match GHC" test_haskell2010Extensions, testCase "GHC2021 extensions match GHC" test_ghc2021Extensions, testCase "GHC2024 extensions match GHC" test_ghc2024Extensions- ]+ ],+ testCase "a later enable does not apply the implications of an earlier one again" test_laterEnableKeepsImpliedExtensionOff ]++-- | GHC applies only the implications of the extension that a setting+-- enables. Thus, a later enable does not turn on an extension that an+-- earlier setting turned off. This is the pragma order of streamly-core.+test_laterEnableKeepsImpliedExtensionOff :: IO ()+test_laterEnableKeepsImpliedExtensionOff = do+ let settings =+ [ Syntax.EnableExtension Syntax.TypeFamilies,+ Syntax.DisableExtension Syntax.MonoLocalBinds,+ Syntax.EnableExtension Syntax.ViewPatterns+ ]+ extensions = Syntax.effectiveExtensions Syntax.Haskell2010Edition settings+ when (Syntax.MonoLocalBinds `elem` extensions) $+ assertFailure ("MonoLocalBinds is on after " <> show settings)+ unless (Syntax.KindSignatures `elem` extensions) $+ assertFailure ("KindSignatures is off after " <> show settings) test_cabalKnownExtensionCoverage :: IO () test_cabalKnownExtensionCoverage = do