AmandaInterface.AmandaTagParser.Parse C# (CSharp) Метод

Parse() публичный Метод

public Parse ( string code ) : void
code string
Результат void
        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);
                }
            }
        }

Usage Example

Пример #1
0
        private void _TextChanged(object sender, TextChangedEventArgs e)
        {
            AmandaTagParser parser = new AmandaTagParser();

            parser.Parse(textBox.Text);

            // Set isEdited to true so the we can ask the user to save the file when he closes the program.
            //
            if (!IsEdited)
            {
                IsEdited = true;
            }

            e.ChangedRange.ClearStyle(KeywordStyle, CommentStyle, ConstantStyle, FunctionStyle);

            e.ChangedRange.SetStyle(KeywordStyle, @"\b(where|if|else|True|False|otherwise)\b");
            e.ChangedRange.SetStyle(CommentStyle, @"\|\|.*");                          //comments ||...
            e.ChangedRange.SetStyle(ConstantStyle, @"\b(\B-)?[0-9]+\b");               //numbers 123, -123, to be removed?
            e.ChangedRange.SetStyle(ConstantStyle, @"""[^""\\]*(?:\\.[^""\\]*)*""?");  //string "", source: stackoverflow
            e.ChangedRange.SetStyle(ConstantStyle, @"'[^'\\]*(?:\\.[^'\\]*)*'?");      //char ''

            foreach (string functionName in parser.AmandaTags.Select(q => q.Name))
            {
                e.ChangedRange.SetStyle(FunctionStyle, @"\b" + functionName + @"\b");
            }
        }
All Usage Examples Of AmandaInterface.AmandaTagParser::Parse