Parse() public method

public Parse ( string code ) : void
code string
return void
示例#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");
            }
        }
示例#2
0
        public void UpdateAutocompleteIdentifiers()
        {
            //of toch wel? :D, word per keydown opnieuw geparsed, zou niet langzaam moeten zijn omdat string compare snel is/kan zijn

            Amanda amandaObj = Amanda.GetInstance();

            amandaTagParser.Parse(textBox.Text);

            ICollection <string> tags = new List <string>();

            amandaTagParser.AmandaTags.ForEach(q => tags.Add(q.Name));

            ICollection <string> items = tags.Concat(amandaObj.GetIdentifiers()).ToList();//amandaTagParser.Concat(Identifiers).ToList();

            autocomplete.Items.SetAutocompleteItems(items);
        }
示例#3
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;
                }
            }
        }
示例#4
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" );
            }
        }
示例#5
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;
                }
            }
        }