Esempio n. 1
0
        public void TestAppendString()
        {
            var expr = new KeywordExpression("for");

            var builder = new StringBuilder();

            expr.AppendString(builder);
            Assert.That(builder.ToString(), Is.EqualTo("for"));
        }
Esempio n. 2
0
 protected virtual void Visit(KeywordExpression keywordExpression)
 {
     // A discard will be transformed to 'return'
     if (keywordExpression.Name.Text == "discard")
     {
         Write("return");
     }
     else
     {
         base.Visit(keywordExpression);
     }
 }
Esempio n. 3
0
        static bool TryParseAtomic(ref TokenParser parser,
                                   [MaybeNullWhen(returnValue: false)] out Expression expr)
        {
            // We can parse keywords, parameter names and constants
            expr = null;
            if (parser.TryParseKeywordLowerCase("this.startingvalue"))
            {
                expr = new KeywordExpression(ExpressionKeyword.StartingValue);
            }
            else if (parser.TryParseKeywordLowerCase("this.currentvalue"))
            {
                expr = new KeywordExpression(ExpressionKeyword.CurrentValue);
            }
            else if (parser.TryParseKeywordLowerCase("this.finalvalue"))
            {
                expr = new KeywordExpression(ExpressionKeyword.FinalValue);
            }
            else if (parser.TryParseKeywordLowerCase("pi"))
            {
                expr = new KeywordExpression(ExpressionKeyword.Pi);
            }
            else if (parser.TryParseKeywordLowerCase("true"))
            {
                expr = new KeywordExpression(ExpressionKeyword.True);
            }
            else if (parser.TryParseKeywordLowerCase("false"))
            {
                expr = new KeywordExpression(ExpressionKeyword.False);
            }
            else if (parser.TryParseKeywordLowerCase("this.target"))
            {
                expr = new KeywordExpression(ExpressionKeyword.Target);
            }

            if (expr != null)
            {
                return(true);
            }

            if (parser.TryParseIdentifier(out var identifier))
            {
                expr = new ParameterExpression(identifier.ToString());
                return(true);
            }

            if (parser.TryParseFloat(out var scalar))
            {
                expr = new ConstantExpression(scalar);
                return(true);
            }

            return(false);
        }
Esempio n. 4
0
 /// <summary>
 /// Visits the specified keyword expression.
 /// </summary>
 /// <param name="keywordExpression">The keyword expression.</param>
 public override void Visit(KeywordExpression keywordExpression)
 {
     // A discard will be transformed to 'return'
     if (keywordExpression.Name.Text == "discard")
     {
         WriteLinkLine(keywordExpression);
         WriteLine("context.Discard();");
     }
     else
     {
         base.Visit(keywordExpression);
     }
 }
        /// <summary>
        /// Checks for errors before applying a rule.
        /// </summary>
        /// <param name="node">The node instance to check.</param>
        /// <param name="dataList">Optional data collected during inspection of sources.</param>
        /// <param name="data">Private data to give to Apply() upon return.</param>
        /// <returns>True if an error occured.</returns>
        public override bool CheckConsistency(IKeywordExpression node, IDictionary <ISourceTemplate, object> dataList, out object data)
        {
            data = null;
            bool Success = true;

            Success &= KeywordExpression.ResolveCompilerReferences(node, ErrorList, out IResultType ResolvedResult, out IResultException ResolvedException, out ISealableList <IExpression> ConstantSourceList, out ILanguageConstant ExpressionConstant);

            if (Success)
            {
                data = new Tuple <IResultType, IResultException, ISealableList <IExpression>, ILanguageConstant>(ResolvedResult, ResolvedException, ConstantSourceList, ExpressionConstant);
            }

            return(Success);
        }
Esempio n. 6
0
        public override void Visit(KeywordExpression expression)
        {
            if (expression.Name.Text == keyword)
            {
                var list = new List <Statement>(containerStack);
                list.Reverse();
                if (ParentNode is ExpressionStatement)
                {
                    list.Add(ParentNode as ExpressionStatement);
                }
                else
                {
                    parserResult.Error("{0} keyword detected, but outside of an ExpressionStatement. It is impossible to unroll the loop", expression.Span, keyword);
                }

                scopeList.Add(list);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Checks for errors before applying a rule.
        /// </summary>
        /// <param name="node">The node instance to check.</param>
        /// <param name="dataList">Optional data collected during inspection of sources.</param>
        /// <param name="data">Private data to give to Apply() upon return.</param>
        /// <returns>True if an error occured.</returns>
        public override bool CheckConsistency(IKeywordAnchoredType node, IDictionary <ISourceTemplate, object> dataList, out object data)
        {
            bool Success = true;

            data = null;

            // The 'Current' case is handled in KeywordAnchoredTypeCurrentRuleTemplate.
            if (node.Anchor != BaseNode.Keyword.Current)
            {
                IClass     EmbeddingClass = node.EmbeddingClass;
                IErrorList CheckErrorList = new ErrorList();
                if (!KeywordExpression.IsKeywordAvailable(node.Anchor, node, CheckErrorList, out ITypeName ResultTypeName, out ICompiledType ResultType))
                {
                    AddSourceErrorList(CheckErrorList);
                    Success = false;
                }
                else
                {
                    data = new Tuple <ITypeName, ICompiledType>(ResultTypeName, ResultType);
                }
            }
Esempio n. 8
0
        /// <summary>
        /// Checks for errors before applying a rule.
        /// </summary>
        /// <param name="node">The node instance to check.</param>
        /// <param name="dataList">Optional data collected during inspection of sources.</param>
        /// <param name="data">Private data to give to Apply() upon return.</param>
        /// <returns>True if an error occured.</returns>
        public override bool CheckConsistency(IKeywordAnchoredType node, IDictionary <ISourceTemplate, object> dataList, out object data)
        {
            bool Success = true;

            data = null;

            if (node.Anchor == BaseNode.Keyword.Current)
            {
                IClass     EmbeddingClass = node.EmbeddingClass;
                IErrorList CheckErrorList = new ErrorList();

                // 'Current' is always available.
                Success = KeywordExpression.IsKeywordAvailable(node.Anchor, node, CheckErrorList, out ITypeName ResultTypeName, out ICompiledType ResultType);
                Debug.Assert(Success);

                data = new Tuple <ITypeName, ICompiledType>(ResultTypeName, ResultType);
            }
            else
            {
                data = new Tuple <ITypeName, ICompiledType>(Class.ClassAny.ResolvedClassTypeName.Item, Class.ClassAny.ResolvedClassType.Item);
            }

            return(Success);
        }
 public override void Visit(KeywordExpression expression)
 {
     _expressionString.Append(" KEYWORD(PROP=");
     Visit(expression.Property);
     _expressionString.Append(", PHRASE=");
     Visit(expression.Phrase);
     _expressionString.Append(")");
 }
Esempio n. 10
0
 private static KeywordExpression Clone(KeywordExpression expression)
 {
     return(expression);
 }