示例#1
0
        private void DrawTerminalTokens()
        {
            EditorGUILayout.LabelField("Unfinished 5");
            //DrawTerminal(null, null);
            if (GUILayout.Button("New Terminal"))
            {
                //Create a new terminal data
                TerminalChunk chunk = new TerminalChunk();
                //[TODO] make this search for a non-taken name
                chunk.LHS_Token = "NEWTERMINAL";
                chunk.regex     = "";
                chunk.mode      = OrbLexer.LexMode.Regex;

                windowSettings.language.terminalTokens.Add(chunk);
            }
            //Draw UI for all tokens
            for (int i = 0; i < windowSettings.language.terminalTokens.Count; i++)
            {
                DrawTerminal(windowSettings.language, windowSettings.language.terminalTokens[i]);
            }
        }
示例#2
0
        static void DrawTerminal(LangFile file, TerminalChunk chunk)
        {
            EditorGUILayout.BeginHorizontal(EditorStyles.helpBox);
            {
                EditorGUILayout.BeginVertical();
                {
                    //Move Up Precedence
                    if (GUILayout.Button("Up"))
                    {
                        //Search for this terminal in the list

                        for (int i = 0; i < file.terminalTokens.Count; i++)
                        {
                            if (file.terminalTokens[i] == chunk)
                            {
                                //If it isnt the first one
                                if (i != 0)
                                {
                                    TerminalChunk temp;
                                    //Perform a swap with the one after it
                                    temp = file.terminalTokens[i];
                                    file.terminalTokens[i]     = file.terminalTokens[i - 1];
                                    file.terminalTokens[i - 1] = temp;
                                }
                                break;
                            }
                        }
                    }
                    //Move Down Precedence
                    if (GUILayout.Button("Down"))
                    {
                        //Search for this terminal in the list
                        for (int i = 0; i < file.terminalTokens.Count; i++)
                        {
                            if (file.terminalTokens[i] == chunk)
                            {
                                //If it isnt the last one
                                if (i != file.terminalTokens.Count - 1)
                                {
                                    //Perform a swap with the one after it
                                    TerminalChunk temp;
                                    temp = file.terminalTokens[i];
                                    file.terminalTokens[i]     = file.terminalTokens[i + 1];
                                    file.terminalTokens[i + 1] = temp;
                                }
                                break;
                            }
                        }
                    }
                }
                EditorGUILayout.EndVertical();
                //Name
                chunk.LHS_Token = EditorGUILayout.TextField("Identifier:", chunk.LHS_Token);
                //Mode
                //EditorGUILayout.TextField("Mode:", "Enum");
                chunk.mode = (OrbLexer.LexMode)EditorGUILayout.EnumPopup(chunk.mode);
                //Regex/string match
                chunk.regex = EditorGUILayout.TextField("Regex/String:", chunk.regex);

                string path = Application.dataPath + "/Assets/Ouroboros/LanguageFiles" + "/" + file.name + "/" + chunk.LHS_Token + ".cs";
                //Create the file if it doesnt exist, otherwise leave it alone.
                System.IO.File.AppendText(path).Close();
                //Edit Code
                DrawEditButton(path);
            }
            EditorGUILayout.EndHorizontal();
        }