Represents the context that is used for the current input query.
Esempio n. 1
0
        public override Expression Scan(ParseEngine engine)
        {
            var start = engine.Pointer;
            var chars = engine.Characters;

            if (chars[start] == '{')
            {
                var index = start;
                var line = engine.CurrentLine;
                var column = engine.CurrentColumn;
                engine.Advance();
                index++;
                var query = engine.Query;
                var scope = new QueryContext(query, query.Input.Substring(index));
                var eng = scope.Parser.SetOffset(line, column + 1).Parse();

                if (!eng.IsTerminated)
                {
                    engine.AddError(new YAMPScopeNotClosedError(line, column));
                }

                foreach (var error in eng.Errors)
                {
                    engine.AddError(error);
                }

                engine.Advance(eng.Pointer);
                return new GroupExpression(line, column, engine.Pointer - start, scope);
            }

            return null;
        }
Esempio n. 2
0
 public FunctionKeyword(Int32 line, Int32 column, QueryContext query)
     : this()
 {
     Query = query;
     StartLine = line;
     StartColumn = column;
 }
Esempio n. 3
0
 public DoKeyword(Int32 line, Int32 column, QueryContext query)
     : this()
 {
     StartLine = line;
     StartColumn = column;
     Query = query;
 }
Esempio n. 4
0
 /// <summary>
 /// Creates a new instance with some parameters.
 /// </summary>
 /// <param name="line">The line where the scope expression starts.</param>
 /// <param name="column">The column in the line where the scope exp. starts.</param>
 /// <param name="length">The length of the scope expression.</param>
 /// <param name="scope">The associated query context (scope).</param>
 public GroupExpression(Int32 line, Int32 column, Int32 length, QueryContext scope)
     : base(scope.Parent, line, column)
 {
     _scope = scope;
     IsSingleStatement = true;
     Length = length;
 }
Esempio n. 5
0
 public BreakKeyword(Int32 line, Int32 column, QueryContext query)
     : this()
 {
     Query = query;
     StartLine = line;
     StartColumn = column;
     Length = Token.Length;
 }
Esempio n. 6
0
        QueryContext GetBreakableContext(QueryContext context)
        {
            if (!context.CurrentStatement.IsKeyword<BreakableKeyword>())
            {
                context.Stop();
                return GetBreakableContext(context.Parent);
            }

            return context;
        }
Esempio n. 7
0
 /// <summary>
 /// Creates a new instance of the parse engine.
 /// </summary>
 /// <param name="query">The query context to consider.</param>
 /// <param name="context">The parser context to use.</param>
 public ParseEngine(QueryContext query, ParseContext context)
 {
     _context = context;
     _query = query;
     _characters = query.Input.ToCharArray();
     _errors = new List<YAMPParseError>();
     _statements = new List<Statement>();
     _markers = Marker.None;
     _currentLine = 1;
     _currentColumn = 1;
 }
Esempio n. 8
0
        void StopAllContexts(QueryContext context)
        {
            context.Stop();
            context.CurrentStatement.IsMuted = false;

            if (context.CurrentStatement.IsKeyword<BreakableKeyword>())
            {
                context.CurrentStatement.GetKeyword<BreakableKeyword>().Break();
            }

            if (context.Parent != null)
            {
                StopAllContexts(context.Parent);
            }
        }
Esempio n. 9
0
        public Value Function(StringValue code)
        {
            var c = new ParseContext(Context);
            var q = new QueryContext(c, code.Value);
            var p = new ParseEngine(q, c).Parse();

            if (p.CanRun)
            {
                foreach (var statement in p.Statements)
                {
                    return statement.Interpret(new Dictionary<String, Value>());
                }
            }

            return new StringValue();
        }
Esempio n. 10
0
 /// <summary>
 /// Creates a new instance with some parameters.
 /// </summary>
 /// <param name="line">The line where the matrix expression starts.</param>
 /// <param name="column">The column in the line where the matrix exp. starts.</param>
 /// <param name="length">The length of the matrix expression.</param>
 /// <param name="query">The associated query context.</param>
 /// <param name="child">The child containing the column and rows.</param>
 public MatrixExpression(Int32 line, Int32 column, Int32 length, QueryContext query, ContainerExpression child)
     : base(child, query, line, column)
 {
     Length = length;
 }
Esempio n. 11
0
 /// <summary>
 /// Creates a new (underlying) QueryContext
 /// </summary>
 /// <param name="query">The query context to copy</param>
 /// <param name="input">The new input to use.</param>
 internal QueryContext(QueryContext query, String input)
     : this(query._context, input)
 {
     Parent = query;
     _parser.Parent = query.Parser;
 }
Esempio n. 12
0
 /// <summary>
 /// Execute the parsing of the given input.
 /// </summary>
 /// <param name="input">The input to parse.</param>
 /// <returns>The query context for further evaluation.</returns>
 public QueryContext Parse(String input)
 {
     var query = new QueryContext(_primary, input);
     query.Parser.Parse();
     return query;
 }
Esempio n. 13
0
 /// <summary>
 /// Execute the evaluation of this parser instance with external symbols.
 /// </summary>
 /// <param name="input">The input to evaluate.</param>
 /// <param name="values">
 /// The values in an Hashtable containing string (name), Value (value) pairs.
 /// </param>
 /// <returns>The value from the evaluation.</returns>
 public Value Evaluate(String input, Dictionary<String, Value> values)
 {
     var query = new QueryContext(_primary, input);
     query.Run(values);
     return query.Output;
 }
Esempio n. 14
0
        /// <summary>
        /// Creates a new FunctionValue with data to parse.
        /// </summary>
        /// <param name="arguments">The list of argument identifiers.</param>
        /// <param name="body">The string representation of the body.</param>
        public FunctionValue(String[] arguments, String body)
        {
            _arguments = arguments;
            _body = body;
            _canSerialize = true;

            _perform = (context, argument) =>
            {
                var query = new QueryContext(context, body);
                var expression = query.Parser.ParseStatement().Container;
                SetPerform(arguments, expression);
                return Perform(context, argument);
            };
        }