📄 parser.cpp
字号:
this->skip_whitespace_count (&nextch);
if (nextch == '\'' || nextch == '"')
{
ACEXML_Char *entity_value = 0;
if (this->get_quoted_string (entity_value) != 0)
{
this->report_fatal_error(ACE_TEXT("Error reading ENTITY value.") ACEXML_ENV_ARG_PARAMETER);
return -1;
}
if (is_GEDecl)
{
if (this->entities_.add_entity (entity_name, entity_value) != 0)
{
this->report_fatal_error(ACE_TEXT("Error storing entity definition (duplicate definition?)") ACEXML_ENV_ARG_PARAMETER);
return -1;
}
}
else
{
// @@ need to implement PEdecl lookup mechanism
ACEXML_THROW_RETURN (ACEXML_SAXNotSupportedException (), -1);
}
}
else
{
ACEXML_Char *systemid, *publicid;
this->parse_external_id_and_ref (publicid, systemid ACEXML_ENV_ARG_PARAMETER);
ACEXML_CHECK_RETURN (-1);
if (systemid == 0)
{
this->report_fatal_error(ACE_TEXT("Invalid ExternalID definition (system ID missing.)") ACEXML_ENV_ARG_PARAMETER);
return -1;
}
this->skip_whitespace_count (&nextch);
if (nextch == 'N') // NDATA section followed
{
if (is_GEDecl == 0)
{
this->report_fatal_error(ACE_TEXT("Unexpected keyword NDATA in PEDecl.") ACEXML_ENV_ARG_PARAMETER);
return -1;
}
if ((this->parse_token (ACE_TEXT ("NDATA")) < 0) ||
this->skip_whitespace_count (&nextch) == 0)
{
this->report_fatal_error(ACE_TEXT("Expecting keyword NDATA") ACEXML_ENV_ARG_PARAMETER);
return -1;
}
ACEXML_Char *ndata = this->read_name ();
this->dtd_handler_->unparsedEntityDecl (entity_name,
publicid,
systemid,
ndata ACEXML_ENV_ARG_PARAMETER);
ACEXML_CHECK_RETURN (-1);
}
else
{
// @@ Need to support external CharStream sources
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("ENTITY: (%s) "),
entity_name));
if (publicid == 0)
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("SYSTEM %s\n"),
systemid));
else
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("PUBLIC %s %s\n"),
publicid, systemid));
}
}
// End of ENTITY definition
if (this->skip_whitespace (0) != '>')
{
this->report_fatal_error(ACE_TEXT("Expecting end of ENTITY definition.") ACEXML_ENV_ARG_PARAMETER);
return -1;
}
return 0;
}
int
ACEXML_Parser::parse_attlist_decl (ACEXML_ENV_SINGLE_ARG_DECL)
{
if ((this->parse_token (ACE_TEXT ("ATTLIST")) < 0) ||
this->skip_whitespace_count () == 0)
{
this->report_fatal_error(ACE_TEXT("Expecting keyword `ATTLIST'") ACEXML_ENV_ARG_PARAMETER);
return -1;
}
ACEXML_Char *element_name = this->read_name ();
if (element_name == 0)
{
this->report_fatal_error(ACE_TEXT("Error reading element name while defining ATTLIST.") ACEXML_ENV_ARG_PARAMETER);
return -1;
}
ACEXML_Char nextch = this->skip_whitespace (0);
// Parse AttDef*
while (nextch != '>')
{
// Parse attribute name
ACEXML_Char *att_name = this->read_name (nextch);
if (att_name == 0)
{
this->report_fatal_error(ACE_TEXT("Error reading attribute name while defining ATTLIST.") ACEXML_ENV_ARG_PARAMETER);
return -1;
}
/*
Parse AttType:
Possible keywords:
CDATA // StringType
ID // TokenizedType
IDREF
IDREFS
ENTITY
ENTITIES
NMTOKEN
NMTOKENS
NOTATION // EnumeratedType - NotationTYpe
( // EnumeratedType - Enumeration
*/
nextch = this->skip_whitespace (0);
switch (nextch)
{
case 'C': // CDATA
if ((this->parse_token (ACE_TEXT ("DATA")) < 0) ||
this->skip_whitespace_count () == 0)
{
this->report_fatal_error(ACE_TEXT("Expecting keyword `CDATA' while defining ATTLIST.") ACEXML_ENV_ARG_PARAMETER);
return -1;
}
// Else, we have successfully identified the type of the
// attribute as CDATA
// @@ Set up validator appropriately here.
break;
case 'I': // ID, IDREF, or, IDREFS
if (this->get () == 'D')
{
if (this->skip_whitespace_count (&nextch) > 0)
{
// We have successfully identified the type of the
// attribute as ID @@ Set up validator as such.
break;
}
if (this->parse_token (ACE_TEXT ("REF")) == 0)
{
if (this->skip_whitespace_count (&nextch) > 0)
{
// We have successfully identified the type of
// the attribute as IDREF
// @@ Set up validator as such.
break;
}
else if (nextch == 'S' &&
this->get () && // consume the 'S'
this->skip_whitespace_count () != 0)
{
// We have successfully identified the type of
// the attribute as IDREFS
// @@ Set up validator as such.
break;
}
}
}
// Admittedly, this error message is not precise enough
this->report_fatal_error(ACE_TEXT("Expecting keyword `ID', `IDREF', or `IDREFS' while defining ATTLIST.") ACEXML_ENV_ARG_PARAMETER);
return -1;
case 'E': // ENTITY or ENTITIES
if (this->parse_token (ACE_TEXT ("NTIT")) == 0)
{
nextch = this->get ();
if (nextch == 'Y')
{
// We have successfully identified the type of
// the attribute as ENTITY
// @@ Set up validator as such.
}
else if (nextch == 'I'&& this->get () == 'E' &&
this->get () == 'S')
{
// We have successfully identified the type of
// the attribute as ENTITIES
// @@ Set up validator as such.
}
if (this->skip_whitespace_count () > 0)
{
// success
break;
}
}
// Admittedly, this error message is not precise enough
this->report_fatal_error(ACE_TEXT("Expecting keyword `ENTITY', or `ENTITIES' while defining ATTLIST.") ACEXML_ENV_ARG_PARAMETER);
return -1;
case 'N': // NMTOKEN, NMTOKENS, or, NOTATION
nextch = this->get ();
if (nextch != 'M' || nextch != 'O')
{
this->report_fatal_error(ACE_TEXT("Expecting keyword `NMTOKEN', `NMTOKENS', or `NOTATION' while defining ATTLIST.") ACEXML_ENV_ARG_PARAMETER);
return -1;
}
if (nextch == 'M')
{
if (this->parse_token (ACE_TEXT ("TOKEN")) == 0)
{
if (this->skip_whitespace_count (&nextch) > 0)
{
// We have successfully identified the type of
// the attribute as NMTOKEN
// @@ Set up validator as such.
break;
}
else if (nextch == 'S' && this->skip_whitespace_count () > 0)
{
// We have successfully identified the type of
// the attribute as NMTOKENS
// @@ Set up validator as such.
break;
}
}
this->report_fatal_error(ACE_TEXT("Expecting keyword `NMTOKEN' or `NMTOKENS' while defining ATTLIST.") ACEXML_ENV_ARG_PARAMETER);
return -1;
}
else // NOTATION
{
if ((this->parse_token (ACE_TEXT ("TATION")) < 0) ||
this->skip_whitespace_count () == 0)
{
this->report_fatal_error(ACE_TEXT("Expecting keyword `NOTATION' while defining ATTLIST.") ACEXML_ENV_ARG_PARAMETER);
return -1;
}
if (this->get () != '(')
{
this->report_fatal_error(ACE_TEXT("Expecting `(' following NOTATION while defining ATTLIST.") ACEXML_ENV_ARG_PARAMETER);
return -1;
}
this->skip_whitespace_count ();
do {
ACEXML_Char *notation_name = this->read_name ();
if (notation_name == 0)
{
this->report_fatal_error(ACE_TEXT("Error reading NOTATION name while defining ATTLIST.") ACEXML_ENV_ARG_PARAMETER);
return -1;
}
// @@ get another notation name, set up validator as such
this->skip_whitespace_count (&nextch);
} while (nextch != ')');
this->get (); // consume the closing paren.
this->skip_whitespace_count ();
}
break;
case '(': // EnumeratedType - Enumeration
this->skip_whitespace_count ();
do {
ACEXML_Char *token_name = this->read_name (); // @@ need a special read_nmtoken?
if (token_name == 0)
{
this->report_fatal_error(ACE_TEXT("Error reading enumerated nmtoken name while defining ATTLIST.") ACEXML_ENV_ARG_PARAMETER);
return -1;
}
// @@ get another nmtoken, set up validator as such
this->skip_whitespace_count (&nextch);
} while (nextch != ')');
this->get (); // consume the closing paren.
this->skip_whitespace_count ();
break;
default:
{
this->report_fatal_error(ACE_TEXT("Invalid Attribute Type while defining ATTLIST.") ACEXML_ENV_ARG_PARAMETER);
return -1;
}
ACE_NOTREACHED (break);
}
/*
Parse DefaultDecl:
#REQUIRED
#IMPLIED
#FIXED
quoted string // #FIXED
*/
nextch = this->peek ();
switch (nextch)
{
case '#':
this->get (); // consume the '#'
switch (this->get ())
{
case 'R':
if (this->parse_token (ACE_TEXT ("EQUIRED")) < 0)
{
this->report_fatal_error(ACE_TEXT("Expecting keyword `#REQUIRED' while defining ATTLIST.") ACEXML_ENV_ARG_PARAMETER);
return -1;
}
// We now know this attribute is required
// @@ Set up the validator as such.
break;
case 'I':
if (this->parse_token (ACE_TEXT ("MPLIED")) < 0)
{
this->report_fatal_error(ACE_TEXT("Expecting keyword `#IMPLIED' while defining ATTLIST.") ACEXML_ENV_ARG_PARAMETER);
return -1;
}
// We now know this attribute is impleid.
// @@ Set up the validator as such.
break;
case 'F':
if (this->parse_token (ACE_TEXT ("IXED")) < 0 ||
this->skip_whitespace_count () == 0)
{
this->report_fatal_error(ACE_TEXT("Expecting keyword `#FIXED' while defining ATTLIST.") ACEXML_ENV_ARG_PARAMETER);
return -1;
}
// We now know this attribute is fixed.
ACEXML_Char *fixed_attr;
if (this->get_quoted_string (fixed_attr) != 0)
{
this->report_fatal_error(ACE_TEXT("Error parsing `#FIXED' attribute value while defining ATTLIST.") ACEXML_ENV_ARG_PARAMETER);
return -1;
}
// @@ set up validator
break;
default:
break;
}
break;
case '\'':
case '"':
ACEXML_Char *fixed_attr;
if (this->get_quoted_string (fixed_attr) != 0)
{
this->report_fatal_error(ACE_TEXT("Error parsing `#FIXED' attribute value while defining ATTLIST.") ACEXML_ENV_ARG_PARAMETER);
return -1;
}
// @@ set up validator
break;
default:
break;
}
this->skip_whitespace_count (&nextch);
}
this->get (); // consume closing '>'
return 0;
}
int
ACEXML_Parser::parse_notation_decl (ACEXML_ENV_SINGLE_ARG_DECL)
{
if (this->parse_token (ACE_TEXT ("NOTATION")) < 0 ||
this->skip_whitespace_count () == 0)
{
this->report_fatal_error(ACE_TEXT("Expecting keyword `NOTATION'") ACEXML_ENV_ARG_PARAMETER);
return -1;
}
ACEXML_Char *notation = this->read_name ();
if (notation == 0)
{
this->report_fatal_error(ACE_TEXT("Invalid notation name.") ACEXML_ENV_ARG_PARAMETER);
return -1;
}
this->skip_whitespace_count ();
ACEXML_Char *systemid, *publicid;
this->parse_external_id_and_ref (publicid, systemid ACEXML_ENV_ARG_PARAMETER);
ACEXML_CHECK_RETURN (-1);
if (this->get () != '>')
{
this->report_fatal_error(ACE_TEXT("Expecting NOTATION closing '>'.") ACEXML_ENV_ARG_PARAMETER);
return -1;
}
this->dtd_handler_->notationDecl (notation,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -