Ejemplo n.º 1
0
        /// <summary>
        /// Return the begin and end of the keyword
        /// </summary>
        public static Tuple <int, int> 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(new Tuple <int, int>(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(new Tuple <int, int>(beginPos, endPos));
        }
Ejemplo n.º 2
0
        private static Tuple <bool, int, int> 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(new Tuple <bool, int, int>(false, 0, 0));
                }
                else if (char.IsWhiteSpace(c))
                {
                    // do nothing
                }
                else
                {
                    break;
                }
            }
            if (i >= nChars)
            {
                return(new Tuple <bool, int, int>(false, 0, 0));
            }
            int beginPos = i;

            // position i points to the start of the current keyword
            //AsmDudeToolsStatic.Output("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(new Tuple <bool, int, int>(false, 0, 0));
                    }
                    else
                    {
                        return(new Tuple <bool, int, int>(true, beginPos, i));
                    }
                }
                else if (AsmSourceTools.isRemarkChar(c))
                {
                    return(new Tuple <bool, int, int>(false, 0, 0));
                }
                else if (AsmSourceTools.isSeparatorChar(c))
                {
                    // found another keyword: labels can only be the first keyword on a line
                    break;
                }
            }
            return(new Tuple <bool, int, int>(false, 0, 0));
        }