The SyntaxDefinition class describes a syntax.
It consists of a mainSpanDefinition , which is the start spanDefinition of the SyntaxDefinition
It also have a list of filetypes that is valid for this syntax
Exemple #1
0
    public TextEditor(string filename)
    {
        BackColor = Color.FromArgb(255, 34, 40, 42);

        //find the syntax definition
        p_SyntaxDefinition = null;
        string syntaxName = new FileInfo(filename).Extension.Replace(".", "").ToLower();
        for (int c = 0; c < p_SyntaxNames.Length; c++) {
            if (p_SyntaxNames[c] == syntaxName) {
                p_SyntaxDefinition = p_SyntaxDefinitions[c];
                break;
            }
        }

        //default to a unknown syntax definition if the file extension
        //isn't known.
        if (p_SyntaxDefinition == null) {
            for (int c = 0; c < p_SyntaxNames.Length; c++) {
                if (p_SyntaxNames[c] == "unknown") {
                    p_SyntaxDefinition = p_SyntaxDefinitions[c];
                    break;
                }
            }
        }

        //create the syntaxbox control
        p_Base = new SyntaxBoxControl() {
            Dock = DockStyle.Fill,
            BackColor = BackColor,
            BracketBackColor = Color.Transparent,
            BracketForeColor = Color.White,
            BracketBorderColor = Color.FromArgb(255, 60, 70, 70),

            ShowLineNumbers = false,
            ShowGutterMargin = false,

            SplitView = false,

            FontName = "Consolas",
            FontSize = 10
        };
        p_Base.Document = new SyntaxDocument();
        p_Base.Document.Parser.Init(p_SyntaxDefinition);
        p_Base.Document.Text = File.ReadAllText(filename);

        p_Base.Document.Change += delegate(object sender, EventArgs e) {
            if (Modified == null) { return; }
            Modified(this, e);
        };

        //create the right click menu
        ContextMenuStrip rightClickMenu = new ContextMenuStrip();
        rightClickMenu.Opening += delegate(object sender, System.ComponentModel.CancelEventArgs e) {
            presentRightClickMenu(rightClickMenu);
        };
        ContextMenuStrip = rightClickMenu;

        //add the control
        Controls.Add(p_Base);
    }
Exemple #2
0
 public void MergeByMainBlock(SyntaxDefinition Target)
 {
     SpanDefinition[] spanDefinitions = SpanDefinitions;
     foreach (SpanDefinition bt in spanDefinitions)
     {
         bt.childSpanDefinitions.Insert(0, Target.mainSpanDefinition);
     }
 }
Exemple #3
0
        //create an EditForm and attatch our opened document and tell the parser to use the given syntax.
        public EditForm(Document Document, SyntaxDefinition SyntaxDefinition)
        {
            InitializeComponent();

            Doc = Document;
            sBox.Document = sDoc;
            sBox.Document.Parser.Init(SyntaxDefinition);
            sBox.Document.Text = Document.Text;
            Text = Doc.Title;
        }
Exemple #4
0
 public void MergeByChildBlocks(SyntaxDefinition Target)
 {
     SpanDefinition[] spanDefinitions = SpanDefinitions;
     foreach (SpanDefinition bt in spanDefinitions)
     {
         for (int i = Target.mainSpanDefinition.childSpanDefinitions.Count - 1; i >= 0; i--)
         {
             SpanDefinition child = Target.mainSpanDefinition.childSpanDefinitions[i];
             bt.childSpanDefinitions.Insert(0, child);
         }
     }
 }
        /// <summary>
        ///
        /// </summary>
        public SyntaxDefinitionList()
        {
            languages = new List <SyntaxDefinition>();

            string[] files = Directory.GetFiles(".", "*.syn");
            foreach (string file in files)
            {
                var loader = new SyntaxDefinitionLoader();
                SyntaxDefinition syntax = loader.Load(file);
                languages.Add(syntax);
            }
        }
        /// <summary>
        /// Load a specific syntax file
        /// </summary>
        /// <param name="File">File name</param>
        /// <returns>SyntaxDefinition object</returns>
        public SyntaxDefinition Load(string File)
        {
            styleLookup = new Hashtable();
            spanDefinitionLookup = new Hashtable();
            syntaxDefinition = new SyntaxDefinition();

            var xmlDocument = new XmlDocument();
            xmlDocument.Load(File);
            ReadLanguageDefinition(xmlDocument);

            return syntaxDefinition;
        }
        /// <summary>
        /// Load a specific syntax file
        /// </summary>
        /// <param name="File">File name</param>
        /// <returns>SyntaxDefinition object</returns>
        public SyntaxDefinition Load(string File)
        {
            styleLookup          = new Hashtable();
            spanDefinitionLookup = new Hashtable();
            syntaxDefinition     = new SyntaxDefinition();

            var xmlDocument = new XmlDocument();

            xmlDocument.Load(File);
            ReadLanguageDefinition(xmlDocument);

            return(syntaxDefinition);
        }
