|
1 | | -{-# LANGUAGE CPP #-} |
2 | | -{-# LANGUAGE DeriveFoldable #-} |
3 | | -{-# LANGUAGE DeriveFunctor #-} |
4 | | -{-# LANGUAGE DeriveGeneric #-} |
5 | | -{-# LANGUAGE DeriveTraversable #-} |
6 | | -{-# LANGUAGE MultiWayIf #-} |
7 | | -{-# LANGUAGE OverloadedStrings #-} |
| 1 | +{-# LANGUAGE CPP #-} |
| 2 | +{-# LANGUAGE DeriveFoldable #-} |
| 3 | +{-# LANGUAGE DeriveFunctor #-} |
| 4 | +{-# LANGUAGE DeriveGeneric #-} |
| 5 | +{-# LANGUAGE DeriveTraversable #-} |
| 6 | +{-# LANGUAGE MultiWayIf #-} |
| 7 | +{-# LANGUAGE OverloadedStrings #-} |
8 | 8 | {-# LANGUAGE ScopedTypeVariables #-} |
9 | 9 | -- | License: GPL-3.0-or-later AND BSD-3-Clause |
10 | 10 | -- |
@@ -58,9 +58,9 @@ import qualified Data.Map.Strict as M |
58 | 58 | import qualified Distribution.CabalSpecVersion as C |
59 | 59 | import qualified Distribution.FieldGrammar as C |
60 | 60 | import qualified Distribution.Fields as C |
| 61 | +import qualified Distribution.Fields.ConfVar as C |
61 | 62 | import qualified Distribution.PackageDescription as C |
62 | 63 | import qualified Distribution.Parsec as C |
63 | | -import qualified Distribution.Fields.ConfVar as C |
64 | 64 |
|
65 | 65 | import Cabal.Internal.Glob |
66 | 66 | import Cabal.Internal.Newtypes |
@@ -433,38 +433,48 @@ parseCondTree |
433 | 433 | parseCondTree subparse = go |
434 | 434 | where |
435 | 435 | go fields = do |
436 | | - let (fs, ss) = C.partitionFields fields |
437 | | - (ss', branches) <- second concat . unzip <$> traverse (parseIfs id id) ss |
438 | | - x <- subparse fs ss' |
439 | | - return $ C.CondNode x () branches |
| 436 | + let (fs, ss) = C.partitionFields fields |
| 437 | + (ss', branches) <- second concat . unzip <$> traverse (goIfs id id) ss |
| 438 | + x <- subparse fs ss' |
| 439 | + return $ C.CondNode x () branches |
440 | 440 |
|
441 | | - parseIfs |
| 441 | + goIfs |
442 | 442 | :: ([C.Section C.Position] -> [C.Section C.Position]) |
443 | 443 | -> ([C.CondBranch C.ConfVar () a] -> [C.CondBranch C.ConfVar () a]) |
444 | 444 | -> [C.Section C.Position] |
445 | 445 | -> C.ParseResult ([C.Section C.Position], [C.CondBranch C.ConfVar () a]) |
446 | | - parseIfs accS accB [] = return (accS [], accB []) |
447 | | - parseIfs accS accB (C.MkSection (C.Name _ name) test fields : sections) | name == "if" = do |
448 | | - test' <- C.parseConditionConfVar test |
449 | | - fields' <- go fields |
450 | | - parseElseIfs (C.CondBranch test' fields') accS accB sections |
451 | | - parseIfs accS accB (section : sections) = do |
452 | | - parseIfs (accS . (section :)) accB sections |
453 | | - |
454 | | - parseElseIfs |
| 446 | + goIfs accS accB [] = |
| 447 | + return (accS [], accB []) |
| 448 | + goIfs accS accB (C.MkSection (C.Name pos name) test fields : sections) |
| 449 | + | name == "if" = do |
| 450 | + test' <- C.parseConditionConfVar test |
| 451 | + fields' <- go fields |
| 452 | + goElse (C.CondBranch test' fields') accS accB sections |
| 453 | + | name == "else" = do |
| 454 | + C.parseFailure pos "standalone else" |
| 455 | + return ([], []) |
| 456 | + | name == "elif" = do |
| 457 | + C.parseFailure pos "standalone elif" |
| 458 | + goIfs accS accB sections |
| 459 | + goIfs accS accB (section : sections) = do |
| 460 | + goIfs (accS . (section :)) accB sections |
| 461 | + |
| 462 | + goElse |
455 | 463 | :: (Maybe (C.CondTree C.ConfVar () a) -> C.CondBranch C.ConfVar () a) |
456 | 464 | -> ([C.Section C.Position] -> [C.Section C.Position]) |
457 | 465 | -> ([C.CondBranch C.ConfVar () a] -> [C.CondBranch C.ConfVar () a]) |
458 | 466 | -> [C.Section C.Position] |
459 | 467 | -> C.ParseResult ([C.Section C.Position], [C.CondBranch C.ConfVar () a]) |
460 | | - parseElseIfs make accS accB [] = do |
| 468 | + goElse make accS accB [] = do |
461 | 469 | let condTree = make Nothing |
462 | 470 | return (accS [], accB [condTree]) |
463 | | - parseElseIfs make accS accB (C.MkSection (C.Name pos name) _args _fields : _sections) | name == "else" = do |
464 | | - C.parseFailure pos "else is not supprted yet" |
465 | | - return ([], []) |
466 | | - parseElseIfs make accS accB (C.MkSection (C.Name pos name) _args _fields : _sections) | name == "elif" = do |
467 | | - C.parseFailure pos "elif is not supprted yet" |
468 | | - return ([], []) |
469 | | - parseElseIfs make accS accB (section : sections) = do |
470 | | - parseIfs (accS . (section :)) (accB . (make Nothing :)) sections |
| 471 | + goElse _make _accS _accB (C.MkSection (C.Name pos name) _args _fields : _sections) |
| 472 | + | name == "else" = do |
| 473 | + C.parseFailure pos "else is not supprted yet" |
| 474 | + return ([], []) |
| 475 | + | name == "elif" = do |
| 476 | + C.parseFailure pos "elif is not supprted yet" |
| 477 | + return ([], []) |
| 478 | + goElse make accS accB (section : sections) = do |
| 479 | + let condTree = make Nothing |
| 480 | + goIfs (accS . (section :)) (accB . (condTree :)) sections |
0 commit comments