示例#1
0
        public void Process(StringSection source, List <StringSection> output, IFileSystem files)
        {
            bool moreLines = !source.IsNullOrEmpty;

            while (moreLines)
            {
                int           iLineBreak = source.IndexOfAny(lineBreaks);
                StringSection line;

                if (iLineBreak == -1)
                {
                    // Last line
                    line      = source;
                    source    = StringSection.Empty;
                    moreLines = false;
                }
                else
                {
                    line = source.Substring(0, iLineBreak);
                    bool isCRLF = (source[iLineBreak] == '\r') && (source.Length > iLineBreak + 1) && (source[iLineBreak + 1] == '\n');
                    if (isCRLF)
                    {
                        source = source.Substring(iLineBreak + 2);
                    }
                    else
                    {
                        source = source.Substring(iLineBreak + 1);
                    }
                }

                if (IsIncludeLine(line))
                {
                    string includeFile = line.Substring(includeDirective.Length).Trim().ToString();
                    // Need to remove optional quotes
                    if (includeFile.Length >= 2 && includeFile[0] == '\"' && includeFile[includeFile.Length - 1] == '\"')
                    {
                        includeFile = includeFile.Substring(1, includeFile.Length - 2).Trim();
                    }
                    if (assembler.FileSystem.FileExists(includeFile))
                    {
                        ProcessInclude(output, files, includeFile);
                    }
                    else
                    {
                        assembler.AddError(new Error(ErrorCode.File_Error, string.Format(Error.Msg_FileNotFound_name, includeFile), output.Count));
                    }
                }
                else
                {
                    output.Add(line);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Parses code from a list of sub-strings. (Useful if the code
        /// is in the form of a single long string.)
        /// </summary>
        /// <param name="lines"></param>
        public void ParseCode(IList <StringSection> lines)
        {
            assembly = Assembler.Assembly;

            Error error;

            for (int i = 0; i < lines.Count; i++)
            {
                ParseLine(lines[i], i, out error);

                if (error.Code != ErrorCode.None)
                {
                    Assembler.AddError(error);
                }
            }
        }
示例#3
0
 protected void AddError(Error error)
 {
     Assembler.AddError(error);
 }