Represents the context that is used for the current input query.
Ejemplo 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;
        }
Ejemplo n.º 2
0
 public FunctionKeyword(Int32 line, Int32 column, QueryContext query)
     : this()
 {
     Query = query;
     StartLine = line;
     StartColumn = column;
 }
Ejemplo n.º 3
0
 public DoKeyword(Int32 line, Int32 column, QueryContext query)
     : this()
 {
     StartLine = line;
     StartColumn = column;
     Query = query;
 }
Ejemplo 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;
 }
Ejemplo n.º 5
0
 public BreakKeyword(Int32 line, Int32 column, QueryContext query)
     : this()
 {
     Query = query;
     StartLine = line;
     StartColumn = column;
     Length = Token.Length;
 }
Ejemplo n.º 6
0
        QueryContext GetBreakableContext(QueryContext context)
        {
            if (!context.CurrentStatement.IsKeyword<BreakableKeyword>())
            {
                context.Stop();
                return GetBreakableContext(context.Parent);
            }

            return context;
        }
Ejemplo 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;
 }
Ejemplo 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);
            }
        }
Ejemplo 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();
        }
Ejemplo 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;
 }
Ejemplo 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;
 }
Ejemplo 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;
 }
Ejemplo 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;
 }
Ejemplo 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);
            };
        }