microelm/elm-peg/1.0.0

NOTE: the latest version is 1.0.1

Peg.Test

compareRules : Rule -> Rule -> Result String ()

Compare two PEG grammar rules for equality. Returns Err message if the rules are different, or Ok () if they are the same.

Arguments

  • expected - The expected rule to compare.
  • actual - The actual rule to compare.

Returns

  • Result String () - Err message if the rules are different, or Ok () if they are the same.

Example

compareRules
    (Sequence [MatchLiteral "a", MatchLiteral "b"])
    (Sequence [MatchLiteral "a", MatchLiteral "b"])
--> Ok ()


compareRules
    (Sequence [MatchLiteral "a", MatchLiteral "b"])
    (Sequence [MatchLiteral "a", MatchLiteral "c"])
--> Err "expected: MatchLiteral \"b\", actual: MatchLiteral \"c\" at position 2"
compareRuleLists : List Rule -> List Rule -> Result String ()

Compare two lists of PEG grammar rules for equality. Returns Err message if the rules are different, or Ok () if they are the same.

Arguments

  • expected - The expected list of rules to compare.
  • actual - The actual list of rules to compare.

Returns

  • Result String () - Err message if the rules are different, or Ok () if they are the same.

Example

compareRuleLists
    [ Sequence [MatchLiteral "a", MatchLiteral "b"]
    , Optional (MatchLiteral "c")
    , RuleRef "foo"
    ]
    [ Sequence [MatchLiteral "a", MatchLiteral "b"]
    , Optional (MatchLiteral "c")
    , RuleRef "foo"
    ]
--> Ok ()


compareRuleLists
    [ Sequence [MatchLiteral "a", MatchLiteral "b"]
    , Optional (MatchLiteral "c")
    , RuleRef "foo"
    ]
    [ Sequence [MatchLiteral "a", MatchLiteral "b"]
    , ZeroOrMore (MatchLiteral "c")
    , RuleRef "foo"
    ]
--> Err "expected: Optional (MatchLiteral \"c\"), actual: ZeroOrMore (MatchLiteral \"c\") at position 1"