Exemple #1
0
 public Token(TreeToken treeToken)
 {
     Clip     = treeToken.Clip;
     Type     = treeToken.Type;
     Value    = treeToken.Value;
     Position = treeToken.Position;
 }
Exemple #2
0
        public static ProcessResult <TreeToken> CreateSyntaxTree(Token[] tokens)
        {
            // todo: support for nested statements need to be added here as well
            // todo: Parameters for commands need to be nested under their respective commands, otherwise the unpacking logic won't work properly...
            // e.g. loop 4 rat 2 3|4|5x2 6 currently leads to the 4 bleeding into the ratchet parameter list
            var rootToken      = new TreeToken(TokenType.Root, "", 0);
            var insertionPoint = rootToken;

            for (var i = 0; i < tokens.Length; i++)
            {
                var token = tokens[i];
                if (token.IsCommand && insertionPoint.Type != TokenType.Root)
                {
                    insertionPoint = insertionPoint.Parent;
                }
                if (i > 0 && tokens[i - 1].IsCommand && !token.IsCommand)
                {
                    insertionPoint = insertionPoint.Children[^ 1];
Exemple #3
0
        private static ProcessResultArray <Token> ResolveAndFlattenSyntaxTree(TreeToken syntaxTree)
        {
            var flattenedTokens = new List <Token>();

            while (!syntaxTree.Children.All(x => x.AllValuesFetched))
            {
                foreach (var treeToken in syntaxTree.Children)
                {
                    var res = treeToken.FlattenedValues;
                    if (res.Success)
                    {
                        flattenedTokens.AddRange(res.Result);
                    }
                    else
                    {
                        return(res);
                    }
                }
            }
            return(new ProcessResultArray <Token>(flattenedTokens.ToArray()));
        }