Ejemplo n.º 1
0
        /// <summary>Return the begin and end of the keyword</summary>
        public static (int BeginPos, int EndPos) GetKeywordPos(int pos, string line)
        {
            //Debug.WriteLine(string.Format("INFO: getKeyword; pos={0}; line=\"{1}\"", pos, new string(line)));
            if ((pos < 0) || (pos >= line.Length))
            {
                return(pos, pos);
            }
            // find the beginning of the keyword
            int beginPos = 0;

            for (int i1 = pos - 1; i1 >= 0; --i1)
            {
                char c = line[i1];
                if (AsmSourceTools.IsSeparatorChar(c) || Char.IsControl(c) || AsmSourceTools.IsRemarkChar(c))
                {
                    beginPos = i1 + 1;
                    break;
                }
            }
            // find the end of the keyword
            int endPos = line.Length;

            for (int i2 = pos; i2 < line.Length; ++i2)
            {
                char c = line[i2];
                if (AsmSourceTools.IsSeparatorChar(c) || Char.IsControl(c) || AsmSourceTools.IsRemarkChar(c))
                {
                    endPos = i2;
                    break;
                }
            }
            return(BeginPos : beginPos, EndPos : endPos);
        }
Ejemplo n.º 2
0
        private static (bool Valid, int BeginPos, int EndPos) GetLabelDefPos_Regular(string line)
        {
            int nChars = line.Length;
            int i      = 0;

            // find the start of the first keyword
            for (; i < nChars; ++i)
            {
                char c = line[i];
                if (AsmSourceTools.IsRemarkChar(c))
                {
                    return(Valid : false, BeginPos : 0, EndPos : 0);
                }
                else if (char.IsWhiteSpace(c))
                {
                    // do nothing
                }
                else
                {
                    break;
                }
            }
            if (i >= nChars)
            {
                return(Valid : false, BeginPos : 0, EndPos : 0);
            }
            int beginPos = i;

            // position i points to the start of the current keyword
            //AsmDudeToolsStatic.Output_INFO("getLabelEndPos: found first char of first keyword "+ line[i]+".");

            for (; i < nChars; ++i)
            {
                char c = line[i];
                if (c.Equals(':'))
                {
                    if (i == 0)
                    { // we found an empty label
                        return(Valid : false, BeginPos : 0, EndPos : 0);
                    }
                    else
                    {
                        return(Valid : true, BeginPos : beginPos, EndPos : i);
                    }
                }
                else if (AsmSourceTools.IsRemarkChar(c))
                {
                    return(Valid : false, BeginPos : 0, EndPos : 0);
                }
                else if (AsmSourceTools.IsSeparatorChar(c))
                {
                    // found another keyword: labels can only be the first keyword on a line
                    break;
                }
            }
            return(Valid : false, BeginPos : 0, EndPos : 0);
        }