示例#1
0
        private void _AutoIndentNeeded(object sender, AutoIndentEventArgs e)
        {
            Match isOtherwiseRegex = Regex.Match(e.LineText.Trim(), ",* otherwise");
            int   currentIndent    = e.LineText.TakeWhile(q => q == ' ').Count(); //shouldn't be too inefficient
            int   at = e.LineText.IndexOf('=');

            AmandaTagParser tagParser = new AmandaTagParser();

            tagParser.Parse(textBox.Text);

            /*
             *              All these todo's might not be neccessary, it's pretty good right now
             */
            //If the line contains a where, we want the next lines to be indented by a tab
            if (Regex.IsMatch(e.LineText, "where"))
            {
                e.ShiftNextLines = e.TabLength;
            }

            //if the line is a condition, we want to find the '=' and indent to there, that's how youre supposed to do conditions in amanda
            else if (Regex.IsMatch(e.LineText.Trim(), ",* if"))
            {
                e.ShiftNextLines = at - currentIndent;
            }

            //If line is empty | prev line is empty | contains otherwise (which indicates the end of an if/else statement)
            else if (e.LineText.Trim() == "" || e.PrevLineText.Trim().Count() == 0 || Regex.IsMatch(e.LineText.Trim(), ",* otherwise") == true)
            {
                //Get the tag based on our current line, if we are at line 3, and there is a big function going from line 1-5, it will return that.
                AmandaTag tag = tagParser.GetTag(e.iLine);
                if (tag != null)
                {
                    e.ShiftNextLines = tag.BeginLocation.X - at;
                }

                //No function found? No problem, resort to a tab
                else
                {
                    e.ShiftNextLines = -e.TabLength;
                }
            }
        }
示例#2
0
        //generates the tags (function names, variables, etc)
        public void Parse(string code)
        {
            if (code != LastCodeParsed)
            {
                int       counter = 0;
                AmandaTag tag     = null;
                LastCodeParsed = code;
                AmandaTags     = new List <AmandaTag>();

                foreach (string line in code.Split('\n'))
                {
                    string functionName = new string(line.TrimStart().TakeWhile(q => q != ' ').ToArray());
                    if (line.Trim().Count() == 0)
                    {
                        continue;
                    }
                    else if (tag != null && line.TrimStart()[0] == '=')
                    {
                        tag.EndLocation = new Point(0, counter);
                    }
                    else if (line.Contains('=') && line.TrimStart()[0] != '=' /*&& GetBracketMismatch(line) < 1*/)
                    {
                        if (tag != null)
                        {
                            AmandaTags.Add(tag);
                        }
                        List <string> functionArguments = line.TrimStart().Replace(functionName, "").TakeWhile(q => q != '=').ToString().Split(' ').ToList(); //This is getting awkward
                        //Unimplemented: Definition, Summary & endlocation
                        tag = new AmandaTag(functionName, functionArguments, "", "", new Point(line.IndexOf(functionName), counter), new Point(0, 0));
                    }
                    counter++;
                }
                if (tag != null)
                {
                    AmandaTags.Add(tag);
                }
            }
        }
示例#3
0
文件: Tags.cs 项目: remco138/amanda
        //generates the tags (function names, variables, etc)
        public void Parse(string code)
        {
            if (code != LastCodeParsed)
            {
                int counter = 0;
                AmandaTag tag = null;
                LastCodeParsed = code;
                AmandaTags = new List<AmandaTag>();

                foreach(string line in code.Split('\n'))
                {
                    string functionName = new string(line.TrimStart().TakeWhile(q => q != ' ').ToArray());
                    if (line.Trim().Count() == 0)
                    {
                        continue;
                    }
                    else if (tag != null && line.TrimStart()[0] == '=')
                    {
                        tag.EndLocation = new Point(0, counter);
                    }
                    else if(line.Contains('=') && line.TrimStart()[0] != '=' /*&& GetBracketMismatch(line) < 1*/)
                    {
                        if (tag != null)
                        {
                             AmandaTags.Add(tag);
                        }
                        List<string> functionArguments = line.TrimStart().Replace(functionName, "").TakeWhile(q => q != '=').ToString().Split(' ').ToList(); //This is getting awkward
                        //Unimplemented: Definition, Summary & endlocation
                        tag = new AmandaTag(functionName, functionArguments, "", "", new Point(line.IndexOf(functionName), counter), new Point(0, 0));
                    }
                    counter++;
                }
                if (tag != null)
                {
                    AmandaTags.Add(tag);
                }
            }
        }