finalize lexer.c
This commit is contained in:
parent
5a3dbd5383
commit
90ddaa3662
120
src/lexer.c
120
src/lexer.c
|
@ -47,6 +47,25 @@
|
||||||
#define SPRTF printf
|
#define SPRTF printf
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !defined(NDEBUG) && defined(_MSC_VER)
|
||||||
|
static void Show_Node( TidyDocImpl* doc, const char *msg, Node *node )
|
||||||
|
{
|
||||||
|
Lexer* lexer = doc->lexer;
|
||||||
|
Bool lex = ((msg[0] == 'l')&&(msg[1] == 'e')) ? yes : no;
|
||||||
|
if (lexer && lexer->token && (lexer->token->type == TextNode)) {
|
||||||
|
SPRTF("Returning %s TextNode %p... %s\n", msg, node,
|
||||||
|
lex ? "lexer" : "stream");
|
||||||
|
} else {
|
||||||
|
SPRTF("Returning %s node %p <%s>... %s\n", msg, node,
|
||||||
|
node->element ? node->element : "blank",
|
||||||
|
lex ? "lexer" : "stream");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#define GTDBG(a,b,c) Show_Node(a,b,c)
|
||||||
|
#else
|
||||||
|
#define GTDBG
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Forward references
|
/* Forward references
|
||||||
*/
|
*/
|
||||||
/* swallows closing '>' */
|
/* swallows closing '>' */
|
||||||
|
@ -2033,7 +2052,7 @@ void TY_(UngetToken)( TidyDocImpl* doc )
|
||||||
if (lexer->txtend > lexer->txtstart) { \
|
if (lexer->txtend > lexer->txtstart) { \
|
||||||
Node *_node = TY_(TextToken)(lexer); \
|
Node *_node = TY_(TextToken)(lexer); \
|
||||||
lexer->token = _node; \
|
lexer->token = _node; \
|
||||||
SPRTF("Returning text node %p...\n",_node); \
|
GTDBG(doc,"text_node",_node); \
|
||||||
return _node; \
|
return _node; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2058,11 +2077,6 @@ static Node* GetTokenFromStream( TidyDocImpl* doc, GetTokenMode mode );
|
||||||
|
|
||||||
Node* TY_(GetToken)( TidyDocImpl* doc, GetTokenMode mode )
|
Node* TY_(GetToken)( TidyDocImpl* doc, GetTokenMode mode )
|
||||||
{
|
{
|
||||||
#if !defined(NDEBUG) && defined(_MSC_VER)
|
|
||||||
static int pushed_count = 0;
|
|
||||||
static int lexer_count = 0;
|
|
||||||
static int insert_count = 0;
|
|
||||||
#endif
|
|
||||||
Node *node;
|
Node *node;
|
||||||
Lexer* lexer = doc->lexer;
|
Lexer* lexer = doc->lexer;
|
||||||
|
|
||||||
|
@ -2076,11 +2090,7 @@ Node* TY_(GetToken)( TidyDocImpl* doc, GetTokenMode mode )
|
||||||
{
|
{
|
||||||
lexer->pushed = no;
|
lexer->pushed = no;
|
||||||
node = lexer->itoken;
|
node = lexer->itoken;
|
||||||
#if !defined(NDEBUG) && defined(_MSC_VER)
|
GTDBG(doc,"lex-itoken", node);
|
||||||
pushed_count++;
|
|
||||||
SPRTF("%d: Returning pushed node %p, '%s'...\n", pushed_count, node,
|
|
||||||
node->element ? node->element : "<blank>");
|
|
||||||
#endif
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
/* itoken has been accepted */
|
/* itoken has been accepted */
|
||||||
|
@ -2092,20 +2102,12 @@ Node* TY_(GetToken)( TidyDocImpl* doc, GetTokenMode mode )
|
||||||
if (lexer->token->type != TextNode
|
if (lexer->token->type != TextNode
|
||||||
|| !(lexer->insert || lexer->inode)) {
|
|| !(lexer->insert || lexer->inode)) {
|
||||||
node = lexer->token;
|
node = lexer->token;
|
||||||
#if !defined(NDEBUG) && defined(_MSC_VER)
|
GTDBG(doc,"lex-token", node);
|
||||||
lexer_count++;
|
|
||||||
SPRTF("%d: Returning lexer node %p, '%s'...\n", lexer_count, node,
|
|
||||||
node->element ? node->element : "<blank>");
|
|
||||||
#endif
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
lexer->itoken = TY_(InsertedToken)( doc );
|
lexer->itoken = TY_(InsertedToken)( doc );
|
||||||
node = lexer->itoken;
|
node = lexer->itoken;
|
||||||
#if !defined(NDEBUG) && defined(_MSC_VER)
|
GTDBG(doc,"lex-inserted", node);
|
||||||
insert_count++;
|
|
||||||
SPRTF("%d: Returning inserted node %p, '%s'...\n", insert_count, node,
|
|
||||||
node->element ? node->element : "<blank>");
|
|
||||||
#endif
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2116,9 +2118,7 @@ Node* TY_(GetToken)( TidyDocImpl* doc, GetTokenMode mode )
|
||||||
if (lexer->insert || lexer->inode) {
|
if (lexer->insert || lexer->inode) {
|
||||||
lexer->token = TY_(InsertedToken)( doc );
|
lexer->token = TY_(InsertedToken)( doc );
|
||||||
node = lexer->token;
|
node = lexer->token;
|
||||||
#if !defined(NDEBUG) && defined(_MSC_VER)
|
GTDBG(doc,"lex-inserted2", node);
|
||||||
SPRTF("Returning INSERT node %p, '%s'...\n", node, node->element ? node->element : "<blank>");
|
|
||||||
#endif
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2126,9 +2126,7 @@ Node* TY_(GetToken)( TidyDocImpl* doc, GetTokenMode mode )
|
||||||
{
|
{
|
||||||
assert( lexer->parent != NULL );
|
assert( lexer->parent != NULL );
|
||||||
node = GetCDATA(doc, lexer->parent);
|
node = GetCDATA(doc, lexer->parent);
|
||||||
#if !defined(NDEBUG) && defined(_MSC_VER)
|
GTDBG(doc,"lex-cdata", node);
|
||||||
SPRTF("Returning Cdatacontent node %p, '%s'...\n", node, node->element ? node->element : "<blank>");
|
|
||||||
#endif
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2263,9 +2261,7 @@ static Node* GetTokenFromStream( TidyDocImpl* doc, GetTokenMode mode )
|
||||||
StoreOriginalTextInToken(doc, lexer->token, 3);
|
StoreOriginalTextInToken(doc, lexer->token, 3);
|
||||||
#endif
|
#endif
|
||||||
node = lexer->token;
|
node = lexer->token;
|
||||||
#if !defined(NDEBUG) && defined(_MSC_VER)
|
GTDBG(doc,"text", node);
|
||||||
SPRTF("Returning text node %p, len %d...\n", node, node->end - node->start );
|
|
||||||
#endif
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2494,9 +2490,7 @@ static Node* GetTokenFromStream( TidyDocImpl* doc, GetTokenMode mode )
|
||||||
StoreOriginalTextInToken(doc, lexer->token, 0); /* hmm... */
|
StoreOriginalTextInToken(doc, lexer->token, 0); /* hmm... */
|
||||||
#endif
|
#endif
|
||||||
node = lexer->token;
|
node = lexer->token;
|
||||||
#if !defined(NDEBUG) && defined(_MSC_VER)
|
GTDBG(doc,"endtag", node);
|
||||||
SPRTF("Returning endtag node %p, '%s'...\n", node, node->element ? node->element : "<blank>");
|
|
||||||
#endif
|
|
||||||
return node; /* the endtag token */
|
return node; /* the endtag token */
|
||||||
|
|
||||||
case LEX_STARTTAG: /* first letter of tagname */
|
case LEX_STARTTAG: /* first letter of tagname */
|
||||||
|
@ -2572,17 +2566,7 @@ static Node* GetTokenFromStream( TidyDocImpl* doc, GetTokenMode mode )
|
||||||
StoreOriginalTextInToken(doc, lexer->token, 0);
|
StoreOriginalTextInToken(doc, lexer->token, 0);
|
||||||
#endif
|
#endif
|
||||||
node = lexer->token;
|
node = lexer->token;
|
||||||
#if !defined(NDEBUG) && defined(_MSC_VER)
|
GTDBG(doc,"starttag", node);
|
||||||
SPRTF("Returning starttag node %p, '%s'...\n", node, node->element ? node->element : "<blank>");
|
|
||||||
if (node->element) {
|
|
||||||
//if (stricmp(node->element,"datalist") == 0) {
|
|
||||||
// check_me(node->element);
|
|
||||||
//} else
|
|
||||||
if (stricmp(node->element,"option") == 0) {
|
|
||||||
check_me(node->element);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return node; /* return start tag */
|
return node; /* return start tag */
|
||||||
|
|
||||||
case LEX_COMMENT: /* seen <!-- so look for --> */
|
case LEX_COMMENT: /* seen <!-- so look for --> */
|
||||||
|
@ -2622,9 +2606,7 @@ static Node* GetTokenFromStream( TidyDocImpl* doc, GetTokenMode mode )
|
||||||
TY_(UngetChar)(c, doc->docIn);
|
TY_(UngetChar)(c, doc->docIn);
|
||||||
|
|
||||||
node = lexer->token;
|
node = lexer->token;
|
||||||
#if !defined(NDEBUG) && defined(_MSC_VER)
|
GTDBG(doc,"comment", node);
|
||||||
SPRTF("Returning comment node %p, '%s'...\n", node, node->element ? node->element : "<blank>");
|
|
||||||
#endif
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2671,9 +2653,7 @@ static Node* GetTokenFromStream( TidyDocImpl* doc, GetTokenMode mode )
|
||||||
if (lexer->doctype == VERS_UNKNOWN && lexer->token && !cfgBool(doc, TidyXmlTags))
|
if (lexer->doctype == VERS_UNKNOWN && lexer->token && !cfgBool(doc, TidyXmlTags))
|
||||||
lexer->doctype = FindGivenVersion(doc, lexer->token);
|
lexer->doctype = FindGivenVersion(doc, lexer->token);
|
||||||
node = lexer->token;
|
node = lexer->token;
|
||||||
#if !defined(NDEBUG) && defined(_MSC_VER)
|
GTDBG(doc,"doctype", node);
|
||||||
SPRTF("Returning doctype node %p, '%s'...\n", node, node->element ? node->element : "<blank>");
|
|
||||||
#endif
|
|
||||||
return node;
|
return node;
|
||||||
|
|
||||||
case LEX_PROCINSTR: /* seen <? so look for '>' */
|
case LEX_PROCINSTR: /* seen <? so look for '>' */
|
||||||
|
@ -2757,9 +2737,7 @@ static Node* GetTokenFromStream( TidyDocImpl* doc, GetTokenMode mode )
|
||||||
lexer->state = LEX_CONTENT;
|
lexer->state = LEX_CONTENT;
|
||||||
lexer->waswhite = no;
|
lexer->waswhite = no;
|
||||||
node = lexer->token;
|
node = lexer->token;
|
||||||
#if !defined(NDEBUG) && defined(_MSC_VER)
|
GTDBG(doc,"procinstr", node);
|
||||||
SPRTF("Returning procinstr node %p, '%s'...\n", node, node->element ? node->element : "<blank>");
|
|
||||||
#endif
|
|
||||||
return node;
|
return node;
|
||||||
|
|
||||||
case LEX_ASP: /* seen <% so look for "%>" */
|
case LEX_ASP: /* seen <% so look for "%>" */
|
||||||
|
@ -2783,9 +2761,7 @@ static Node* GetTokenFromStream( TidyDocImpl* doc, GetTokenMode mode )
|
||||||
lexer->waswhite = no;
|
lexer->waswhite = no;
|
||||||
lexer->token = AspToken(doc);
|
lexer->token = AspToken(doc);
|
||||||
node = lexer->token;
|
node = lexer->token;
|
||||||
#if !defined(NDEBUG) && defined(_MSC_VER)
|
GTDBG(doc,"ASP", node);
|
||||||
SPRTF("Returning ASP node %p, '%s'...\n", node, node->element ? node->element : "<blank>");
|
|
||||||
#endif
|
|
||||||
return node; /* the endtag token */
|
return node; /* the endtag token */
|
||||||
|
|
||||||
|
|
||||||
|
@ -2811,9 +2787,7 @@ static Node* GetTokenFromStream( TidyDocImpl* doc, GetTokenMode mode )
|
||||||
lexer->waswhite = no;
|
lexer->waswhite = no;
|
||||||
lexer->token = JsteToken(doc);
|
lexer->token = JsteToken(doc);
|
||||||
node = lexer->token;
|
node = lexer->token;
|
||||||
#if !defined(NDEBUG) && defined(_MSC_VER)
|
GTDBG(doc,"JSTE", node);
|
||||||
SPRTF("Returning JSTE node %p, '%s'...\n", node, node->element ? node->element : "<blank>");
|
|
||||||
#endif
|
|
||||||
return node; /* the JSTE token */
|
return node; /* the JSTE token */
|
||||||
|
|
||||||
|
|
||||||
|
@ -2837,9 +2811,7 @@ static Node* GetTokenFromStream( TidyDocImpl* doc, GetTokenMode mode )
|
||||||
lexer->waswhite = no;
|
lexer->waswhite = no;
|
||||||
lexer->token = PhpToken(doc);
|
lexer->token = PhpToken(doc);
|
||||||
node = lexer->token;
|
node = lexer->token;
|
||||||
#if !defined(NDEBUG) && defined(_MSC_VER)
|
GTDBG(doc,"PHP", node);
|
||||||
SPRTF("Returning PHP node %p, '%s'...\n", node, node->element ? node->element : "<blank>");
|
|
||||||
#endif
|
|
||||||
return node; /* the PHP token */
|
return node; /* the PHP token */
|
||||||
|
|
||||||
case LEX_XMLDECL: /* seen "<?xml" so look for "?>" */
|
case LEX_XMLDECL: /* seen "<?xml" so look for "?>" */
|
||||||
|
@ -2871,9 +2843,7 @@ static Node* GetTokenFromStream( TidyDocImpl* doc, GetTokenMode mode )
|
||||||
lexer->token = XmlDeclToken(doc);
|
lexer->token = XmlDeclToken(doc);
|
||||||
lexer->token->attributes = attributes;
|
lexer->token->attributes = attributes;
|
||||||
node = lexer->token;
|
node = lexer->token;
|
||||||
#if !defined(NDEBUG) && defined(_MSC_VER)
|
GTDBG(doc,"xml", node);
|
||||||
SPRTF("Returning xml node %p, '%s'...\n", node, node->element ? node->element : "<blank>");
|
|
||||||
#endif
|
|
||||||
return node; /* the xml token */
|
return node; /* the xml token */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2903,9 +2873,7 @@ static Node* GetTokenFromStream( TidyDocImpl* doc, GetTokenMode mode )
|
||||||
lexer->token = XmlDeclToken(doc);
|
lexer->token = XmlDeclToken(doc);
|
||||||
lexer->token->attributes = attributes;
|
lexer->token->attributes = attributes;
|
||||||
node = lexer->token;
|
node = lexer->token;
|
||||||
#if !defined(NDEBUG) && defined(_MSC_VER)
|
GTDBG(doc,"XML", node);
|
||||||
SPRTF("Returning XML node %p, '%s'...\n", node, node->element ? node->element : "<blank>");
|
|
||||||
#endif
|
|
||||||
return node; /* the XML token */
|
return node; /* the XML token */
|
||||||
|
|
||||||
case LEX_SECTION: /* seen "<![" so look for "]>" */
|
case LEX_SECTION: /* seen "<![" so look for "]>" */
|
||||||
|
@ -2939,9 +2907,7 @@ static Node* GetTokenFromStream( TidyDocImpl* doc, GetTokenMode mode )
|
||||||
lexer->waswhite = no;
|
lexer->waswhite = no;
|
||||||
lexer->token = SectionToken(doc);
|
lexer->token = SectionToken(doc);
|
||||||
node = lexer->token;
|
node = lexer->token;
|
||||||
#if !defined(NDEBUG) && defined(_MSC_VER)
|
GTDBG(doc,"SECTION", node);
|
||||||
SPRTF("Returning SECTION node %p, '%s'...\n", node, node->element ? node->element : "<blank>");
|
|
||||||
#endif
|
|
||||||
return node; /* the SECTION token */
|
return node; /* the SECTION token */
|
||||||
|
|
||||||
case LEX_CDATA: /* seen "<![CDATA[" so look for "]]>" */
|
case LEX_CDATA: /* seen "<![CDATA[" so look for "]]>" */
|
||||||
|
@ -2974,9 +2940,7 @@ static Node* GetTokenFromStream( TidyDocImpl* doc, GetTokenMode mode )
|
||||||
lexer->waswhite = no;
|
lexer->waswhite = no;
|
||||||
lexer->token = CDATAToken(doc);
|
lexer->token = CDATAToken(doc);
|
||||||
node = lexer->token;
|
node = lexer->token;
|
||||||
#if !defined(NDEBUG) && defined(_MSC_VER)
|
GTDBG(doc,"CDATA", node);
|
||||||
SPRTF("Returning CDATA node %p, '%s'...\n", node, node->element ? node->element : "<blank>");
|
|
||||||
#endif
|
|
||||||
return node; /* the CDATA token */
|
return node; /* the CDATA token */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2999,9 +2963,7 @@ static Node* GetTokenFromStream( TidyDocImpl* doc, GetTokenMode mode )
|
||||||
StoreOriginalTextInToken(doc, lexer->token, 0); /* ? */
|
StoreOriginalTextInToken(doc, lexer->token, 0); /* ? */
|
||||||
#endif
|
#endif
|
||||||
node = lexer->token;
|
node = lexer->token;
|
||||||
#if !defined(NDEBUG) && defined(_MSC_VER)
|
GTDBG(doc,"textstring", node);
|
||||||
SPRTF("Returning textstring node %p, '%s'...\n", node, node->element ? node->element : "<blank>");
|
|
||||||
#endif
|
|
||||||
return node; /* the textstring token */
|
return node; /* the textstring token */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3016,9 +2978,7 @@ static Node* GetTokenFromStream( TidyDocImpl* doc, GetTokenMode mode )
|
||||||
lexer->waswhite = no;
|
lexer->waswhite = no;
|
||||||
lexer->token = CommentToken(doc);
|
lexer->token = CommentToken(doc);
|
||||||
node = lexer->token;
|
node = lexer->token;
|
||||||
#if !defined(NDEBUG) && defined(_MSC_VER)
|
GTDBG(doc,"COMMENT", node);
|
||||||
SPRTF("Returning COMMENT node %p, '%s'...\n", node, node->element ? node->element : "<blank>");
|
|
||||||
#endif
|
|
||||||
return node; /* the COMMENT token */
|
return node; /* the COMMENT token */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue