def parse_cut(cube, cut_expr)
      p = mdx_parser.parseExpression(cut_expr)

      case p
      when org.olap4j.mdx.CallNode
        case p.getOperatorName
        when '{}'
          # check that the set contains only Members of a single dimension level
          set_members = p.getArgList.map do |id_node|
            get_member(cube, unparse_node(id_node))
          end

          if set_members.any?(&:nil?)
            error!('Illegal cut. Unknown member in cut set', 400)
          end

          ls = set_members.map(&:raw_level).uniq
          error!('Illegal cut: ' + cut_expr, 400) unless ls.size == 1
          { level: ls.first, cut: unparse_node(p), type: :set, set_members: set_members }
        when '()'
          # check that the range contains a valid range

          unless p.getArgList.first.is_a?(org.olap4j.mdx.CallNode) \
            && (p.getArgList.first.getOperatorName == ':')
            error!('Illegal cut: ' + cut_expr, 400)
          end

          ls = p.getArgList.first.getArgList.map do |id_node|
            get_member(cube, unparse_node(id_node)).raw_level
          end.uniq

          error!('Illegal cut: ' + cut_expr, 400) unless ls.size == 1

          { level: ls.first, cut: unparse_node(p), type: :range }
        else
          error!('Illegal cut: ' + cut_expr, 400)
        end
      when org.olap4j.mdx.IdentifierNode

        # does cut_expr look like a NamedSet?
        s = get_named_set(cube, cut_expr)
        return { level: nil, cut: cut_expr, type: :named_set } unless s.nil?

        # if `cut_expr` looks like a member, check that it's level is
        # equal to `level`
        m = get_member(cube, cut_expr)

        if m.nil?
          error!("Illegal cut: #{cut_expr} — Member does not exist", 400)
        end

        { level: m.raw_level, cut: cut_expr, type: :member }
      else
        error!('Illegal cut: ' + cut_expr, 400)
      end
    end
def parse_cut(cube, cut_expr)
      p = mdx_parser.parseExpression(cut_expr)

      case p
      when org.olap4j.mdx.CallNode
        case p.getOperatorName
        when '{}'
          # check that the set contains only Members of a single dimension level
          set_members = p.getArgList.map do |id_node|
            get_member(cube, unparse_node(id_node))
          end

          if set_members.any?(&:nil?)
            error!('Illegal cut. Unknown member in cut set', 400)
          end

          ls = set_members.map(&:raw_level).uniq
          error!('Illegal cut: ' + cut_expr, 400) unless ls.size == 1
          { level: ls.first, cut: unparse_node(p), type: :set, set_members: set_members }
        when '()'
          # check that the range contains a valid range

          unless p.getArgList.first.is_a?(org.olap4j.mdx.CallNode) \
            && (p.getArgList.first.getOperatorName == ':')
            error!('Illegal cut: ' + cut_expr, 400)
          end

          ls = p.getArgList.first.getArgList.map do |id_node|
            get_member(cube, unparse_node(id_node)).raw_level
          end.uniq

          error!('Illegal cut: ' + cut_expr, 400) unless ls.size == 1

          { level: ls.first, cut: unparse_node(p), type: :range }
        else
          error!('Illegal cut: ' + cut_expr, 400)
        end
      when org.olap4j.mdx.IdentifierNode

        # does cut_expr look like a NamedSet?
        s = get_named_set(cube, cut_expr)
        return { level: nil, cut: cut_expr, type: :named_set } unless s.nil?

        # if `cut_expr` looks like a member, check that it's level is
        # equal to `level`
        m = get_member(cube, cut_expr)

        if m.nil?
          error!("Illegal cut: #{cut_expr} — Member does not exist", 400)
        end

        { level: m.raw_level, cut: cut_expr, type: :member }
      else
        error!('Illegal cut: ' + cut_expr, 400)
      end
    end
Parses a string containing a 'cut' expression
 It can be a set (`{Dim.Mem, Dim2.Mem2}`), a range (`([Time].[Year].[1997]:[Time].[Year].[1998])`), a member identifier (`[Time].[Year].[1998]`) or a NamedSet.