Skip to content

Commit

Permalink
Merge 'upstream/master' into issue_43029
Browse files Browse the repository at this point in the history
  • Loading branch information
ravinperera00 committed Sep 5, 2024
2 parents 5f118b8 + 9a6321e commit fa0cf9b
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.ballerina.compiler.syntax.tree.ExpressionNode;
import io.ballerina.compiler.syntax.tree.Node;
import io.ballerina.compiler.syntax.tree.NodeParser;
import io.ballerina.shell.parser.ParserConstants;
import io.ballerina.shell.parser.TrialTreeParser;

import java.util.ArrayList;
Expand Down Expand Up @@ -57,7 +58,16 @@ public Collection<Node> parse(String source) throws ParserTrialFailedException {
if (expressionNode.hasDiagnostics()) {
throw new ParserTrialFailedException("Error occurred during extracting expression from the statement");
}
validateExpression(expressionNode.toSourceCode());
nodes.add(expressionNode);
return nodes;
}

private void validateExpression(String expression) {
String functionName = expression.replaceAll("\\s*\\(.*", "");
if (ParserConstants.isFunctionNameRestricted(functionName)) {
String message = String.format("Function name '%s' not allowed in Ballerina Shell.%n", functionName);
throw new InvalidMethodException(message);
}
}
}
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ plugins {
apply from: "$rootDir/gradle/repositories.gradle"

allprojects {
tasks.withType(JavaCompile).configureEach {
options.fork = true
}

group = project.group
version = project.version

Expand Down Expand Up @@ -144,4 +148,3 @@ sonarqube {
}

copyBallerinaClassFiles.dependsOn copyExecFilesAndJavaClassFiles
createCodeCoverageReport.dependsOn copyBallerinaClassFiles
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private static boolean isDirectDependency(Collection<ModuleDependency> moduleDep
dependency.descriptor().packageName().value().equals(packageName) &&
(moduleName == null
? dependency.descriptor().name().moduleNamePart() == null
: dependency.descriptor().name().moduleNamePart().equals(moduleName))
: moduleName.equals(dependency.descriptor().name().moduleNamePart()))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void addObserveInternalModuleImport(BLangPackage pkgNode) {
importDcl.alias = ASTBuilderUtil.createIdentifier(pkgNode.pos, "_");
importDcl.version = ASTBuilderUtil.createIdentifier(pkgNode.pos, "");
importDcl.symbol = packageCache.getSymbol(PackageID.OBSERVE_INTERNAL);
pkgNode.imports.add(importDcl);
pkgNode.imports.add(0, importDcl);
pkgNode.symbol.imports.add(importDcl.symbol);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
}.balLogo {
padding-left: 50px !important;
padding-top: 25px !important;
object-fit: contain; !important;
object-fit: contain !important;
width: 500px !important;
height: auto !important;
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ org.gradle.vfs.watch=false
systemProp.scan.capture-build-logging=false
systemProp.scan.capture-test-logging=false

version=2201.10.0-SNAPSHOT
version=2201.11.0-SNAPSHOT
group=org.ballerinalang
bootstrappedOn=1.1.0-alpha
specVersion=2024R1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,14 @@
"metaInfo":{"definedVars":[],"moduleDclns":[]},
"consoleOut":""
}
},
{
"source": "main()",
"result": {
"errors":["Parsing the node from the statement failed."],
"diagnostics":["Function name \u0027main\u0027 not allowed in Ballerina Shell.\n"],
"metaInfo":{"definedVars":[],"moduleDclns":[]},
"consoleOut":""
}
}
]

0 comments on commit fa0cf9b

Please sign in to comment.