Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions cfml.parsing/src/main/antlr4/cfml/CFSCRIPTParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,11 @@ cfmlExpression

// FINAL is Lucee's immutable local; it takes the same shape as VAR and may combine
// with it, as in `final var x = 1;`.
localAssignmentExpression
: (VAR | FINAL VAR? | VAR FINAL) left=startExpression ( (EQUALSOP otherIdentifiers)* EQUALSOP right=startExpression )? //-> ^( VARLOCAL identifier ( EQUALSOP baseExpression )? )
// STATIC sits here alongside FINAL because `static x = 1;` is a declaration, not a function.
// Without it, STATIC is only reachable as a functionModifier, so functionDeclaration wins
// prediction and then finds no FUNCTION token -- see #63.
localAssignmentExpression
: (VAR | (FINAL | STATIC) VAR? | VAR (FINAL | STATIC)) left=startExpression ( (EQUALSOP otherIdentifiers)* EQUALSOP right=startExpression )? //-> ^( VARLOCAL identifier ( EQUALSOP baseExpression )? )
;

otherIdentifiers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class CFVarDeclExpression extends CFExpression {
private CFExpression init; // null if none
/** True for Lucee's `final x = 1;`, which is a different declaration from `var x = 1;`. */
private boolean finalDecl = false;
/** True for `static x = 1;`, a component-level static member rather than a local. */
private boolean staticDecl = false;
List<CFIdentifier> otherVars = new ArrayList<CFIdentifier>();
List<CFIdentifier> otherIds = new ArrayList<CFIdentifier>();

Expand All @@ -42,7 +44,7 @@ public CFVarDeclExpression(Token _t, CFExpression _var, CFExpression _init) {
@Override
public String Decompile(int indent) {
StringBuilder s = new StringBuilder(Indent(indent));
s.append(finalDecl ? "final " : "var ");
s.append(staticDecl ? "static " : finalDecl ? "final " : "var ");
s.append(var.Decompile(0));
for (CFIdentifier id : otherVars) {
s.append(" = var ");
Expand All @@ -66,6 +68,14 @@ public boolean isFinal() {
public void setFinal(boolean b) {
finalDecl = b;
}

public boolean isStatic() {
return staticDecl;
}

public void setStatic(boolean b) {
staticDecl = b;
}

public CFExpression getInit() {
return init;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ public CFExpression visitLocalAssignmentExpression(LocalAssignmentExpressionCont
final CFExpression initExpression = ctx.right == null ? null : visit(ctx.right);
CFVarDeclExpression retval = new CFVarDeclExpression(ctx.start, visit(ctx.left), initExpression);
retval.setFinal(ctx.FINAL() != null);
retval.setStatic(ctx.STATIC() != null);
if (ctx.otherIdentifiers().size() > 0) {
for (OtherIdentifiersContext oi : ctx.otherIdentifiers()) {
CFIdentifier otherid = (CFIdentifier) visit(oi.identifier());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
component {
static myStatic = "v";
final myConst = "c";

function f() {
var local1 = myStatic;
return local1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/*===TOKENS===*/
COMPONENT <component>
'{' <{>
Hidden:NEWLINE <>
STATIC <static>
IDENTIFIER <myStatic>
'=' <=>
OPEN_STRING <">
STRING_LITERAL <v>
CLOSE_STRING <">
';' <;>
Hidden:NEWLINE <>
FINAL <final>
IDENTIFIER <myConst>
'=' <=>
OPEN_STRING <">
STRING_LITERAL <c>
CLOSE_STRING <">
';' <;>
Hidden:NEWLINE <>
FUNCTION <function>
IDENTIFIER <f>
'(' <(>
')' <)>
'{' <{>
Hidden:NEWLINE <>
VAR <var>
IDENTIFIER <local1>
'=' <=>
IDENTIFIER <myStatic>
';' <;>
Hidden:NEWLINE <>
RETURN <return>
IDENTIFIER <local1>
';' <;>
Hidden:NEWLINE <>
'}' <}>
Hidden:NEWLINE <>
'}' <}>
Hidden:NEWLINE <>
/*===TREE===*/
(scriptBlock
(componentDeclaration
component
(componentGuts
{
(element
(statement
(localAssignmentExpression
static
(startExpression
(baseExpression (unaryExpression (memberExpression (identifier myStatic))))
)
=
(startExpression
(baseExpression
(unaryExpression
(primaryExpression
(literalExpression (stringLiteral " (stringLiteralPart v) "))
)
)
)
)
)
(endOfStatement ;)
)
)
(element
(statement
(localAssignmentExpression
final
(startExpression
(baseExpression (unaryExpression (memberExpression (identifier myConst))))
)
=
(startExpression
(baseExpression
(unaryExpression
(primaryExpression
(literalExpression (stringLiteral " (stringLiteralPart c) "))
)
)
)
)
)
(endOfStatement ;)
)
)
(element
(functionDeclaration
function
(identifier f)
(
parameterList
)
(compoundStatement
{
(statement
(localAssignmentExpression
var
(startExpression
(baseExpression (unaryExpression (memberExpression (identifier local1))))
)
=
(startExpression
(baseExpression (unaryExpression (memberExpression (identifier myStatic))))
)
)
(endOfStatement ;)
)
(statement
(returnStatement
return
(anExpression
(startExpression
(baseExpression (unaryExpression (memberExpression (identifier local1))))
)
)
)
(endOfStatement ;)
)
}
)
)
)
}
)
)
)
/*======*/
/*===DECOMPILE===*/
component {
{
static myStatic = 'v';
final myConst = 'c';
public function f() {
var local1 = myStatic;
return local1;

};

}
}
/*======*/
Loading