packages feed

egison-5.0.0: sample/xml-test.egi

--
-- This file has been auto-generated by egison-translator.
--

load "lib/tree/xml.egi"

def xml1 : XMLTree :=
  Node
    "top"
    [ Node
        "middle1"
        [ Leaf "bottom1" "text1"
        , Leaf "bottom1" "text2"
        , Leaf "bottom1" "text3"
        , Node
            "bottom1"
            [ Leaf "bottom2" "text21"
            , Leaf "bottom2" "text100"
            , Leaf "bottom2" "text22" ] ]
    , Node
        "middle2"
        [ Leaf "bottom3" "text31"
        , Leaf "bottom3" "text32"
        , Leaf "bottom3" "text33"
        , Leaf "bottom3" "text31"
        , Leaf "bottom3" "text35" ]
    , Node
        "middle3"
        [ Leaf "bottom4" "text41"
        , Leaf "bottom4" "text42"
        , Node
            "bottom4"
            [ Leaf "bottom2" "text51"
            , Leaf "bottom2" "text100"
            , Leaf "bottom2" "text53" ]
        , Leaf "bottom4" "text44"
        , Leaf "bottom4" "text53" ] ]

-- List up all tags.
-- Expected: ["top", "middle1", "middle2", "middle3", "bottom1", "bottom4"]
matchAll xml1 as xml with
  | descendant (mnode $tag _) _ -> tag

-- List up all nodes which has more than two same child nodes.
-- Expected: [("middle2", Leaf "bottom3" "text31"), ("middle2", Leaf "bottom3" "text31")]
matchAll xml1 as xml with
  | descendant (mnode $tag ($x :: #x :: _)) -> (tag, x)

-- List up all nodes which has more than two same descendant nodes.
-- Expected: [("middle2", Leaf "bottom3" "text31"), ("middle2", Leaf "bottom3" "text31"), ("top", Leaf "bottom2" "text100"), ("top", Leaf "bottom2" "text100")]
matchAll xml1 as xml with
  | descendant (mnode $tag (descendant $x :: descendant #x :: _)) -> (tag, x)