Skip to content

Commit

Permalink
Поддержка парсером Асинх и Ждать
Browse files Browse the repository at this point in the history
  • Loading branch information
EvilBeaver committed Oct 10, 2023
1 parent c030fd4 commit e1480a0
Show file tree
Hide file tree
Showing 14 changed files with 198 additions and 252 deletions.
32 changes: 7 additions & 25 deletions src/OneScript.Language/LanguageDef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,13 @@ public static class LanguageDef
static readonly Dictionary<Token, int> _priority = new Dictionary<Token, int>();
public const int MAX_OPERATION_PRIORITY = 8;

private static readonly LexemTrie<Token> _stringToToken = new LexemTrie<Token>();
private static readonly IdentifiersTrie<Token> _stringToToken = new IdentifiersTrie<Token>();

private static readonly LexemTrie<bool> _undefined = new LexemTrie<bool>();
private static readonly LexemTrie<bool> _booleans = new LexemTrie<bool>();
private static readonly LexemTrie<bool> _logicalOp = new LexemTrie<bool>();
private static readonly IdentifiersTrie<bool> _undefined = new IdentifiersTrie<bool>();
private static readonly IdentifiersTrie<bool> _booleans = new IdentifiersTrie<bool>();
private static readonly IdentifiersTrie<bool> _logicalOp = new IdentifiersTrie<bool>();

private static readonly LexemTrie<bool> _preprocRegion = new LexemTrie<bool>();
private static readonly LexemTrie<bool> _preprocEndRegion = new LexemTrie<bool>();

private static readonly LexemTrie<bool> _preprocImport = new LexemTrie<bool>();
private static readonly IdentifiersTrie<bool> _preprocImport = new IdentifiersTrie<bool>();

const int BUILTINS_INDEX = (int)Token.ByValParam;

Expand Down Expand Up @@ -134,6 +131,8 @@ static LanguageDef()
AddToken(Token.Equal, "=");
AddToken(Token.Semicolon, ";");
AddToken(Token.Question, "?");
AddToken(Token.Tilde, "~");
AddToken(Token.Colon, ":");

#endregion

Expand Down Expand Up @@ -216,11 +215,6 @@ static LanguageDef()

#endregion

_preprocRegion.Add("Область",true);
_preprocRegion.Add("Region", true);
_preprocEndRegion.Add("КонецОбласти", true);
_preprocEndRegion.Add("EndRegion", true);

_preprocImport.Add("Использовать", true);
_preprocImport.Add("Use", true);
}
Expand Down Expand Up @@ -410,18 +404,6 @@ public static bool IsLogicalOperatorString(string content)
return _logicalOp.TryGetValue(content, out var nodeIsFilled) && nodeIsFilled;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsPreprocRegion(string value)
{
return _preprocRegion.TryGetValue(value, out var nodeIsFilled) && nodeIsFilled;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsPreprocEndRegion(string value)
{
return _preprocEndRegion.TryGetValue(value, out var nodeIsFilled) && nodeIsFilled;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsImportDirective(string value)
{
Expand Down
213 changes: 0 additions & 213 deletions src/OneScript.Language/LexemTrie.cs

This file was deleted.

2 changes: 2 additions & 0 deletions src/OneScript.Language/LexicalAnalysis/Token.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public enum Token
RemoveHandler,
Async,
Await,
Tilde,
Colon,

// operators
Plus,
Expand Down
2 changes: 2 additions & 0 deletions src/OneScript.Language/SyntaxAnalysis/AstNodes/MethodNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public MethodNode() : base(NodeKind.Method)
{
}

public bool IsAsync { get; set; }

public MethodSignatureNode Signature { get; private set; }

public BslSyntaxNode MethodBody { get; private set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class UnaryOperationNode : NonTerminalNode
{
public Token Operation { get; }

public UnaryOperationNode(Lexem operation) : base(NodeKind.UnaryOperation)
public UnaryOperationNode(Lexem operation) : base(NodeKind.UnaryOperation, operation)
{
Operation = operation.Token;
}
Expand Down
10 changes: 10 additions & 0 deletions src/OneScript.Language/SyntaxAnalysis/BslSyntaxWalker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,20 @@ protected virtual void VisitStatement(BslSyntaxNode statement)
VisitGlobalProcedureCall(statement as CallNode);
else if (statement.Kind == NodeKind.DereferenceOperation)
VisitProcedureDereference(statement);
else if (statement.Kind == NodeKind.UnaryOperation && statement is UnaryOperationNode
{
Operation: Token.Await
} unaryOp)
VisitGlobalAwaitCall(unaryOp);
else
DefaultVisit(statement);
}

private void VisitGlobalAwaitCall(UnaryOperationNode awaitStatement)
{
VisitStatement(awaitStatement.Children[0]);
}

protected virtual void VisitAssignment(BslSyntaxNode assignment)
{
var left = assignment.Children[0];
Expand Down
Loading

0 comments on commit e1480a0

Please sign in to comment.