Exemplo n.º 1
0
        void RaiseError(string message)
        {
            var      token = this.CurrentToken();
            Position pos   = token != null?this.GetPosition(token.StartPos) : null;

            string fileName = pos != null ? pos.FileName : null;
            bool   atEof    = token == null;
            string errorMessage;

            if (pos != null)
            {
                var startPos = pos;
                var endPos   = this.GetPosition(token.EndPos);
                var lines    = Utils.ExtractRelevantSource(GetSourceFile().Content.Split('\n'), startPos, endPos);
                errorMessage = String.Format("{0}\n{1}\n{2}", message, lines [0], lines [1]);
            }
            else
            {
                errorMessage = message;
            }
            var error = new ShovelException();

            error.Message = errorMessage;
            if (pos != null)
            {
                error.Line   = pos.Line;
                error.Column = pos.Column;
            }
            else
            {
                error.AtEof = atEof;
            }
            error.FileName = fileName;
            throw error;
        }
Exemplo n.º 2
0
        void RaiseErrorAt(string message, int?startPosition, int?endPosition)
        {
            Position pos = startPosition != null?this.GetPosition(startPosition.Value) : null;

            string fileName = pos != null ? pos.FileName : null;
            bool   atEof    = startPosition == null && endPosition == null;
            string errorMessage;

            if (pos != null)
            {
                var startPos = pos;
                var endPos   = this.GetPosition(endPosition.Value);
                var lines    = Utils.ExtractRelevantSource(GetSourceFile().Content.Split('\n'), startPos, endPos);
                errorMessage = String.Format("{0}\n{1}\n{2}", message, lines[0], lines[1]);
            }
            else
            {
                errorMessage = message;
            }
            var error = new ShovelException();

            error.ShovelMessage = errorMessage;
            if (pos != null)
            {
                error.Line   = pos.Line;
                error.Column = pos.Column;
            }
            else
            {
                error.AtEof = atEof;
            }
            error.FileName = fileName;
            throw error;
        }
Exemplo n.º 3
0
 public Either(ShovelException error)
 {
     this.Error = error;
 }