Beispiel #1
0
        void RaiseError(int characterStartPos, int characterEndPos, string message)
        {
            string errorFileName = null;
            int?   line          = null;
            int?   column        = null;

            if (this.sources != null && this.fileName != null)
            {
                var sourceFile = SourceFile.FindSource(this.sources, this.fileName);
                var content    = sourceFile.Content;
                errorFileName = fileName;
                var startPos = Position.CalculatePosition(sourceFile, characterStartPos);
                var endPos   = Position.CalculatePosition(sourceFile, characterEndPos);
                var lines    = Utils.ExtractRelevantSource(content.Split('\n'), startPos, endPos);
                message = String.Format("{0}\n{1}\n{2}", message, lines [0], lines [1]);
                line    = startPos.Line;
                column  = startPos.Column;
            }
            throw new ShovelException()
                  {
                      ShovelMessage = message,
                      FileName      = errorFileName,
                      Line          = line,
                      Column        = column,
                      AtEof         = line == null
                  };
        }
Beispiel #2
0
        void ExtendFrame(Types.Environment env, string name, ParseTree nameAst)
        {
            var topFrame           = env.Frame;
            var currentStartPos    = nameAst.StartPos;
            var previousDefinition = topFrame.EntryFor(name);

            if (previousDefinition != null)
            {
                var sourceFile = SourceFile.FindSource(this.sources, previousDefinition.FileName);
                var pos        = Position.CalculatePosition(sourceFile, previousDefinition.StartPos);
                var message    = String.Format(
                    "Variable '{0}' is already defined in this frame in file '{1}', at line {2}, column {3}.",
                    name, pos.FileName, pos.Line, pos.Column);
                this.RaiseError(currentStartPos, nameAst.EndPos, message);
            }
            else
            {
                var newVar = new EnvVar()
                {
                    Name     = name,
                    FileName = this.fileName,
                    Place    = topFrame.Vars.Count,
                    StartPos = currentStartPos
                };
                topFrame.Vars.Add(newVar);
            }
        }