Skip to content

Commit 896eaf7

Browse files
committed
[ more ] add replicate combinator
1 parent bfa3e4b commit 896eaf7

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

examples/SExp.agda

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module SExp where
22

33
open import Level using (0ℓ)
4-
open import Level.Bounded using (theSet; [_])
4+
open import Level.Bounded using (theSet)
55
open import Data.Char.Base
66
open import Data.String.Base as String using (String)
77

src/Text/Parser.agda

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ private
2626

2727
-- We re-export all of the combinators someone may need, specialised to CHARS
2828

29+
open Level≤ using ([_]) public
2930
open import Text.Parser.Types P hiding (runParser) public
3031
open import Text.Parser.Combinators {P = P} public
3132
open import Text.Parser.Combinators.Numbers {P = P} public

src/Text/Parser/Combinators.agda

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ open import Data.Bool.Base as Bool using (Bool; if_then_else_; not; _∧_)
1414
open import Data.List.Base as List using (_∷_; []; null)
1515
open import Data.List.NonEmpty as List⁺ using (_∷⁺_ ; _∷_)
1616
open import Data.Maybe.Base using (just; nothing; maybe)
17+
open import Data.Nat.Base using (suc; NonZero)
1718
open import Data.Product as Product using (_,_; proj₁; proj₂; uncurry)
1819
open import Data.Sum.Base as Sum using (inj₁; inj₂)
20+
open import Data.Vec.Base as Vec using (_∷_; [])
1921

2022
open import Data.Nat.Properties as Nat using (≤-refl; ≤-trans; <⇒≤; <-trans)
2123
import Data.List.Relation.Unary.Any as Any
@@ -275,3 +277,7 @@ module _ {{𝕊 : Sized Tok Toks}} {{𝕄 : RawMonadPlus M}}
275277
list⁺ = Box.fix (Parser A ⇒ Parser (List⁺ A)) $ λ rec pA
276278
uncurry (λ hd (hd ∷_) ∘′ maybe List⁺.toList [])
277279
<$> (pA <&?> (Box.app rec (box pA)))
280+
281+
replicate : (n : ℕ) {NonZero n} ∀[ Parser A ⇒ Parser (Vec A n) ]
282+
replicate 1 p = Vec.[_] <$> p
283+
replicate (suc n@(suc _)) p = uncurry Vec._∷_ <$> (p <&> box (replicate n p))

0 commit comments

Comments
 (0)