SGML-Parser-OpenSP

 view release on metacpan or  search on metacpan

OpenSP.xs  view on Meta::CPAN

    HV* hv = newHV();

    hv_store(hv, "Name", 4, cs2sv(e.name), HvvName);

    // dataType
    switch (e.dataType)
    {
    case SGMLApplication::Entity::sgml:
        hv_store(hv, "DataType", 8, newSVpvn("sgml", 4), HvvDataType);
        break;
    case SGMLApplication::Entity::cdata:
        hv_store(hv, "DataType", 8, newSVpvn("cdata", 5), HvvDataType);
        break;
    case SGMLApplication::Entity::sdata:
        hv_store(hv, "DataType", 8, newSVpvn("sdata", 5), HvvDataType);
        break;
    case SGMLApplication::Entity::ndata:
        hv_store(hv, "DataType", 8, newSVpvn("ndata", 5), HvvDataType);
        break;
    case SGMLApplication::Entity::subdoc:
        hv_store(hv, "DataType", 8, newSVpvn("subdoc", 6), HvvDataType);
        break;

OpenSP.xs  view on Meta::CPAN

}

HV* SgmlParserOpenSP::attribute2hv(const SGMLApplication::Attribute a)
{
    HV* hv = newHV();

    // Name => ...
    hv_store(hv, "Name", 4, cs2sv(a.name), HvvName);

    // Type => ...
    if (a.type == SGMLApplication::Attribute::cdata)
    {
        AV* av = newAV();

        for (unsigned int i = 0; i < a.nCdataChunks; ++i)
        {
            HV* cc = newHV();

            if (a.cdataChunks[i].isSdata)
            {
                SV* sv = cs2sv(a.cdataChunks[i].entityName);

                // redundant?
                hv_store(cc, "IsSdata", 7, newSViv(1), HvvIsSdata);
                hv_store(cc, "EntityName", 10, sv, HvvEntityName);
            }
            else if (a.cdataChunks[i].isNonSgml)
            {
                SV* sv = newSViv(a.cdataChunks[i].nonSgmlChar);
                
                // redundant?
                hv_store(cc, "IsNonSgml", 9, newSViv(1), HvvIsNonSgml);
                hv_store(cc, "NonSgmlChar", 11, sv, HvvNonSgmlChar);
            }

            hv_store(cc, "Data", 4, cs2sv(a.cdataChunks[i].data), HvvData);

            av_push(av, newRV_noinc((SV*)cc));
        }

        hv_store(hv, "Type", 4, newSVpvn("cdata", 5), HvvType);
        hv_store(hv, "CdataChunks", 11, newRV_noinc((SV*)av), HvvCdataChunks);

    }
    else if (a.type == SGMLApplication::Attribute::tokenized)
    {
        AV* entities = newAV();

        hv_store(hv, "Type", 4, newSVpvn("tokenized", 9), HvvType);
        hv_store(hv, "Tokens", 6, cs2sv(a.tokens), HvvTokens);
        hv_store(hv, "IsGroup", 7, newSViv((int)a.isGroup), HvvIsGroup);

OpenSP.xs  view on Meta::CPAN

    }
    else if (a.type == SGMLApplication::Attribute::implied)
    {
        hv_store(hv, "Type", 4, newSVpvn("implied", 7), HvvType);
    }
    else if (a.type == SGMLApplication::Attribute::invalid)
    {
        hv_store(hv, "Type", 4, newSVpvn("invalid", 7), HvvType);
    }

    if (a.type == SGMLApplication::Attribute::cdata ||
        a.type == SGMLApplication::Attribute::tokenized)
    {
        switch (a.defaulted)
        {
        case SGMLApplication::Attribute::specified:
            hv_store(hv, "Defaulted", 9, newSVpvn("specified", 9), HvvDefaulted);
            break;
        case SGMLApplication::Attribute::definition:
            hv_store(hv, "Defaulted", 9, newSVpvn("definition", 10), HvvDefaulted);
            break;

OpenSP.xs  view on Meta::CPAN

    SV* sv = newRV_noinc((SV*)attributes2hv(e.attributes, e.nAttributes));

    hv_store(hv, "Name", 4, cs2sv(e.gi), HvvName);
    hv_store(hv, "Attributes", 10, sv, HvvAttributes);

    switch (e.contentType)
    {
    case SGMLApplication::StartElementEvent::empty:
        hv_store(hv, "ContentType", 11, newSVpvn("empty", 5), HvvContentType);
        break;
    case SGMLApplication::StartElementEvent::cdata:
        hv_store(hv, "ContentType", 11, newSVpvn("cdata", 5), HvvContentType);
        break;
    case SGMLApplication::StartElementEvent::rcdata:
        hv_store(hv, "ContentType", 11, newSVpvn("rcdata", 6), HvvContentType);
        break;
    case SGMLApplication::StartElementEvent::mixed:
        hv_store(hv, "ContentType", 11, newSVpvn("mixed", 5), HvvContentType);
        break;
    case SGMLApplication::StartElementEvent::element:
        hv_store(hv, "ContentType", 11, newSVpvn("element", 7), HvvContentType);
        break;
    }

    hv_store(hv, "Included", 8, newSViv(e.included ? 1 : 0), HvvIncluded);

OpenSP.xs  view on Meta::CPAN

    updatePosition(e.pos);

    HV* hv = newHV();
    AV* av = newAV();

    switch (e.status)
    {
    case SGMLApplication::MarkedSectionStartEvent::include:
        hv_store(hv, "Status", 6, newSVpvn("include", 7), HvvStatus);
        break;
    case SGMLApplication::MarkedSectionStartEvent::rcdata:
        hv_store(hv, "Status", 6, newSVpvn("rcdata", 6), HvvStatus);
        break;
    case SGMLApplication::MarkedSectionStartEvent::cdata:
        hv_store(hv, "Status", 6, newSVpvn("cdata", 5), HvvStatus);
        break;
    case SGMLApplication::MarkedSectionStartEvent::ignore:
        hv_store(hv, "Status", 6, newSVpvn("ignore", 6), HvvStatus);
        break;
    }

    for (unsigned int i = 0; i < e.nParams; ++i)
    {
        HV* param = newHV();

        switch (e.params[i].type)
        {
        case SGMLApplication::MarkedSectionStartEvent::Param::temp:
            hv_store(param, "Type", 6, newSVpvn("temp", 4), HvvType);
            break;
        case SGMLApplication::MarkedSectionStartEvent::Param::include:
            hv_store(param, "Type", 6, newSVpvn("include", 7), HvvType);
            break;
        case SGMLApplication::MarkedSectionStartEvent::Param::rcdata:
            hv_store(param, "Type", 6, newSVpvn("rcdata", 6), HvvType);
            break;
        case SGMLApplication::MarkedSectionStartEvent::Param::cdata:
            hv_store(param, "Type", 6, newSVpvn("cdata", 5), HvvType);
            break;
        case SGMLApplication::MarkedSectionStartEvent::Param::ignore:
            hv_store(param, "Type", 6, newSVpvn("ignore", 6), HvvType);
            break;
        case SGMLApplication::MarkedSectionStartEvent::Param::entityRef:
            hv_store(param, "Type", 6, newSVpvn("entityRef", 9), HvvType);
            hv_store(param, "EntityName", 10, cs2sv(e.params[i].entityName), HvvEntityName);
            break;
        }

OpenSP.xs  view on Meta::CPAN


    updatePosition(e.pos);

    HV* hv = newHV();

    switch (e.status)
    {
    case SGMLApplication::MarkedSectionEndEvent::include:
        hv_store(hv, "Status", 6, newSVpvn("include", 7), HvvStatus);
        break;
    case SGMLApplication::MarkedSectionEndEvent::rcdata:
        hv_store(hv, "Status", 6, newSVpvn("rcdata", 6), HvvStatus);
        break;
    case SGMLApplication::MarkedSectionEndEvent::cdata:
        hv_store(hv, "Status", 6, newSVpvn("cdata", 5), HvvStatus);
        break;
    case SGMLApplication::MarkedSectionEndEvent::ignore:
        hv_store(hv, "Status", 6, newSVpvn("ignore", 6), HvvStatus);
        break;
    }

    dispatchEvent("marked_section_end", hv);
}

///////////////////////////////////////////////////////////////////////////

lib/SGML/Parser/OpenSP.pm  view on Meta::CPAN

The following values can be used to enable warnings:

=over 4

=item xml 

Warn about constructs that are not allowed by XML. 

=item mixed 

Warn about mixed content models that do not allow #pcdata anywhere. 

=item sgmldecl 

Warn about various dubious constructions in the SGML declaration. 

=item should 

Warn about various recommendations made in ISO 8879 that the document
does not comply with. (Recommendations are expressed with ``should'',
as distinct from requirements which are usually expressed with ``shall''.)

lib/SGML/Parser/OpenSP.pm  view on Meta::CPAN

=over 4

=item inclusion 

Warn about inclusions in element type declarations. 

=item exclusion 

Warn about exclusions in element type declarations. 

=item rcdata-content 

Warn about RCDATA declared content in element type declarations. 

=item cdata-content 

Warn about CDATA declared content in element type declarations. 

=item ps-comment 

Warn about comments in parameter separators. 

=item attlist-group-decl 

Warn about name groups in attribute declarations. 

lib/SGML/Parser/OpenSP.pm  view on Meta::CPAN

Warn about name groups in element type declarations. 

=item pi-entity 

Warn about PI entities. 

=item internal-sdata-entity 

Warn about internal SDATA entities. 

=item internal-cdata-entity 

Warn about internal CDATA entities. 

=item external-sdata-entity 

Warn about external SDATA entities. 

=item external-cdata-entity 

Warn about external CDATA entities. 

=item bracket-entity 

Warn about bracketed text entities. 

=item data-atts 

Warn about attribute definition list declarations for notations. 

lib/SGML/Parser/OpenSP.pm  view on Meta::CPAN

Warn about named character references. 

=item refc 

Warn about ommitted refc delimiters. 

=item temp-ms 

Warn about TEMP marked sections. 

=item rcdata-ms 

Warn about RCDATA marked sections. 

=item instance-include-ms 

Warn about INCLUDE marked sections in the document instance. 

=item instance-ignore-ms 

Warn about IGNORE marked sections in the document instance. 

lib/SGML/Parser/OpenSP/Tools.pm  view on Meta::CPAN

    
    # ...
    return unless value_attribute($attr);

    # tokenized attributes
    return $attr->{Tokens}
      if $attr->{Type} eq "tokenized";

    my $value = "";
    
    # type is cdata
    foreach my $chunk (@{$attr->{CdataChunks}})
    {
        # todo: fix this for SDATA
        # todo: fix this for non-sgml chars

        $value .= $chunk->{Data};
    }
    
    return $value;
}

lib/SGML/Parser/OpenSP/Tools.pm  view on Meta::CPAN


Routines to post-process OpenSP event data.

=head1 UTILITY FUNCTIONS

=over 4

=item specified_attribute($attribute)

specified_attribute returns a true value if the attribute is
of type C<cdata> or C<tokenized> and has its C<Defaulted> property
set to C<specified>. For example

  sub start_element
  {
    my $self = shift;
    my $elem = shift;
    my @spec = grep specified_attribute($_),
                    values %{$elem->{Attributes}};

    # @spec contains all explicitly specified attributes
  }

=item defaulted_attribute($attribute)

defaulted_attribute returns a true value if the attribute is
of type C<cdata> or C<tokenized> and has its C<Defaulted> property
set to something but C<specified>. For all attributes, the following
always holds true,

  !defined(attribute_value($_)) or
  defaulted_attribute($_) or
  specified_attribute($_)

since only defaulted and specified attributes can have a value.

=item value_attribute($attribute)

t/12utf8.t  view on Meta::CPAN

    $s->{data}.=$e->{Data};
}

my $h7 = TestHandler7->new;

$p->handler($h7);

lives_ok { $p->parse("<LITERAL><no-doctype x='y'>Bj&#246;rn</no-doctype>") }
  'utf8 flags';

is($h7->{ok0}, 0, 'utf8 pcdata');
is($h7->{ok1}, 1, 'utf8 element name');
is($h7->{ok2}, 1, 'utf8 element name check');
is($h7->{ok8}, 1, 'attributes');
is($h7->{ok9}, 1, 'attribute hash key utf8');
is($h7->{oka}, 1, 'attribute hash key utf8 check');
is($h7->{okb}, 1, 'attribute name utf8');
is($h7->{okc}, 1, 'attribute name utf8 check');
is($h7->{ok3}, 1, 'end element name');
is($h7->{ok4}, 1, 'end element name');
is($h7->{ok5}, 1, 'complete data');



( run in 0.711 second using v1.01-cache-2.11-cpan-454fe037f31 )