From 908e54f1610c9f26059354ef97923c8503762948 Mon Sep 17 00:00:00 2001 From: "rickg%netscape.com" Date: Wed, 23 Sep 1998 16:55:13 +0000 Subject: [PATCH] added support for XML processing instructions --- htmlparser/src/CNavDTD.cpp | 25 +++++++++++ htmlparser/src/CNavDTD.h | 1 + htmlparser/src/nsHTMLTokens.cpp | 57 ++++++++++++++++++++++++++ htmlparser/src/nsHTMLTokens.h | 19 ++++++++- htmlparser/src/nsParserTypes.h | 1 + parser/htmlparser/src/CNavDTD.cpp | 25 +++++++++++ parser/htmlparser/src/CNavDTD.h | 1 + parser/htmlparser/src/nsHTMLTokens.cpp | 57 ++++++++++++++++++++++++++ parser/htmlparser/src/nsHTMLTokens.h | 19 ++++++++- parser/htmlparser/src/nsParserTypes.h | 1 + 10 files changed, 204 insertions(+), 2 deletions(-) diff --git a/htmlparser/src/CNavDTD.cpp b/htmlparser/src/CNavDTD.cpp index 5d32a4b9de4..7ff20299cdf 100644 --- a/htmlparser/src/CNavDTD.cpp +++ b/htmlparser/src/CNavDTD.cpp @@ -199,6 +199,7 @@ CToken* nsCTokenRecycler::CreateTokenOfType(eHTMLTokenTypes aType,eHTMLTags aTag case eToken_script: result=new CScriptToken(); break; case eToken_style: result=new CStyleToken(); break; case eToken_skippedcontent: result=new CSkippedContentToken(aString); break; + case eToken_instruction:result=new CInstructionToken(); break; default: break; } @@ -308,6 +309,8 @@ PRInt32 NavDispatchTokenHandler(CToken* aToken,nsIDTD* aDTD) { result=theDTD->HandleStyleToken(aToken); break; case eToken_skippedcontent: result=theDTD->HandleSkippedContentToken(aToken); break; + case eToken_instruction: + result=theDTD->HandleProcessingInstructionToken(aToken); break; default: result=0; }//switch @@ -337,6 +340,7 @@ void CNavDTD::InitializeDefaultTokenHandlers() { // AddTokenHandler(new CTokenHandler(NavDispatchTokenHandler,eToken_script)); AddTokenHandler(new CTokenHandler(NavDispatchTokenHandler,eToken_style)); AddTokenHandler(new CTokenHandler(NavDispatchTokenHandler,eToken_skippedcontent)); + AddTokenHandler(new CTokenHandler(NavDispatchTokenHandler,eToken_instruction)); } @@ -864,6 +868,21 @@ nsresult CNavDTD::HandleStyleToken(CToken* aToken){ } +/** + * This method gets called when an "instruction" token has been + * encountered in the parse process. + * + * @update gess 3/25/98 + * @param aToken -- next (start) token to be handled + * @return PR_TRUE if all went well; PR_FALSE if error occured + */ +nsresult CNavDTD::HandleProcessingInstructionToken(CToken* aToken){ + NS_PRECONDITION(0!=aToken,kNullToken); + +// CStyleToken* st = (CStyleToken*)(aToken); + return NS_OK; +} + /** * Retrieve the attributes for this node, and add then into * the node. @@ -2698,9 +2717,15 @@ CNavDTD::ConsumeTag(PRUnichar aChar,CScanner& aScanner,CToken*& aToken) { else aToken=gTokenRecycler.CreateTokenOfType(eToken_comment,eHTMLTag_unknown,gEmpty); }//if break; + case kExclamation: aToken=gTokenRecycler.CreateTokenOfType(eToken_comment,eHTMLTag_comment,gEmpty); break; + + case kQuestionMark: //it must be an XML processing instruction... + aToken=gTokenRecycler.CreateTokenOfType(eToken_instruction,eHTMLTag_unknown,gEmpty); + break; + default: if(nsString::IsAlpha(aChar)) return ConsumeStartTag(aChar,aScanner,aToken); diff --git a/htmlparser/src/CNavDTD.h b/htmlparser/src/CNavDTD.h index 5c5798aab0a..084189e0d19 100644 --- a/htmlparser/src/CNavDTD.h +++ b/htmlparser/src/CNavDTD.h @@ -416,6 +416,7 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD { nsresult HandleAttributeToken(CToken* aToken); nsresult HandleScriptToken(nsCParserNode& aNode); nsresult HandleStyleToken(CToken* aToken); + nsresult HandleProcessingInstructionToken(CToken* aToken); virtual nsITokenRecycler* GetTokenRecycler(void); diff --git a/htmlparser/src/nsHTMLTokens.cpp b/htmlparser/src/nsHTMLTokens.cpp index 7604cb8fa6f..a5db062858c 100644 --- a/htmlparser/src/nsHTMLTokens.cpp +++ b/htmlparser/src/nsHTMLTokens.cpp @@ -1290,3 +1290,60 @@ const char* GetTagName(PRInt32 aTag) { } return result; } + + +/** + * + * + * @update gess 9/23/98 + * @param + * @return + */ +CInstructionToken::CInstructionToken() : CHTMLToken(eHTMLTag_unknown) { +} + +/** + * + * + * @update gess 9/23/98 + * @param + * @return + */ +CInstructionToken::CInstructionToken(const nsString& aString) : CHTMLToken(aString) { +} + +/** + * + * + * @update gess 9/23/98 + * @param + * @return + */ +nsresult CInstructionToken::Consume(PRUnichar aChar,CScanner& aScanner){ + mTextValue="HandleStyleToken(aToken); break; case eToken_skippedcontent: result=theDTD->HandleSkippedContentToken(aToken); break; + case eToken_instruction: + result=theDTD->HandleProcessingInstructionToken(aToken); break; default: result=0; }//switch @@ -337,6 +340,7 @@ void CNavDTD::InitializeDefaultTokenHandlers() { // AddTokenHandler(new CTokenHandler(NavDispatchTokenHandler,eToken_script)); AddTokenHandler(new CTokenHandler(NavDispatchTokenHandler,eToken_style)); AddTokenHandler(new CTokenHandler(NavDispatchTokenHandler,eToken_skippedcontent)); + AddTokenHandler(new CTokenHandler(NavDispatchTokenHandler,eToken_instruction)); } @@ -864,6 +868,21 @@ nsresult CNavDTD::HandleStyleToken(CToken* aToken){ } +/** + * This method gets called when an "instruction" token has been + * encountered in the parse process. + * + * @update gess 3/25/98 + * @param aToken -- next (start) token to be handled + * @return PR_TRUE if all went well; PR_FALSE if error occured + */ +nsresult CNavDTD::HandleProcessingInstructionToken(CToken* aToken){ + NS_PRECONDITION(0!=aToken,kNullToken); + +// CStyleToken* st = (CStyleToken*)(aToken); + return NS_OK; +} + /** * Retrieve the attributes for this node, and add then into * the node. @@ -2698,9 +2717,15 @@ CNavDTD::ConsumeTag(PRUnichar aChar,CScanner& aScanner,CToken*& aToken) { else aToken=gTokenRecycler.CreateTokenOfType(eToken_comment,eHTMLTag_unknown,gEmpty); }//if break; + case kExclamation: aToken=gTokenRecycler.CreateTokenOfType(eToken_comment,eHTMLTag_comment,gEmpty); break; + + case kQuestionMark: //it must be an XML processing instruction... + aToken=gTokenRecycler.CreateTokenOfType(eToken_instruction,eHTMLTag_unknown,gEmpty); + break; + default: if(nsString::IsAlpha(aChar)) return ConsumeStartTag(aChar,aScanner,aToken); diff --git a/parser/htmlparser/src/CNavDTD.h b/parser/htmlparser/src/CNavDTD.h index 5c5798aab0a..084189e0d19 100644 --- a/parser/htmlparser/src/CNavDTD.h +++ b/parser/htmlparser/src/CNavDTD.h @@ -416,6 +416,7 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD { nsresult HandleAttributeToken(CToken* aToken); nsresult HandleScriptToken(nsCParserNode& aNode); nsresult HandleStyleToken(CToken* aToken); + nsresult HandleProcessingInstructionToken(CToken* aToken); virtual nsITokenRecycler* GetTokenRecycler(void); diff --git a/parser/htmlparser/src/nsHTMLTokens.cpp b/parser/htmlparser/src/nsHTMLTokens.cpp index 7604cb8fa6f..a5db062858c 100644 --- a/parser/htmlparser/src/nsHTMLTokens.cpp +++ b/parser/htmlparser/src/nsHTMLTokens.cpp @@ -1290,3 +1290,60 @@ const char* GetTagName(PRInt32 aTag) { } return result; } + + +/** + * + * + * @update gess 9/23/98 + * @param + * @return + */ +CInstructionToken::CInstructionToken() : CHTMLToken(eHTMLTag_unknown) { +} + +/** + * + * + * @update gess 9/23/98 + * @param + * @return + */ +CInstructionToken::CInstructionToken(const nsString& aString) : CHTMLToken(aString) { +} + +/** + * + * + * @update gess 9/23/98 + * @param + * @return + */ +nsresult CInstructionToken::Consume(PRUnichar aChar,CScanner& aScanner){ + mTextValue="