element method

  1. @override
Parser<XmlElementNaturalImpl> element()
override

Implementation

@override
Parser<XmlElementNaturalImpl> element() => elementProd().token().map((a) {
      final list = a.value;
      final left_croc = list[0] as Token<dynamic>;
      final name = list[1] as Token<dynamic>;
      final attributes = (list[2] as List<dynamic>).cast<XmlNode>();
      final dynamic last = list[4];
      if (last is Token<dynamic> && last.value == XmlToken.closeEndElement) {
        return XmlElementNaturalImpl(
          _range(a),
          name.value as XmlName,
          attributes.cast(),
          [],
          true,
          ElementypeSelfclosing(
            source_tag: _range<dynamic>(name),
            source_left_croc: _range<dynamic>(left_croc),
            source_right_croc: _range<dynamic>(last),
          ),
        );
      } else {
        final fourth = last as List<dynamic>;
        final name_right = fourth[3] as Token<dynamic>;
        if (name.value == name_right.value) {
          final children = (fourth[1] as List<dynamic>).cast<XmlElementChildNatural>();
          return XmlElementNaturalImpl(
            _range(a),
            name.value as XmlName,
            attributes.cast(),
            children,
            children.isNotEmpty,
            ElementypeNonselfclosing(
              source_left_left_croc: _range<dynamic>(left_croc),
              source_tag_left: _range<dynamic>(name),
              source_left_right_croc: _range<dynamic>(last[0] as Token<dynamic>),
              source_right_left_croc: _range<dynamic>(fourth[2] as Token<dynamic>),
              source_tag_right: _range<dynamic>(name_right),
              source_right_right_croc: _range<dynamic>(fourth[5] as Token<dynamic>),
            ),
          );
        } else {
          final token = (list[4] as List<dynamic>)[2] as Token<dynamic>;
          final lineAndColumn = Token.lineAndColumnOf(token.buffer, token.start);
          throw XmlParserException(
            'Expected </${(list[1] as Token<dynamic>).value}>, but found </${name_right.value}>',
            buffer: token.buffer,
            position: token.start,
            line: lineAndColumn[0],
            column: lineAndColumn[1],
          );
        }
      }
    });