Skip to content

Commit

Permalink
Merge pull request #108 from ortus-boxlang/development
Browse files Browse the repository at this point in the history
1.0.0-Beta14
  • Loading branch information
lmajano authored Sep 13, 2024
2 parents 53596b9 + 857bffd commit 6a624ae
Show file tree
Hide file tree
Showing 95 changed files with 2,887 additions and 1,420 deletions.
11 changes: 0 additions & 11 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,6 @@
"mainClass": "ortus.boxlang.runtime.BoxRunner",
"projectName": "boxlang"
},
{
"type": "java",
"name": "CrazyFileTest",
"request": "launch",
"mainClass": "ortus.boxlang.runtime.BoxRunner",
"projectName": "boxlang",
"args": [
"--debugger",
"CrazyFileTest.cfs"
]
},
{
"type": "java",
"name": "Current File",
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ dependencies {
// https://mvnrepository.com/artifact/org.slf4j/slf4j-api
implementation 'org.slf4j:slf4j-api:2.0.16'
// https://mvnrepository.com/artifact/ch.qos.logback/logback-classic
implementation 'ch.qos.logback:logback-classic:1.5.7'
implementation 'ch.qos.logback:logback-classic:1.5.8'
// https://mvnrepository.com/artifact/com.zaxxer/HikariCP
implementation 'com.zaxxer:HikariCP:5.1.0'
// https://mvnrepository.com/artifact/org.ow2.asm/asm-tree
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Fri Aug 30 16:46:29 UTC 2024
#Fri Sep 06 12:03:20 UTC 2024
antlrVersion=4.13.1
jdkVersion=21
version=1.0.0-beta13
version=1.0.0-beta14
1 change: 0 additions & 1 deletion gradle/boxlang-miniserver
Submodule boxlang-miniserver deleted from e5a0d8
1 change: 1 addition & 0 deletions src/main/antlr/BoxScriptGrammar.g4
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ relOps
| GE
| GTESIGN
| TEQ
| TENQ
| LTE
| LE
| LTESIGN
Expand Down
1 change: 1 addition & 0 deletions src/main/antlr/BoxScriptLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ MODEQUAL : '%=';
PLUS : '+';
PLUSPLUS : '++';
TEQ : '===';
TENQ : '!==';

// BITWISE OPERATORS
BITWISE_OR : 'b|';
Expand Down
1 change: 1 addition & 0 deletions src/main/antlr/CFScriptGrammar.g4
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ relOps
| GE
| GTESIGN
| TEQ
| TENQ
| LTE
| LE
| LTESIGN
Expand Down
1 change: 1 addition & 0 deletions src/main/antlr/CFScriptLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ MODEQUAL : '%=';
PLUS : '+';
PLUSPLUS : '++';
TEQ : '===';
TENQ : '!==';

// BITWISE OPERATORS
BITWISE_OR : 'b|';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public enum BoxComparisonOperator {
LessThanEquals,
NotEqual,
Contains,
TEqual;
TEqual,
TNotEqual;

public String getSymbol() {
switch ( this ) {
Expand All @@ -43,6 +44,8 @@ public String getSymbol() {
return "contains";
case TEqual :
return "===";
case TNotEqual :
return "!==";
default :
return "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package ortus.boxlang.compiler.ast.visitor;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -27,6 +28,7 @@
import ortus.boxlang.compiler.ast.BoxExpression;
import ortus.boxlang.compiler.ast.BoxNode;
import ortus.boxlang.compiler.ast.BoxStatement;
import ortus.boxlang.compiler.ast.SourceFile;
import ortus.boxlang.compiler.ast.comment.BoxSingleLineComment;
import ortus.boxlang.compiler.ast.expression.BoxAccess;
import ortus.boxlang.compiler.ast.expression.BoxArgument;
Expand Down Expand Up @@ -93,6 +95,7 @@ public class CFTranspilerVisitor extends ReplacingBoxVisitor {
private static BoxRuntime runtime = BoxRuntime.getInstance();
private static ModuleService moduleService = runtime.getModuleService();
private boolean isClass = false;
private String className = "";
private boolean upperCaseKeys = true;
private boolean forceOutputTrue = true;
private boolean mergeDocsIntoAnnotations = true;
Expand Down Expand Up @@ -190,6 +193,13 @@ public CFTranspilerVisitor( IStruct settings ) {
public BoxNode visit( BoxClass node ) {
var annotations = node.getAnnotations();
this.isClass = true;

// We don't store the class name in the AST since it's based on the file name, so try and see the filename we compiled.
if ( node.getPosition() != null && node.getPosition().getSource() != null && node.getPosition().getSource() instanceof SourceFile sf ) {
File sourceFile = sf.getFile();
className = sourceFile.getName().replaceFirst( "[.][^.]+$", "" );
}

mergeDocsIntoAnnotations( annotations, node.getDocumentation() );

// Disable Accessors by default in CFML, unless there is a parent class, in which case don't add so we can inherit
Expand All @@ -213,13 +223,17 @@ public BoxNode visit( BoxClass node ) {
* Transpile UDF declarations
* - Merge documentation into annotations
* - enable output
* - rename onCFCRequest to onClassRequest
*/
@Override
public BoxNode visit( BoxFunctionDeclaration node ) {
mergeDocsIntoAnnotations( node.getAnnotations(), node.getDocumentation() );
// Don't touch UDFs in a class, otherwise they won't inherit from the class's output annotation.
if ( node.getFirstAncestorOfType( BoxClass.class ) == null ) {
if ( isClass ) {
enableOutput( node.getAnnotations() );
if ( node.getName().equalsIgnoreCase( "onCFCRequest" ) && className.equalsIgnoreCase( "application" ) ) {
node.setName( "onClassRequest" );
}
}
return super.visit( node );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private void processName( BoxNode node, IStruct meta ) {
File sourceFile = sf.getFile();
var contractedPath = FileSystemUtil.contractPath( context, sourceFile.toString() );
String name = sourceFile.getName().replaceFirst( "[.][^.]+$", "" );
String packageName = FQN.of( Paths.get( contractedPath.relativePath() ) ).toString();
String packageName = FQN.of( Paths.get( contractedPath.relativePath() ) ).getPackageString();
String fullName = packageName.length() > 0 ? packageName + "." + name : name;
meta.put( Key._NAME, name );
meta.put( Key.fullname, fullName );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public class BoxClassTransformer extends AbstractTransformer {
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Optional;
Expand All @@ -143,6 +144,7 @@ public class ${className} ${extendsTemplate} implements ${interfaceList} {
private static final Map<Key,Property> getterLookup=null;
private static final Map<Key,Property> setterLookup=null;
private static Map<Key, AbstractFunction> abstractMethods = new LinkedHashMap<>();
private static Set<Key> compileTimeMethodNames = ${compileTimeMethodNames};
private static final boolean isJavaExtends=${isJavaExtends};
private static StaticScope staticScope = new StaticScope();
// This is public so the ClassLocator can check it easily
Expand Down Expand Up @@ -189,6 +191,10 @@ public Map<Key, AbstractFunction> getAllAbstractMethods() {
return allAbstractMethods;
}
public Set<Key> getCompileTimeMethodNames() {
return compileTimeMethodNames;
}
public BoxMeta _getbx() {
return this.$bx;
}
Expand Down Expand Up @@ -528,7 +534,8 @@ public Node transform( BoxNode node, TransformerContext context ) throws Illegal
Map.entry( "resolvedFilePath", transpiler.getResolvedFilePath( mappingName, mappingPath, relativePath, filePath ) ),
Map.entry( "compiledOnTimestamp", transpiler.getDateTime( LocalDateTime.now() ) ),
Map.entry( "compileVersion", "1L" ),
Map.entry( "boxClassName", createKey( boxClassName ).toString() )
Map.entry( "boxClassName", createKey( boxClassName ).toString() ),
Map.entry( "compileTimeMethodNames", generateCompileTimeMethodNames( boxClass ) )
);
String code = PlaceholderHelper.resolve( CLASS_TEMPLATE, values );
ParseResult<CompilationUnit> result;
Expand Down Expand Up @@ -655,6 +662,16 @@ public Node transform( BoxNode node, TransformerContext context ) throws Illegal
return entryPoint;
}

private String generateCompileTimeMethodNames( BoxClass boxClass ) {
List<String> methodNames = boxClass.getDescendantsOfType( BoxFunctionDeclaration.class )
.stream()
.map( BoxFunctionDeclaration::getName )
.map( this::createKey )
.map( String::valueOf )
.collect( java.util.stream.Collectors.toList() );
return "Set.of(" + methodNames.stream().collect( java.util.stream.Collectors.joining( ", " ) ) + ")";
}

/**
* Transforms a collection of properties into a Map
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ public Node transform( BoxNode node, TransformerContext context ) throws Illegal
template = "!EqualsEquals.invoke(${left},${right})";
} else if ( operation.getOperator() == BoxComparisonOperator.TEqual ) {
template = "EqualsEqualsEquals.invoke(${left},${right})";
} else if ( operation.getOperator() == BoxComparisonOperator.TNotEqual ) {
template = "!EqualsEqualsEquals.invoke(${left},${right})";
} else if ( operation.getOperator() == BoxComparisonOperator.Contains ) {
template = "Contains.invoke(${left},${right})";
} else if ( operation.getOperator() == BoxComparisonOperator.GreaterThan ) {
template = "GreaterThan.invoke(${left},${right})";
} else if ( operation.getOperator() == BoxComparisonOperator.GreaterThanEquals ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@
*/
package ortus.boxlang.compiler.javaboxpiler.transformer.expression;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.NodeList;
import com.github.javaparser.ast.expr.Expression;
import com.github.javaparser.ast.expr.MethodCallExpr;
import com.github.javaparser.ast.expr.NameExpr;
import com.github.javaparser.ast.expr.StringLiteralExpr;

import ortus.boxlang.compiler.ast.BoxNode;
Expand All @@ -28,6 +36,8 @@
*/
public class BoxStringLiteralTransformer extends AbstractTransformer {

private static final int MAX_LITERAL_LENGTH = 30000; // 64KB limit

public BoxStringLiteralTransformer( JavaTranspiler transpiler ) {
super( transpiler );
}
Expand All @@ -38,15 +48,55 @@ public BoxStringLiteralTransformer( JavaTranspiler transpiler ) {
* @param node a BoxStringLiteral instance
* @param context transformation context
*
* @return generates a Java Parser string Literal
* @return generates a Java Parser string Literal or concatenation expression
*/
@Override
public Node transform( BoxNode node, TransformerContext context ) throws IllegalStateException {
BoxStringLiteral literal = ( BoxStringLiteral ) node;
StringLiteralExpr expr = new StringLiteralExpr( escape( literal.getValue() ) );
String side = context == TransformerContext.NONE ? "" : "(" + context.toString() + ") ";
// logger.trace( side + node.getSourceText() + " -> " + expr );
return expr;
String value = escape( literal.getValue() );

if ( value.length() > MAX_LITERAL_LENGTH ) {
List<String> parts = splitStringIntoParts( value );
return createArrayJoinMethodCall( parts );
} else {
return new StringLiteralExpr( value );
}
}

/**
* Split a large string into parts
*
* @param str The input string.
*
* @return A list of StringLiteralExpr parts.
**/
private List<String> splitStringIntoParts( String str ) {
List<String> parts = new ArrayList<>();
int length = str.length();
for ( int i = 0; i < length; i += MAX_LITERAL_LENGTH ) {
int end = Math.min( length, i + MAX_LITERAL_LENGTH );
String part = str.substring( i, end );
parts.add( part );
}
return parts;
}

/**
* Create a BinaryExpr that concatenates all the StringLiteralExpr parts
*
* @param parts List of StringLiteralExpr parts.
*
* @return A BinaryExpr representing the concatenation of all parts.
**/
private Expression createArrayJoinMethodCall( List<String> parts ) {
// Create a MethodCallExpr for String.join with an array of strings
var args = parts.stream()
.map( part -> ( Expression ) new StringLiteralExpr( escape( part ) ) ) // Escape quotes and create StringLiteralExpr
.collect( Collectors.toCollection( NodeList::new ) ); // Collect into NodeList
args.add( 0, new StringLiteralExpr( "" ) ); // Delimiter
MethodCallExpr joinMethodCall = new MethodCallExpr( new NameExpr( "String" ), "join", args );

return joinMethodCall;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,7 @@ public BoxComparisonOperator buildRelOp( RelOpsContext ctx ) {
case "GT", ">", "GREATERTHAN" -> BoxComparisonOperator.GreaterThan;
case "GTE", ">=", "GE", "GREATERTHANOREQTO", "GREATERTHANOREQUALTO" -> BoxComparisonOperator.GreaterThanEquals;
case "===" -> BoxComparisonOperator.TEqual;
case "!==" -> BoxComparisonOperator.TNotEqual;
case "LE", "<=", "LTE", "LESSTHANOREQTO", "LESSTHANOREQUALTO" -> BoxComparisonOperator.LessThanEquals;
case "LT", "<", "LESSTHAN" -> BoxComparisonOperator.LessThan;
case "NEQ", "!=", "NOTEQUAL", "ISNOT", "<>" -> BoxComparisonOperator.NotEqual;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,7 @@ public BoxComparisonOperator buildRelOp( RelOpsContext ctx ) {
case "GT", ">", "GREATERTHAN" -> BoxComparisonOperator.GreaterThan;
case "GTE", ">=", "GE", "GREATERTHANOREQTO", "GREATERTHANOREQUALTO" -> BoxComparisonOperator.GreaterThanEquals;
case "===" -> BoxComparisonOperator.TEqual;
case "!==" -> BoxComparisonOperator.TNotEqual;
case "LE", "<=", "LTE", "LESSTHANOREQTO", "LESSTHANOREQUALTO" -> BoxComparisonOperator.LessThanEquals;
case "LT", "<", "LESSTHAN" -> BoxComparisonOperator.LessThan;
case "NEQ", "!=", "NOTEQUAL", "ISNOT", "<>" -> BoxComparisonOperator.NotEqual;
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/ortus/boxlang/debugger/DebugMain.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/**
* [BoxLang]
*
* Copyright [2023] [Ortus Solutions, Corp]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ortus.boxlang.debugger;

import java.util.ArrayList;
Expand All @@ -18,7 +35,6 @@ private static CLIOptions parseCommandLineOptions( String[] args ) {
List<String> argsList = new ArrayList<>( Arrays.asList( args ) );
// Initialize options with defaults
int DAPPort = 0;

String current = null;

// Consume args in order
Expand Down
Loading

0 comments on commit 6a624ae

Please sign in to comment.