Example #1
0
 /// <summary>
 /// Forces an update of the current context
 /// </summary>
 public void UpdateContext()
 {
     curContext = DotContext.NodeID;
     curLine    = dotEditor.CaretLine();
     if (curLine == null)
     {
         return;
     }
     inQuotes = false;
     escaped  = false;
     inDict   = false;
     foreach (char c in curLine.Take(dotEditor.TextArea.Caret.Column - 1))
     {
         PushNewChar(c);
     }
 }
Example #2
0
        private void PushNewChar(char inChar)
        {
            if (inChar == '"' && !escaped)
            {
                inQuotes = !inQuotes;
            }
            else if (inChar == '\\' || escaped)
            {
                escaped = !escaped;
            }

            if (!inQuotes) //the context cannot change if we are in quotes
            {
                DotContext newContext = curContext;

                if (!inDict && inChar == '[')
                {
                    inDict = true;
                }

                if (curContext == DotContext.MultiLineComment)
                {
                    if (inChar == '*' && prevChar == '/')
                    {
                        newContext = DotContext.NodeID;
                    }
                }
                else if (curContext == DotContext.Comment)
                {
                    if (inChar == '\n')
                    {
                        newContext = DotContext.NodeID;
                    }
                }
                else if (inChar == '/' && prevChar == '*')
                {
                    newContext = DotContext.MultiLineComment;
                }
                else if (inChar == '#' || (inChar == '/' && prevChar == '/'))
                {
                    newContext = DotContext.Comment;
                }
                else if (inDict)
                {
                    if (inChar == ']')
                    {
                        newContext = DotContext.NodeID;
                        inDict     = false;
                    }
                    else if ("[,; \t\n".Contains(inChar))
                    {
                        switch (curContext)
                        {
                        case DotContext.EdgeAttribute:
                        case DotContext.NodeAttribute:
                        case DotContext.GraphAttribute:
                        case DotContext.ClusterAttribute:
                            break;

                        case DotContext.EdgeValue: newContext = DotContext.EdgeAttribute;
                            break;

                        case DotContext.NodeValue: newContext = DotContext.NodeAttribute;
                            break;

                        case DotContext.GraphValue: newContext = DotContext.GraphAttribute;
                            break;

                        case DotContext.ClusterValue: newContext = DotContext.ClusterAttribute;
                            break;

                        default:
                            string startLine = curLine.GetDotBase().Trim();
                            if (string.IsNullOrWhiteSpace(startLine))
                            {
                                newContext = DotContext.NodeID;
                            }
                            else if (startLine == "edge")
                            {
                                newContext = DotContext.EdgeAttribute;
                            }
                            else if (startLine == "node")
                            {
                                newContext = DotContext.NodeAttribute;
                            }
                            else if (startLine == "graph")
                            {
                                newContext = DotContext.GraphAttribute;
                            }
                            else if (startLine.Contains("--") || startLine.Contains("->"))
                            {
                                newContext = DotContext.EdgeAttribute;
                            }
                            else
                            {
                                newContext = DotContext.NodeAttribute;
                            }
                            break;
                        }
                    }
                    else if (inChar == '=')
                    {
                        switch (curContext)
                        {
                        case DotContext.EdgeAttribute: newContext = DotContext.EdgeValue;
                            break;

                        case DotContext.NodeAttribute: newContext = DotContext.NodeValue;
                            break;

                        case DotContext.GraphAttribute: newContext = DotContext.GraphValue;
                            break;

                        case DotContext.ClusterAttribute: newContext = DotContext.ClusterValue;
                            break;

                        default:
                            break;
                        }
                    }
                }
                else //Not in dict
                {
                    if (prevChar == '-' && (inChar == '-' || inChar == '>'))
                    {
                        newContext = DotContext.NodeID;
                    }
                }
                Console.WriteLine("q:{0}\te:{1}\tc:{2}\td:{3}\tnc:{4}", inQuotes, escaped, inChar, inDict, newContext);
                curContext = newContext;
            }
            prevChar = inChar;
            curLine  = curLine.Insert(dotEditor.TextArea.Caret.Column - 1, inChar.ToString());
        }