示例#1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ParseResult{T}"/> class.
 /// </summary>
 /// <param name="startPosition">The start position.</param>
 /// <param name="position">The position.</param>
 /// <param name="error">The parse error that occured.</param>
 public ParseResult(int startPosition, int position, IParseError error)
 {
     StartPosition = startPosition;
     Position      = position;
     Error         = error;
     Success       = false;
 }
示例#2
0
        private static void tokenError(string what, ref IParseError parseError, Collision collision)
        {
            switch (collision)
            {
            case Collision._keyword:
                parseError.Error     = true;
                parseError.ErrorInfo = String.Format("a keyword can not be used as a {0} name", what);
                break;

            case Collision._type:
                parseError.Error     = true;
                parseError.ErrorInfo = String.Format("a type can not be used as a {0} name", what);
                break;

            case Collision._var:
                parseError.Error     = true;
                parseError.ErrorInfo = String.Format("a variable can not be use as a {0} name", what);
                break;

            case Collision._none:
                parseError.Error     = true;
                parseError.ErrorInfo = String.Format("the {0} has invalid characters in it's name", what);
                break;
            }
        }
示例#3
0
 public ParseResult(IParseError error)
 {
     ParseError         = error ?? throw new ArgumentNullException(nameof(error));
     TargetCommand      = error.Command;
     RemainingOperands  = new string[0];
     SeparatedArguments = new string[0];
 }
示例#4
0
        private DeclareExpression(IParser parser, IEnumerable <IToken> tokens, ref IParseError parseError)
        {
            this.tokens = tokens;
            IToken keyword, var_name, var_type, end;
            int    count = F.count <IToken>(tokens);

            if (count == 4)   // declare name type end
            {
                keyword = F.first <IToken>(tokens);
                IEnumerable <IToken> rest = F.rest <IToken>(tokens);
                var_name = F.first <IToken>(rest);
                rest     = F.rest <IToken>(rest);
                var_type = F.first <IToken>(rest);
                rest     = F.rest <IToken>(rest);
                end      = F.first <IToken>(rest);
                Collision collision = Collision._none;
                if (VariableVerifier.Verify(var_name.Info, parser.Keywords, parser.Types, parser.Variables, ref collision))
                {
                    if (TypeVerifier.Verify(var_type.Info, parser.Keywords, parser.Types, parser.Variables, ref collision))
                    {
                    }
                    else
                    {
                        tokenError("type", ref parseError, collision);
                    }
                }
                else
                {
                    tokenError("variable", ref parseError, collision);
                }
            }
        }
示例#5
0
        /// <summary>
        /// Adds a parse error to this instance.
        /// </summary>
        /// <param name="error">The error to add.</param>
        public virtual void AddError(IParseError error)
        {
            if (error == null)
            {
                throw new ArgumentNullException(nameof(error));
            }

            this.errors.Add(error);
        }
示例#6
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////
        // NON-PUBLIC PROCEDURES
        /////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Occurs when a mouse is double-clicked.
        /// </summary>
        /// <param name="sender">The sender of the event.</param>
        /// <param name="e">A <see cref="MouseButtonEventArgs"/> that contains the event data.</param>
        private void OnErrorListViewDoubleClick(object sender, MouseButtonEventArgs e)
        {
            ListBox     listBox = (ListBox)sender;
            IParseError error   = listBox.SelectedItem as IParseError;

            if (error != null)
            {
                editor.ActiveView.Selection.StartPosition = error.PositionRange.StartPosition;
                editor.Focus();
            }
        }
        // return null if this token isn't for this expression parser
        public IExpression Parse(IParser parser, IStream <IToken> tokenStream, ref IParseError parseError)
        {
            IExpression    declareExpression = null;
            IList <IToken> tokens            = new List <IToken>();
            IToken         token             = tokenStream.Get(); // the first is the keyword

            if ((token.Kind == TokenKind.UnquotedWord) && (token.Info == keywords.comment))
            {
                while ((token.Kind != TokenKind.NULL) && (!((token.Kind == TokenKind.UnquotedWord) && (token.Info == keywords.end))))
                {
                    tokens.Add(token);
                    token = tokenStream.Get();
                }
                tokens.Add(token);
                declareExpression = DeclareExpression.Create(parser, tokens, ref parseError);
            }
            else
            {
                tokenStream.Push(token);
            }
            return(declareExpression);
        }
 /// <summary>
 /// Adds an error to the parse result.
 /// </summary>
 /// <param name="error">The error to add to the parse result.</param>
 public void AddError(IParseError error)
 {
     this.ParseResult.AddError(error);
 }
示例#9
0
 public static IExpression Create(IParser parser, IEnumerable <IToken> tokens, ref IParseError parseError)
 {
     return(new DeclareExpression(parser, tokens, ref parseError));
 }