options { USER_CHAR_STREAM = true; NODE_USES_PARSER=true; UNICODE_INPUT=true; FORCE_LA_CHECK = false; IGNORE_CASE = true; STATIC = false; MULTI=true; VISITOR=true; } PARSER_BEGIN(VfParserImpl) package net.sourceforge.pmd.lang.visualforce.ast; /** * @deprecated Since 7.5.0. VfParserImpl should have been package private because this is an implementation class * that should not be used directly. */ @Deprecated public class VfParserImpl { /** * Counter used to keep track of unclosed tags */ private OpenTagRegister tagRegister = new OpenTagRegister(); /** * Return the contents of a quote. * @param quote String - starting and ending with " or ' * @return String a substring of quote: quote without the first and list * character. */ private static String quoteContent(String quote) { return quote.substring(1, quote.length()-1); } /** * Return the contents of a EL expression. * @param expression String - starting with ${ or #{ and ending with } * @return String a substring of expression: expression without the first two and list * characters. */ private static String expressionContent(String expression) { return expression.substring(2, expression.length()-1).trim(); } } PARSER_END(VfParserImpl) /** ************************* VF LEXICON **************************** */ <*> TOKEN : { <#ALPHA_CHAR: [ "\u0024", "\u0041"-"\u005a", "\u005f", "\u0061"-"\u007a", "\u00c0"-"\u00d6", "\u00d8"-"\u00f6", "\u00f8"-"\u00ff" ] > | <#NUM_CHAR: [ "\u0030"-"\u0039" ] > | <#ALPHANUM_CHAR: ( | ) > | <#IDENTIFIER_CHAR: ( | [ "_", "-", ":" ] ) > | <#IDENTIFIER: ()* > | <#IDENTIFIER_DOTTED: ( )+ > | <#XMLNAME: ( | "_" | ":") ()* > | <#QUOTED_STRING_NO_BREAKS: ( "'" ( ~["'", "\r", "\n"] )* "'" ) | ( "\"" ( ~["\"", "\r", "\n"] )* "\"" ) > | <#QUOTED_STRING: ( "'" ( ~["'"] )* "'" ) | ( "\"" ( ~["\""] | "\\\"" )* "\"" ) > | <#WHITESPACE: ( " " | "\t" | "\n" | "\r" ) > | <#NEWLINE: ( "\r\n" | "\r" | "\n" ) > | <#QUOTE: ( "'" | "\"" )> | <#NO_WHITESPACE_OR_LT_OR_DOLLAR: (~[" ", "\t", "\n", "\r", "<"])> | <#NO_BANG: (~["!"])> | <#OPENBRACE: ("{") > | <#NO_LT_OR_OPENBRACE: (~["<","{"])> | <#NO_ENDTAG_START: (~["<"]~["/"]) > | <#TEXT_IN_EL: (~["}", "'", "\""])+ > | <#CLOSEBRACE: ("}")> | <#DOT: "." > | <#COMMNT_START: "/*" > | <#COMMNT_END: "*/" > } SKIP : { < ()+ > } SPECIAL_TOKEN: { < ()+ > } TOKEN : { : StartTagState | : StartTagState | : CommentState | : StartTagState | : DocTypeState | : CDataState | : InTagState } TOKEN : { : ElTagState | |)+ > } TOKEN : { | | | | | | | | > | | | | | | | | | | | " | "!=" ) > | =" > | | " > | | | > | )+ ( ()+)? > | > | | } TOKEN : { )? > : AfterTagState } TOKEN : { > : InlineCommentStateSQ | )? > : AttrValueBetweenSingleQuotesState } TOKEN : { > : InlineCommentStateDQ | )? > : AttrValueBetweenDoubleQuotesState } TOKEN : { )? > : AttrValueNoQuotesState } TOKEN : { > : InlineCommentStateScript | )? > : HtmlScriptContentState } TOKEN : { )+ > } TOKEN: { ) > : DocTypeExternalIdState } TOKEN: { | | " > : AfterTagState | ) > } TOKEN : { | ") > : AfterTagState } TOKEN : { > : InTagState | : DEFAULT } TOKEN : { | > | " > : AfterTagState | " | "!>") > : AfterTagState | " | "/ >") > : AfterTagState | : AttrValueBetweenSingleQuotesState | )? "\"">: AttrValueBetweenDoubleQuotesState | { input_stream.backup(1);} : AttrValueNoQuotesState | : InTagState //support for empty attributes } TOKEN : { : InTagState | )? > : ElAttribTagStateNQ | } TOKEN : { : InTagState | )? > : ElAttribTagStateSQ | } TOKEN : { : InTagState | )? > : ElAttribTagStateDQ | } TOKEN : { < COMMENT_END: ("--" (" ")* ">" ) > : AfterTagState | < COMMENT_TEXT: (~[]) > } TOKEN : { < COMMENT_CLOSE_SCRIPT: () > : ElInScriptState | < COMMENT_INNER_TEXT_SCRIPT: (~[]) > } TOKEN : { < COMMENT_CLOSE_SQ: () > : ElAttribTagStateSQ | < COMMENT_INNER_TEXT_SQ: (~[]) > } TOKEN : { < COMMENT_CLOSE_DQ: () > : ElAttribTagStateDQ | < COMMENT_INNER_TEXT_DQ: (~[]) > } TOKEN : { " > : AfterTagState | )? > : ElInScriptState | } /** ************************* VF GRAMMAR **************************** */ /** * The root of the AST of a VF. */ ASTCompilationUnit CompilationUnit() : {} { (Bom())? Prolog() Content() { return jjtThis; } } /** * The optional prolog of a VF, including (xml) declarations and DTD. */ void Prolog() #void : {} { ( LOOKAHEAD( ( CommentTag() )* Declaration() ) ( CommentTag() )* Declaration() )? ( LOOKAHEAD( ( CommentTag() )* DoctypeDeclaration() ) ( CommentTag() )* DoctypeDeclaration() )? } void Bom() #void : {} { } /** * Everything between a start-tag and the corresponding end-tag of an element (if an end tag exists). */ void Content() : {} { ( ElOrText() | ContentElement() )* } /** * A single (non-text) element that can occur between a start-tag and end-tag of an element. * */ void ContentElement() #void : {} { ( CommentTag() | Element() | CData() | HtmlScript() ) } /** * This production groups all characters between two tags, where * tag is an xml-tag "<...>" or CDATA "<![CDATA[...]]>". * Text consists of unparsed text and/or Expression Language expressions. */ void ElOrText() #void : {} { ( ElExpression() | Text() )+ } void Text() : { Token t; } { t = { jjtThis.setImage(t.image); } } void UnparsedTextNoWhitespace() #Text : { Token t;} { ( t = ) { jjtThis.setImage(t.image); } } /** * Text that contains no single quotes, and that does not contain the start * of a EL expression. */ void UnparsedTextNoSingleQuotes() #Text : { Token t; } { t = { jjtThis.setImage(t.image); } } /** * Text that contains no double quotes, and that does not contain the start * of a EL expression. */ void UnparsedTextNoDoubleQuotes() #Text : { Token t; } { t = { jjtThis.setImage(t.image); } } /** * An EL expression, not within an attribute value. */ void ElExpression() : {} { (Expression())+ } void Expression() : {} { ConditionalExpression() [ AssignmentOperator() Expression() ] | CommentExpression() ( ConditionalExpression() | CommentExpression() )* | ELDQCommentExpression() ( ConditionalExpression() | ELDQCommentExpression() )* | ELSQCommentExpression() ( ConditionalExpression() | ELSQCommentExpression() )* } void AssignmentOperator() #void : {} { | | | | | } void ConditionalExpression() #void : {} { ConditionalOrExpression() [ Expression() ConditionalExpression() ] } void ConditionalOrExpression() #void : {} { ConditionalAndExpression() ( ConditionalAndExpression() )* } void ConditionalAndExpression() #void : {} { PowerExpression() ( PowerExpression() )* } void PowerExpression() #void : {} { ConcatExpression() ( ConcatExpression() )* } void ConcatExpression() #void : {} { EqualityExpression() ( EqualityExpression() )* } void EqualityExpression() #void : {} { RelationalExpression() ( ( | ) RelationalExpression() )* } void RelationalExpression() #void : {} { AdditiveExpression() ( ( | | | ) AdditiveExpression() )* } void AdditiveExpression() #void : {} { MultiplicativeExpression() ( LOOKAHEAD(2) ( | ) MultiplicativeExpression() )* } void MultiplicativeExpression() #void : {} { UnaryExpression() ( ( |
| ) UnaryExpression() )* } void UnaryExpression() #void : {} { ( | ) UnaryExpression() | PrimaryExpression() } void PrimaryExpression() #void : {} { PrimaryPrefix() ( LOOKAHEAD(2) PrimarySuffix() )* } void ELSQCommentExpression() #void : {} { ( )* } void ELDQCommentExpression() #void : {} { ( )* } void CommentExpression() #void : {} { ( )* } void PrimaryPrefix() #void : {} { Literal() | Identifier() | Expression() | Expression() ( Expression())* | NegationExpression() } void PrimarySuffix() #void : {} { Expression() ( Expression())* | DotExpression() | Arguments() } void NegationExpression() : {} { ( ) Expression() } void DotExpression() : {} { (Identifier() | Literal() ) } void Arguments() : {} { [ ArgumentList() ] } void ArgumentList() #void: {} { Expression() ( Expression() )* } void Literal() : { String s; Token t; } { t = { jjtThis.setImage(t.image);} | t = { jjtThis.setImage(t.image);} | s = BooleanLiteral() { jjtThis.setImage(s);} | s = NullLiteral() { jjtThis.setImage(s);} } String BooleanLiteral() #void : { Token t; } { ( t = | t = ) { return t.image; } } String NullLiteral() #void : { Token t; } { t = { return t.image;} } void Identifier() : { Token t; } { t = { jjtThis.setImage(t.image);} } void ElExpressionInAttribute() #ElExpression : {} { [Expression()] | [Expression()] | [Expression()] } void ElExpressionInScript() #ElExpression : {} { [Expression()] } void CData() : { StringBuffer content = new StringBuffer(); Token t; } { ( t = { content.append(t.image); } )* { jjtThis.setImage(content.toString()); } } /** * A XML element, either with a single empty tag, or with a starting and closing tag * with optional contained content. */ void Element() : { Token startTag; Token endTag; String tagName; } { ( ( startTag = { tagName = startTag.image; jjtThis.setName(tagName); tagRegister.openTag(jjtThis); } ) (Attribute())* ( ( { jjtThis.setEmpty(false);} (Content()) ( LOOKAHEAD(2) endTag = {tagRegister.closeTag(endTag.image);} )? ) | ( { jjtThis.setEmpty(true); jjtThis.setUnclosed(false); } ) ) ) } void Attribute() : { Token t; } { t = { jjtThis.setName(t.image); } ( AttributeValue() ) } /** * The value of an attribute of an element. * EL expressions * are parsed as sub-nodes of the AttributeValue node. */ void AttributeValue() : {} { ( ( ( ( UnparsedTextNoDoubleQuotes() | ElExpressionInAttribute() ) )* ( ) ) | ( ( ( UnparsedTextNoSingleQuotes() | ElExpressionInAttribute() ) )* ( ) ) | ( ( ( UnparsedTextNoWhitespace() | ElExpressionInAttribute() ) )* ( ) ) | ) } void CommentTag() #void : {} { ( )* } void Declaration() : { Token t; } { t = { jjtThis.setName(t.image); } (Attribute())* } void DoctypeDeclaration() : { Token t; } { t = { jjtThis.setName(t.image); } ()? (DoctypeExternalId() ()?)? } void DoctypeExternalId() : { Token systemLiteral; Token pubIdLiteral; } { ( systemLiteral = { jjtThis.setUri(quoteContent(systemLiteral.image)); } ) | ( pubIdLiteral = { jjtThis.setPublicId(quoteContent(pubIdLiteral.image)); } systemLiteral = { jjtThis.setUri(quoteContent(systemLiteral.image)); } ) } void HtmlScript() : {} { {} (Attribute() )* {} ( ( {token_source.SwitchTo(HtmlScriptContentState);} ( ( HtmlScriptContent() | ElExpressionInScript() ) )* ) | ( ) ) } void HtmlScriptContent() #Text : { StringBuffer content = new StringBuffer(); Token t; } { ( t = { content.append(t.image); } )+ { jjtThis.setImage(content.toString()); } }