Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DYN-7112: Fix DS parser to error early on finding import statements in code block nodes #15288

Merged
merged 17 commits into from
Nov 8, 2024
Merged
13 changes: 9 additions & 4 deletions src/Engine/ProtoCore/Parser/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
//#define ENABLE_INC_DEC_FIX
using System;
using System.Collections.Generic;
using System.IO;
using ProtoCore.AST;
using ProtoCore.AST.AssociativeAST;
using ProtoCore.DSASM;
using ProtoCore.Properties;
using ProtoCore.Utils;
using ProtoCore.Properties;

namespace ProtoCore.DesignScriptParser
{
namespace ProtoCore.DesignScriptParser {



public class Parser {
public class Parser {
public const int _EOF = 0;
public const int _ident = 1;
public const int _number = 2;
Expand Down Expand Up @@ -890,6 +890,11 @@ void Hydrogen(out Node codeBlockNode) {
}

void Import_Statement(out ProtoCore.AST.AssociativeAST.AssociativeNode node) {
if (core.IsParsingCodeBlockNode)
{
core.BuildStatus.LogSemanticError(Resources.ImportStatementNotSupported);
}

while (!(la.kind == 0 || la.kind == 34)) {SynErr(66); Get();}
string moduleName = "", typeName = "", alias = "";

Expand Down
7 changes: 3 additions & 4 deletions src/Engine/ProtoCore/Parser/Scanner.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@

using System;
using System.Collections;
using System.IO;
using System.Collections;

namespace ProtoCore.DesignScriptParser
{
namespace ProtoCore.DesignScriptParser {

public class Token {
public class Token {
public int kind; // token kind
public int pos; // token position in bytes in the source text (starting at 0)
public int charPos; // token position in characters in the source text (starting at 0)
Expand Down
11 changes: 7 additions & 4 deletions src/Engine/ProtoCore/Parser/atg/Associative.atg
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,13 @@ Hydrogen<out Node codeBlockNode>
.

Import_Statement<out ProtoCore.AST.AssociativeAST.AssociativeNode node>
= SYNC
= (.
if (core.IsParsingCodeBlockNode)
{
core.BuildStatus.LogSemanticError(Resources.ImportStatementNotSupported);
}
.)
SYNC
(.
string moduleName = "", typeName = "", alias = "";
.)
Expand Down Expand Up @@ -2028,9 +2034,6 @@ Associative_IdentifierList<out ProtoCore.AST.AssociativeAST.AssociativeNode node
}
else
{
string rhsName = null;
ProtoCore.AST.AssociativeAST.ExprListNode dimList = null;
int dim = 0;
if (rnode is ProtoCore.AST.AssociativeAST.FunctionCallNode)
{
ProtoCore.AST.AssociativeAST.FunctionCallNode rhsFNode = rnode as ProtoCore.AST.AssociativeAST.FunctionCallNode;
Expand Down
6 changes: 1 addition & 5 deletions src/Engine/ProtoCore/Utils/CompilerUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,7 @@ private static void ParseUserCodeCore(Core core, string expression, out List<Ass
// Append the temporaries only if it is not a function def or class decl
bool isFunctionOrClassDef = n is FunctionDefinitionNode;

if (n is ImportNode)
{
core.BuildStatus.LogSemanticError(Resources.ImportStatementNotSupported);
}
else if (n is ClassDeclNode)
if (n is ClassDeclNode)
{
core.BuildStatus.LogSemanticError(Resources.ClassDeclarationNotSupported);
}
Expand Down
Loading