Use getters for tokens in javacc grammars

This commit is contained in:
Clément Fournier
2020-01-06 14:56:10 +01:00
parent a0d0a22e7b
commit af537034a9
3 changed files with 116 additions and 116 deletions

View File

@ -101,7 +101,7 @@ public final class CppParser {
int i; int i;
if (t.kind != SCOPE) if (t.kind != SCOPE)
{ {
s.append(t.image); s.append(t.getImage());
t = getToken(2); t = getToken(2);
i = 3; i = 3;
} }
@ -110,8 +110,8 @@ public final class CppParser {
while (t.kind == SCOPE) while (t.kind == SCOPE)
{ {
s.append(t.image); s.append(t.getImage());
s.append((t = getToken(i++)).image); s.append((t = getToken(i++)).getImage());
t = getToken(i++); t = getToken(i++);
} }
@ -172,7 +172,7 @@ MORE:
| |
"\\\r\n" "\\\r\n"
| |
"/*": IN_PREPROCESSOR_OUTPUT_COMMENT "/*": IN_PREPROCESSOR_OUTPUT_COMMENT
| |
< ~[] > < ~[] >
} }
@ -606,12 +606,12 @@ String scope_override() :
("::") { name += "::"; } ("::") { name += "::"; }
( (
LOOKAHEAD(2) t = <ID> ("<" template_argument_list() ">")? "::" LOOKAHEAD(2) t = <ID> ("<" template_argument_list() ">")? "::"
{ name += t.image + "::"; } { name += t.getImage() + "::"; }
)* )*
| |
( (
LOOKAHEAD(2) t = <ID> ("<" template_argument_list() ">")? "::" LOOKAHEAD(2) t = <ID> ("<" template_argument_list() ">")? "::"
{ name += t.image + "::"; } { name += t.getImage() + "::"; }
)+ )+
) )
{ return name; } { return name; }
@ -627,7 +627,7 @@ String qualified_id() :
[ LOOKAHEAD(scope_override_lookahead()) name = scope_override() ] [ LOOKAHEAD(scope_override_lookahead()) name = scope_override() ]
( (
t = <ID> [ "<" template_argument_list() ">" ] t = <ID> [ "<" template_argument_list() ">" ]
{ return name + t.image; } { return name + t.getImage(); }
| |
"operator" optor() { return "operator"; } "operator" optor() { return "operator"; }
) )
@ -718,7 +718,7 @@ void class_specifier() :
| |
LOOKAHEAD(2) t = <ID> LOOKAHEAD(2) t = <ID>
{ {
sc = (ClassScope)sym.OpenScope(t.image, true); sc = (ClassScope)sym.OpenScope(t.getImage(), true);
} }
(base_clause(sc))? (base_clause(sc))?
"{" "{"
@ -729,7 +729,7 @@ void class_specifier() :
} }
| |
t=<ID> (LOOKAHEAD(2) "<" template_argument_list() ">")? t=<ID> (LOOKAHEAD(2) "<" template_argument_list() ">")?
{ sym.PutTypeName(t.image); } { sym.PutTypeName(t.getImage()); }
) )
} }
@ -745,7 +745,7 @@ void base_specifier(ClassScope scope) :
("virtual" (access_specifier())? | access_specifier() ("virtual")?)? ("virtual" (access_specifier())? | access_specifier() ("virtual")?)?
(LOOKAHEAD(scope_override_lookahead()) scope_override())? (LOOKAHEAD(scope_override_lookahead()) scope_override())?
t = <ID> ("<" template_argument_list() ">")? t = <ID> ("<" template_argument_list() ">")?
{ scope.AddSuper(sym.GetScope(t.image)); { scope.AddSuper(sym.GetScope(t.getImage()));
} }
} }
@ -837,7 +837,7 @@ void enum_specifier() :
"{" enumerator_list() "}" "{" enumerator_list() "}"
| |
t=<ID> (LOOKAHEAD(2) "{" enumerator_list() "}")? t=<ID> (LOOKAHEAD(2) "{" enumerator_list() "}")?
{ sym.PutTypeName(t.image); } { sym.PutTypeName(t.getImage()); }
) )
} }
@ -894,7 +894,7 @@ String direct_declarator() :
{ {
LOOKAHEAD(2) LOOKAHEAD(2)
"~" t = <ID> (LOOKAHEAD(2) declarator_suffixes())? "~" t = <ID> (LOOKAHEAD(2) declarator_suffixes())?
{ return "~" + t.image; } { return "~" + t.getImage(); }
| |
"(" name = declarator() ")" (LOOKAHEAD(2) declarator_suffixes())? "(" name = declarator() ")" (LOOKAHEAD(2) declarator_suffixes())?
{ return name; } { return name; }
@ -1149,7 +1149,7 @@ void template_parameter() :
{ Token t; } { Token t; }
{ {
LOOKAHEAD(3) LOOKAHEAD(3)
"class" t=<ID> { sym.PutTypeName(t.image); } "class" t=<ID> { sym.PutTypeName(t.getImage()); }
| |
parameter_declaration() parameter_declaration()
} }

File diff suppressed because it is too large Load Diff

View File

@ -23,7 +23,7 @@
*/ */
options options
{ {
/** The default package for this parser kit /** The default package for this parser kit
NODE_PACKAGE="org.apache.velocity.runtime.parser"; NODE_PACKAGE="org.apache.velocity.runtime.parser";
*/ */
NODE_PACKAGE="net.sourceforge.pmd.lang.vm.ast"; NODE_PACKAGE="net.sourceforge.pmd.lang.vm.ast";
@ -75,12 +75,12 @@ options
*/ */
DEBUG_PARSER=false; DEBUG_PARSER=false;
DEBUG_TOKEN_MANAGER=false; DEBUG_TOKEN_MANAGER=false;
/** /**
Copied from JSP parser Copied from JSP parser
*/ */
FORCE_LA_CHECK = false; FORCE_LA_CHECK = false;
IGNORE_CASE = true; IGNORE_CASE = true;
} }
PARSER_BEGIN(VmParser) PARSER_BEGIN(VmParser)
@ -156,7 +156,7 @@ public class VmParser
int iLast = strImage.lastIndexOf("\\"); int iLast = strImage.lastIndexOf("\\");
String strDirective = strImage.substring(iLast + 1); String strDirective = strImage.substring(iLast + 1);
// return ( strImage.substring(0,iLast/2) + strDirective); // return ( strImage.substring(0,iLast/2) + strDirective);
boolean bRecognizedDirective = false; boolean bRecognizedDirective = false;
@ -998,9 +998,9 @@ TOKEN:
/* /*
* Remove the double period if it is there * Remove the double period if it is there
*/ */
if (matchedToken.image.endsWith("..")) { if (matchedToken.getImage().endsWith("..")) {
input_stream.backup(2); input_stream.backup(2);
matchedToken.image = matchedToken.image.substring(0,matchedToken.image.length()-2); matchedToken.image = matchedToken.getImage().substring(0,matchedToken.getImage().length()-2);
} }
/* /*
@ -1197,7 +1197,7 @@ void EscapedDirective() : {}
/* /*
* churn and burn.. * churn and burn..
*/ */
t.image = escapedDirective( t.image ); t.image = escapedDirective( t.getImage() );
} }
} }
@ -1238,7 +1238,7 @@ void Escape() : {}
/* /*
* if that failed, lets lookahead to see if we matched a PD or a VM * if that failed, lets lookahead to see if we matched a PD or a VM
*/ */
String nTag = t.next.image.substring(1); String nTag = t.next.getImage().substring(1);
if (strictEscape if (strictEscape
|| isDirective(nTag) || isDirective(nTag)
|| macroNames.containsKey(nTag) || macroNames.containsKey(nTag)
@ -1380,11 +1380,11 @@ VmNode Directive() :
String directiveName; String directiveName;
if (t.kind == VmParserConstants.BRACKETED_WORD) if (t.kind == VmParserConstants.BRACKETED_WORD)
{ {
directiveName = t.image.substring(2, t.image.length() - 1); directiveName = t.getImage().substring(2, t.getImage().length() - 1);
} }
else else
{ {
directiveName = t.image.substring(1); directiveName = t.getImage().substring(1);
} }
d = getDirective(directiveName); d = getDirective(directiveName);
@ -1459,13 +1459,13 @@ VmNode Directive() :
else if (isVM) else if (isVM)
{ {
throw new MacroParseException("Invalid arg #" throw new MacroParseException("Invalid arg #"
+ argPos + " in VM " + t.image, currentTemplateName, t); + argPos + " in VM " + t.getImage(), currentTemplateName, t);
} }
/* if #foreach and it's the 2nd arg, ok */ /* if #foreach and it's the 2nd arg, ok */
else if (d != null && (!directiveName.equals("foreach") || argPos != 1)) else if (d != null && (!directiveName.equals("foreach") || argPos != 1))
{ {
throw new MacroParseException("Invalid arg #" throw new MacroParseException("Invalid arg #"
+ argPos + " in directive " + t.image, currentTemplateName, t); + argPos + " in directive " + t.getImage(), currentTemplateName, t);
} }
else else
{ {
@ -1505,7 +1505,7 @@ VmNode Directive() :
throw new MacroParseException("A macro declaration requires at least a name argument" throw new MacroParseException("A macro declaration requires at least a name argument"
, currentTemplateName, t); , currentTemplateName, t);
} }
/** /**
* Not a directive * Not a directive
*/ */
@ -1533,7 +1533,7 @@ VmNode Directive() :
{ {
// Add the macro name so that we can peform escape processing // Add the macro name so that we can peform escape processing
// on defined macros // on defined macros
String macroName = ((AbstractVmNode)jjtThis.jjtGetChild(0)).getFirstToken().image; String macroName = ((AbstractVmNode)jjtThis.jjtGetChild(0)).getFirstToken().getImage();
macroNames.put(macroName, macroName); macroNames.put(macroName, macroName);
} }
/* /*