Exemple #8
0
		public Main()
		{
			InitializeComponent();
			
			SyntaxDefinitionLoader sl = new SyntaxDefinitionLoader();
			syntaxDefinition = sl.LoadXML(DEVotion.Properties.Resources.LUA.ToString());

			LoadSettings();

			tabDocs.OnClose += CloseTab;
			tabDocs.OnAfterClose += AfterCloseTab;
			UpdateButtons();
		}
        /// <summary>
        ///
        /// </summary>
        public SyntaxDefinitionList()
        {
            languages = new List <SyntaxDefinition>();

            var assy    = Assembly.GetExecutingAssembly();
            var assyDir = Path.GetDirectoryName(assy.Location);

            string[] files = Directory.GetFiles(assyDir, "*.syn");
            foreach (string file in files)
            {
                var loader = new SyntaxDefinitionLoader();
                SyntaxDefinition syntax = loader.Load(file);
                languages.Add(syntax);
            }
        }
Exemple #10
0
        //create an EditForm and attach our opened document and tell the parser to use the given syntax.
        public EditForm(string title, string path, string documentText, SyntaxDefinition SyntaxDefinition, FileType ext)
        {
            Load += EditForm_Load;
            Closing += EditForm_Closing;
            InitializeComponent();

            this.Doc = new Document(title, path, documentText);
            sBox.Document = sDoc;
            sBox.Document.Parser.Init(SyntaxDefinition);
            this.Syntax = SyntaxDefinition;
            sBox.Document.Text = Doc.DocumentText;
            this.Text = Doc.Title;
            this.TabText = Doc.Title;
            this.Ext = ext;
            this.statusBar1.Visible = false;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="File"></param>
        /// <param name="Separators"></param>
        /// <returns></returns>
        public SyntaxDefinition Load(string File, string Separators)
        {
            styleLookup = new Hashtable();
            spanDefinitionLookup = new Hashtable();
            syntaxDefinition = new SyntaxDefinition {Separators = Separators};

            var xmlDocument = new XmlDocument();
            xmlDocument.Load(File);
            ReadLanguageDefinition(xmlDocument);

            if (syntaxDefinition.mainSpanDefinition == null) {
                throw new Exception("no main block found in syntax");
            }

            return syntaxDefinition;
        }
        /// <summary>
        /// Load a specific syntax from an xml string
        /// </summary>
        /// <param name="XML"></param>
        /// <returns></returns>
        public SyntaxDefinition LoadXML(string XML)
        {
            styleLookup = new Hashtable();
            spanDefinitionLookup = new Hashtable();
            syntaxDefinition = new SyntaxDefinition();

            var xmlDocument = new XmlDocument();
            xmlDocument.LoadXml(XML);
            ReadLanguageDefinition(xmlDocument);

            if (syntaxDefinition.mainSpanDefinition == null)
            {
                throw new Exception("no main block found in syntax");
            }


            return syntaxDefinition;
        }
        /// <summary>
        /// Load a specific syntax from an xml string
        /// </summary>
        /// <param name="XML"></param>
        /// <returns></returns>
        public SyntaxDefinition LoadXML(string XML)
        {
            styleLookup          = new Hashtable();
            spanDefinitionLookup = new Hashtable();
            syntaxDefinition     = new SyntaxDefinition();

            var xmlDocument = new XmlDocument();

            xmlDocument.LoadXml(XML);
            ReadLanguageDefinition(xmlDocument);

            if (syntaxDefinition.mainSpanDefinition == null)
            {
                throw new Exception("no main block found in syntax");
            }


            return(syntaxDefinition);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="File"></param>
        /// <param name="Separators"></param>
        /// <returns></returns>
        public SyntaxDefinition Load(string File, string Separators)
        {
            styleLookup          = new Hashtable();
            spanDefinitionLookup = new Hashtable();
            syntaxDefinition     = new SyntaxDefinition {
                Separators = Separators
            };

            var xmlDocument = new XmlDocument();

            xmlDocument.Load(File);
            ReadLanguageDefinition(xmlDocument);

            if (syntaxDefinition.mainSpanDefinition == null)
            {
                throw new Exception("no main block found in syntax");
            }

            return(syntaxDefinition);
        }
Exemple #15
0
 private void Init()
 {
     var l = new SyntaxDefinition();
     l.mainSpanDefinition = new SpanDefinition(l)
                   {
                       MultiLine = true
                   };
     Parser.Init(l);
 }
Exemple #16
0
 /// <summary>
 /// Default spanDefinition constructor
 /// </summary>
 public SpanDefinition(SyntaxDefinition parent) : this()
 {
     Parent = parent;
     Parent.ChangeVersion();
 }
 public void MergeByChildBlocks(SyntaxDefinition Target)
 {
     SpanDefinition[] spanDefinitions = SpanDefinitions;
     foreach (SpanDefinition bt in spanDefinitions)
     {
         for (int i = Target.mainSpanDefinition.childSpanDefinitions.Count - 1; i >= 0; i--)
         {
             SpanDefinition child = Target.mainSpanDefinition.childSpanDefinitions[i];
             bt.childSpanDefinitions.Insert(0, child);
         }
     }
 }
 public void MergeByMainBlock(SyntaxDefinition Target)
 {
     SpanDefinition[] spanDefinitions = SpanDefinitions;
     foreach (SpanDefinition bt in spanDefinitions)
     {
         bt.childSpanDefinitions.Insert(0, Target.mainSpanDefinition);
     }
 }