Example #1
0
 public KeywordResult(
     DslKeywordSchema schema,
     KeywordContextFrame frame)
 {
     Schema = schema;
     Frame  = frame;
 }
Example #2
0
        private static KeywordResult?GetCurrentKeyword(Ast ast, IReadOnlyList <Token> tokens, IScriptPosition cursorPosition)
        {
            KeywordContext context = KeywordContext.BuildFromInput(ast, tokens, cursorPosition);

            if (context is null)
            {
                return(null);
            }

            DslKeywordSchema    currentSchema = PSArmSchemaInformation.PSArmSchema;
            KeywordContextFrame currentFrame  = null;

            for (int i = 0; i < context.KeywordStack.Count; i++)
            {
                KeywordContextFrame frame = context.KeywordStack[i];

                string commandName = frame.CommandAst.GetCommandName();

                if (commandName is null)
                {
                    continue;
                }

                IReadOnlyDictionary <string, DslKeywordSchema> subschemas = currentSchema.GetInnerKeywords(currentFrame);

                if (subschemas is null ||
                    !subschemas.TryGetValue(commandName, out DslKeywordSchema subschema))
                {
                    continue;
                }

                currentSchema = subschema;
                currentFrame  = frame;
            }

            if (currentFrame is null || currentSchema is null)
            {
                return(null);
            }

            return(new KeywordResult(currentSchema, currentFrame));
        }