]> O.S.I.I.S - jp/crowedit.git/commitdiff
Syntax analysing improvment wip start
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sat, 8 Mar 2025 11:51:26 +0000 (12:51 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sat, 8 Mar 2025 11:51:26 +0000 (12:51 +0100)
16 files changed:
CrowEditBase/src/Compiler/SourceDocument.cs
CrowEditBase/src/Compiler/SyntaxAnalyser.cs
CrowEditBase/src/Compiler/SyntaxNode.cs
CrowEditBase/src/Compiler/Tokenizer.cs
CrowEditBase/src/SourceEditor.cs
plugins/CECrowPlugin/src/Parsing/IML/ImlSyntaxAnalyser.cs
plugins/CECrowPlugin/src/Parsing/Styling/StyleSyntaxAnalyser.cs [new file with mode: 0644]
plugins/CECrowPlugin/src/Parsing/Styling/SyntaxAnalyser.cs [deleted file]
plugins/CECrowPlugin/src/Parsing/Styling/SyntaxNodes.cs
plugins/CEEbnfPlugin/src/Parsing/EbnfSyntaxAnalyser.cs
plugins/CERoslynPlugin/src/CSDocument.cs
plugins/CERoslynPlugin/src/CSSyntaxAnalyser.cs
plugins/CERoslynPlugin/src/CSTokenizer.cs
plugins/CERoslynPlugin/src/ProjectTree/MSBuildProjectItemNodes.cs
plugins/CEXmlPlugin/src/Parsing/XmlSyntaxAnalyser.cs
src/CrowEdit.cs

index b7126bec3472fbd6db3fc7736169dac5b0a4e8e3..d702db177107a8439cc9c417d300e3302091d9d8 100644 (file)
@@ -9,6 +9,7 @@ using System.Diagnostics;
 using System.Collections;
 using System.Collections.Generic;
 using Drawing2D;
+using System.Security;
 
 namespace CrowEditBase
 {
@@ -26,7 +27,10 @@ namespace CrowEditBase
 
                        CMDRefreshSyntaxTree = new ActionCommand ("Reparse", parse, "#icons.refresh.svg", true);
         }
-        public SyntaxRootNode Root => root;
+        public SyntaxRootNode Root {
+                       get => root;
+               }
+
                public bool IsParsed => root != null && Tokens.Length > 0;
                public ReadOnlySpan<Token> Tokens => root.Tokens;
                public IEnumerable<SyntaxNode> SyntaxRootChildNodes => root?.children;
@@ -82,13 +86,9 @@ namespace CrowEditBase
                protected override void apply(TextChange change)
                {
                        SyntaxNode editedNode = root?.FindNodeIncludingSpan (new TextSpan (change.Start, change.End));
-
                        base.apply(change);
-
-                       SyntaxAnalyser syntaxAnalyser = CreateSyntaxAnalyser ();
-                       root = syntaxAnalyser?.Process ();
-
-                       NotifyValueChanged("Exceptions", syntaxAnalyser?.Exceptions);
+                       parse ();
+                       
 
                        //SyntaxNode changedNode = root.FindNodeIncludingSpan (TextSpan.FromStartAndLength (change.Start, change.ChangedText.Length));                  
                        
@@ -140,9 +140,9 @@ namespace CrowEditBase
                protected abstract SyntaxAnalyser CreateSyntaxAnalyser ();
                public abstract IList GetSuggestions (int absoluteTextPos, int currentTokenIndex, SyntaxNode currentNode, CharLocation loc);
 
-               void parse () {
+               protected virtual async void parse () {
                        SyntaxAnalyser syntaxAnalyser = CreateSyntaxAnalyser ();
-                       root = syntaxAnalyser?.Process ();
+                       root = await syntaxAnalyser.Process ();
 
                        NotifyValueChanged("Exceptions", syntaxAnalyser?.Exceptions);
                        NotifyValueChanged ("SyntaxRootChildNodes", (object)null);
index 98a4117a28369c7056c991ac362db7561faa297c..409787413da841b6d6ee799720693ba6360c48bc 100644 (file)
@@ -4,25 +4,25 @@
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Threading.Tasks;
 using Crow.Text;
 
 namespace CrowEditBase
 {
        public abstract class SyntaxAnalyser {
-               //protected abstract void Parse(SyntaxNode node);
-               protected ReadOnlyMemory<char> source;
+               protected SourceDocument document;
                protected LineCollection lines;
                protected SyntaxRootNode Root;
                public IEnumerable<SyntaxException> Exceptions => Root?.GetAllExceptions();
                public SyntaxAnalyser (SourceDocument document) {
-                       this.source = document.ImmutableBufferCopy;
+                       this.document = document;
                        this.lines = document.Lines;
                }
-               public abstract SyntaxRootNode Process ();
+               public abstract Task<SyntaxRootNode> Process ();
                
                #region Token handling
                protected Token curTok => tokIdx < 0 ? default : tokens[tokIdx];
-               protected ReadOnlySpan<char> curTokString => curTok.AsString(source.Span);
+               
                protected ReadOnlySpan<Token> tokens => Root.Tokens;
                protected bool EOF => tokIdx == tokens.Length;
                protected bool tryRead (out Token tok) {
index 00dd6c7372c6d7152a87a4aff7368f36fa7751bb..e88631321e77a5718ab9a2e627c62507da1e3e37 100644 (file)
@@ -9,7 +9,12 @@ using Crow;
 
 namespace CrowEditBase
 {
+       /*public class SingleTokenSyntax {
+               Token token;
+
+       }*/
        public class SyntaxNode : CrowEditComponent {
+               #region CTOR
                internal SyntaxNode () {}
                public SyntaxNode (int startLine, int tokenBase, int? lastTokenIdx = null) {
                        StartLine = startLine;
@@ -17,12 +22,17 @@ namespace CrowEditBase
                        if (lastTokenIdx.HasValue)
                                lastTokenOfset = lastTokenIdx - tokenBase;
                }
-               
-               bool _isExpanded;
+               #endregion
+
+               internal List<SyntaxNode> children = new List<SyntaxNode> ();
+
+
                internal int? lastTokenOfset;
-               internal bool isFolded;
                internal int lineCount;
 
+               #region  Folding and ?expand?
+               bool _isExpanded;
+               internal bool isFolded;
 
                public bool isExpanded {
                        get => _isExpanded;
@@ -33,26 +43,60 @@ namespace CrowEditBase
                                NotifyValueChanged (_isExpanded);
                        }
                }
+               public virtual bool IsFoldable => IsComplete && !(Parent != Root && Parent.StartLine == StartLine) && lineCount > 1;
                public void ExpandToTheTop () {
                        isExpanded = true;
                        Parent?.ExpandToTheTop ();
                }
-               public SyntaxNode Parent { get; private set; }
-               public int StartLine { get; private set; }
-               public virtual int LineCount => lineCount;
-               public virtual bool IsComplete => lastTokenOfset.HasValue;
-               public virtual bool IsFoldable => IsComplete && !(Parent != Root && Parent.StartLine == StartLine) && lineCount > 1;
-               public virtual SyntaxRootNode Root => Parent.Root;
                public virtual void UnfoldToTheTop () {
                        isFolded = false;
                        Parent.UnfoldToTheTop ();
                }
-               protected Token getTokenByIndex (int idx) => Root.GetTokenByIndex(idx);
-               internal List<SyntaxNode> children = new List<SyntaxNode> ();
+               public IEnumerable<SyntaxNode> VisibleFoldableNodes {
+                       get {
+                               if (IsFoldable) {
+                                       yield return this;
+                               }
+                               if (!isFolded) {
+                                       foreach (SyntaxNode n in Children) {
+                                               foreach (SyntaxNode folds in n.VisibleFoldableNodes)
+                                                       yield return folds;
+                                       }
+                               }
+                       }
+               }
+               public virtual int FoldedLineCount {
+                       get {
+                               if (isFolded)
+                                       return lineCount;
+                               int tmp = 0;
+                               if (HasChilds) {
+                                       foreach (SyntaxNode n in children.Where (c => c.IsFoldable))
+                                               tmp += n.FoldedLineCount;
+                               }
+                               return tmp;
+                       }
+               }
+               #endregion
+
+
+               
+               public IEnumerable<SyntaxNode> Children => children;
+               public bool HasChilds => children.Count > 0;
+               public SyntaxNode Parent { get; private set; }
+               public virtual bool IsComplete => lastTokenOfset.HasValue;
+
+               public virtual SyntaxRootNode Root => Parent.Root;
+
+
+               public int StartLine { get; private set; }
+               public virtual int LineCount => lineCount;
+
+
                List<SyntaxException> exceptions = new List<SyntaxException>();
+               public IEnumerable<SyntaxException> Exceptions => exceptions;
                public void AddException(SyntaxException e) => exceptions.Add(e);
                public void ResetExceptions(SyntaxException e) => exceptions.Clear();
-               public IEnumerable<SyntaxException> Exceptions => exceptions;
                public IEnumerable<SyntaxException> GetAllExceptions() {
                                foreach (SyntaxException e in exceptions)
                                        yield return e;
@@ -62,9 +106,11 @@ namespace CrowEditBase
                                }
                }
 
-               public IEnumerable<SyntaxNode> Children => children;
+
+               protected Token getTokenByIndex (int idx) => Root.GetTokenByIndex(idx);
+
+               
                //public int IndexOf (SyntaxNode node) => children.IndexOf (node);
-               public bool HasChilds => children.Count > 0;
                public SyntaxNode NextSibling {
                        get {
                                if (Parent != null) {
@@ -87,31 +133,6 @@ namespace CrowEditBase
                }
                public virtual SyntaxNode NextSiblingOrParentsNextSibling
                        => NextSibling ?? Parent.NextSiblingOrParentsNextSibling;
-               public IEnumerable<SyntaxNode> VisibleFoldableNodes {
-                       get {
-                               if (IsFoldable) {
-                                       yield return this;
-                               }
-                               if (!isFolded) {
-                                       foreach (SyntaxNode n in Children) {
-                                               foreach (SyntaxNode folds in n.VisibleFoldableNodes)
-                                                       yield return folds;
-                                       }
-                               }
-                       }
-               }
-               public virtual int FoldedLineCount {
-                       get {
-                               if (isFolded)
-                                       return lineCount;
-                               int tmp = 0;
-                               if (HasChilds) {
-                                       foreach (SyntaxNode n in children.Where (c => c.IsFoldable))
-                                               tmp += n.FoldedLineCount;
-                               }
-                               return tmp;
-                       }
-               }
 
                public virtual int TokenIndexBase { get; private set; }
                public virtual int TokenCount => lastTokenOfset.HasValue ? lastTokenOfset.Value + 1 : 0;
@@ -130,6 +151,8 @@ namespace CrowEditBase
                                return new TextSpan (startTok.Start, endTok.End);
                        }
                }
+               public int SpanStart;
+
                public SyntaxNode AddChild (SyntaxNode child) {
                        children.Add (child);
                        child.Parent = this;
index ee3f2d6383772299920d4cb9092292f33c2eb7b3..b9788a8bee9c8b507634ae2fd46624d2d6ce373c 100644 (file)
@@ -18,7 +18,7 @@ namespace CrowEditBase
                protected int startOfTok;
 
                public Tokenizer  () {}
-               public abstract Token[] Tokenize (ReadOnlySpan<char> source);
+               public abstract Token[] Tokenize (ReadOnlySpan<char> source = default);
                /// <summary>
                /// First method to call in tokenizers to init parsing variables
                /// </summary>
index 27b4d16cb459ff8646e193c409c8c59bb96f4fa4..ce40fb62e262c3056a9fc4f03cfd51db8aa72760 100644 (file)
@@ -413,6 +413,8 @@ namespace CrowEditBase
                        doc.EnterReadLock();
                        try {
                                int foldedLines = 0;
+                               if (!doc.IsParsed)
+                                       return 0;
                                IEnumerator<SyntaxNode> foldsEnum = doc.Root.VisibleFoldableNodes.GetEnumerator();
                                bool notEndOfFolds = foldsEnum.MoveNext();
                                while (notEndOfFolds && foldsEnum.Current.StartLine < absoluteLine) {
@@ -438,6 +440,8 @@ namespace CrowEditBase
                        doc.EnterReadLock();
                        try {
                                int foldedLines = 0;
+                               if (!doc.IsParsed)
+                                       return 0;
                                IEnumerator<SyntaxNode> nodeEnum = doc.Root.VisibleFoldableNodes.GetEnumerator ();
                                if (!nodeEnum.MoveNext())
                                        return 0;
index e1b9047ac638e26cb6de68a9a8e196974bf83102..d8d9816cfd5e6bd1fa83dd8de3e612620d9c838f 100644 (file)
@@ -6,6 +6,7 @@ using System.Collections.Generic;
 using System.Linq;
 using CrowEditBase;
 using CrowEdit.Xml;
+using System.Threading.Tasks;
 
 namespace CECrowPlugin
 {
@@ -13,9 +14,9 @@ namespace CECrowPlugin
                public ImlSyntaxAnalyser (ImlDocument document) : base (document) {}
 
 
-               public override SyntaxRootNode Process () {
+               public override async Task<SyntaxRootNode> Process () {
 
-                       return base.Process();
+                       return await base.Process();
 
 /*
                        ImlDocument xmlDoc = source as ImlDocument;
diff --git a/plugins/CECrowPlugin/src/Parsing/Styling/StyleSyntaxAnalyser.cs b/plugins/CECrowPlugin/src/Parsing/Styling/StyleSyntaxAnalyser.cs
new file mode 100644 (file)
index 0000000..e7a670e
--- /dev/null
@@ -0,0 +1,72 @@
+// Copyright (c) 2021-2021  Bruyère Jean-Philippe <jp_bruyere@hotmail.com>
+//
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using CrowEditBase;
+
+namespace CECrowPlugin.Style
+{
+       public static class Extensions {
+               public static StyleTokenType GetTokenType (this Token tok) {
+                       return (StyleTokenType)tok.Type;
+               }
+               public static void SetTokenType (this Token tok, StyleTokenType type) {
+                       tok.Type = (TokenType)type;
+               }
+       }
+       public class StyleSyntaxAnalyser : SyntaxAnalyser {
+               public StyleSyntaxAnalyser (StyleDocument document) : base (document) {}
+
+               public override async Task<SyntaxRootNode> Process () {
+                       Tokenizer tokenizer = new StyleTokenizer();
+                       ReadOnlyMemory<char> source = document.ImmutableBufferCopy;
+                       Token[] tokens = tokenizer.Tokenize(source.Span);
+                       currentNode = Root = new StyleRootSyntax (source, tokens);
+
+                       currentLine = 0;
+                       tokIdx = 0;
+
+                       while (tokIdx < tokens.Length) {
+                               if (!skipTrivia(true))
+                                       break;
+                               Token curTok = tokens[tokIdx];
+                               if (currentNode is StyleRootSyntax srs) {
+                                       if (tokens[tokIdx].GetTokenType() != StyleTokenType.Name) {
+                                               addException ("Unexpected Token");
+                                       } else {
+                                               StyleIdentifierSyntax sis = new StyleIdentifierSyntax(currentLine, tokIdx);
+                                               if (!skipTrivia(true)) {
+                                                       addException ("Unexpected end of file");
+                                                       break;
+                                               }
+                                               if (tokens[tokIdx].GetTokenType() == StyleTokenType.EqualSign) {
+                                                       ConstantDefinitionSyntax cds = new ConstantDefinitionSyntax(sis);
+                                                       cds.equal = tokIdx;
+                                                       if (!skipTrivia(true)) {
+                                                               addException ("Unexpected end of file");
+                                                               break;
+                                                       }
+
+
+                                               }
+                                               
+                                       }
+                               }
+                       
+                               tokIdx++;
+                       }
+                       while (currentNode.Parent != null) {
+                               if (!currentNode.LastTokenIndex.HasValue)
+                                       finishCurrentNode (-1);
+                               else
+                                       currentNode = currentNode.Parent;
+                       }
+                       setCurrentNodeEndLine (currentLine);
+
+                       return Root;
+               }
+       }
+}
\ No newline at end of file
diff --git a/plugins/CECrowPlugin/src/Parsing/Styling/SyntaxAnalyser.cs b/plugins/CECrowPlugin/src/Parsing/Styling/SyntaxAnalyser.cs
deleted file mode 100644 (file)
index ee7f780..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-// Copyright (c) 2021-2021  Bruyère Jean-Philippe <jp_bruyere@hotmail.com>
-//
-// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using CrowEditBase;
-
-namespace CECrowPlugin.Style
-{
-       public static class Extensions {
-               public static StyleTokenType GetTokenType (this Token tok) {
-                       return (StyleTokenType)tok.Type;
-               }
-               public static void SetTokenType (this Token tok, StyleTokenType type) {
-                       tok.Type = (TokenType)type;
-               }
-       }
-       public class StyleSyntaxAnalyser : SyntaxAnalyser {
-               public StyleSyntaxAnalyser (StyleDocument document) : base (document) {}
-
-               public override SyntaxRootNode Process () {
-                       Tokenizer tokenizer = new StyleTokenizer();
-                       Token[] tokens = tokenizer.Tokenize(source.Span);
-
-                       currentNode = Root = new StyleRootSyntax (source, tokens);
-
-                       currentLine = 0;
-                       tokIdx = 0;
-
-                       int firstNameIdx = -1;
-
-                       while (tokIdx < tokens.Length) {
-                               Token curTok = tokens[tokIdx];
-                               if (curTok.Type == TokenType.LineBreak)
-                                       currentLine++;
-                               else if (!curTok.Type.HasFlag (TokenType.Trivia)) {
-                                       /*if (currentNode is StyleRootSyntax root) {
-                                               if (firstNameIdx < 0) {
-                                                       if (curTok.GetTokenType()  == StyleTokenType.Name) {
-                                                               firstNameIdx = tokIdx;
-                                                       } else {
-                                                               Exceptions.Add (new SyntaxException  ("Unexpected Token", curTok));
-                                                       }
-
-                                               }
-
-                                       }*/
-                               }
-                               tokIdx++;
-                       }
-                       while (currentNode.Parent != null) {
-                               if (!currentNode.LastTokenIndex.HasValue)
-                                       finishCurrentNode (-1);
-                               else
-                                       currentNode = currentNode.Parent;
-                       }
-                       setCurrentNodeEndLine (currentLine);
-
-                       return Root;
-               }
-       }
-}
\ No newline at end of file
index 0619d710672d69355fbfb490954b81f04dc69855..a615950b7defe96a42d7a429de204f639bb929e2 100644 (file)
@@ -14,12 +14,29 @@ namespace CECrowPlugin.Style
                public StyleRootSyntax (ReadOnlyMemory<char> source, Token[] tokens) : base (source, tokens) { }
        }
        public class ConstantDefinitionSyntax : SyntaxNode {
-               internal int? name, equal, valueOpen, valueClose;
-               public override bool IsComplete => base.IsComplete & name.HasValue & equal.HasValue &
+               internal int? equal;
+               public readonly StyleIdentifierSyntax Identifier;
+               public readonly ImlValueSyntax Value;
+               public override bool IsComplete => base.IsComplete & Identifier != null & equal.HasValue;
+               public ConstantDefinitionSyntax (StyleIdentifierSyntax id)
+                       : base (id.StartLine, id.TokenIndexBase) {
+                       Identifier = id;
+               }
+       }
+       public class StyleIdentifierSyntax : SyntaxNode {
+               public StyleIdentifierSyntax (int startLine, int tokenBase)
+                       : base (startLine, tokenBase, tokenBase) {
+                       EndLine = startLine;
+               }
+       }
+       public class ImlValueSyntax : SyntaxNode {
+               internal int? valueOpen, value, valueClose;
+               public override bool IsComplete => base.IsComplete & value.HasValue &
                        valueOpen.HasValue & valueClose.HasValue;
-               public ConstantDefinitionSyntax (int startLine, int tokenBase)
+               public ImlValueSyntax (int startLine, int tokenBase)
                        : base (startLine, tokenBase) {
                }
+
        }
        public class AttributeSyntax : SyntaxNode {
                public Token? NameToken { get; internal set; }
index d733ab3b3cd59937c6c315004b05a4b5c61c8e10..bfa4a9b4cfb13645d71667bf5a3a9885ec232d16 100644 (file)
@@ -4,6 +4,7 @@
 
 using System;
 using System.Collections.Generic;
+using System.Threading.Tasks;
 using CrowEditBase;
 
 namespace CrowEdit.Ebnf
@@ -21,12 +22,13 @@ namespace CrowEdit.Ebnf
                //NCName | StringLiteral | CharCode | CharClass | '(' Choice ')'
                // StringLiteral ::= '"' [^"]* '"' | "'" [^']* "'"      
                
-        public override SyntaxRootNode Process()
+        public override async Task<SyntaxRootNode> Process()
         {
                        Tokenizer tokenizer = new EbnfTokenizer();
+                       ReadOnlyMemory<char> source = document.ImmutableBufferCopy;
                        Token[] tokens = tokenizer.Tokenize(source.Span);
-
                        currentNode = Root = new EbnfRootSyntax (source, tokens);
+
                        currentLine = 0;
                        tokIdx = 0;
                        
index e4a3aac26ee6d86c67a1befc33f5600232a87992..adabef8b6404e1d709956ee0e615b6e9e42c7908 100644 (file)
@@ -33,11 +33,10 @@ namespace CERoslynPlugin
                        App.GetService<RoslynService> ()?.Start ();
                }
 
-               CSharpSyntaxTree tree;
+               internal CSharpSyntaxTree tree;
                public CSDocument (string fullPath, string editorPath)  : base (fullPath, editorPath) {
 
                        tree = (CSharpSyntaxTree)CSharpSyntaxTree.ParseText (source.ToString(), CSharpParseOptions.Default);
-                       var root = tree.GetRoot();
                }
 
                #region SourceDocument abstract class implementation
@@ -93,7 +92,20 @@ namespace CERoslynPlugin
                                return Colors.DarkSlateBlue;
                        return Colors.Red;
 
-               }               
+               }
+
+        protected override void apply(TextChange change)
+        {
+                       buffer.Update(change);
+                       NotifyValueChanged ("IsDirty", IsDirty);
+                       CMDSave.CanExecute = IsDirty;
 
-       }
+                       parse();
+        }
+        protected override void parse()
+        {
+                       tree = (CSharpSyntaxTree)CSharpSyntaxTree.ParseText (source.ToString(), CSharpParseOptions.Default);
+            base.parse();
+        }
+    }
 }
\ No newline at end of file
index 6f17c913de3bd816021861c0683d48da02906698..a2e1fd553e21531c9afbacd04d41977a509083bb 100644 (file)
@@ -4,6 +4,7 @@
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Threading.Tasks;
 using CrowEditBase;
 using Microsoft.CodeAnalysis;
 using Microsoft.CodeAnalysis.CSharp.Syntax;
@@ -26,22 +27,20 @@ namespace CERoslynPlugin
         {
             throw new NotImplementedException();
         }*/
+               CSDocument csdoc;
+               public CSSyntaxAnalyser (CSDocument document) : base (document) {
+                       csdoc = document;
+               }
 
-               public CSSyntaxAnalyser (CSDocument document) : base (document) {}
-
-               public override SyntaxRootNode Process () {
-                       CSTokenizer tokenizer = new CSTokenizer();
-                       Token[] tokens = tokenizer.Tokenize(source.Span);
-
-
-                       
+               public override async Task<SyntaxRootNode> Process () {
+                       CSTokenizer tokenizer = new CSTokenizer(csdoc.tree);
+                       ReadOnlyMemory<char> source = document.ImmutableBufferCopy;
+                       Token[] tokens = tokenizer.Tokenize();
                        CsharpSyntaxWalkerBridge bridge = new CsharpSyntaxWalkerBridge(new CSRootSyntax (source, tokens));
-                       bridge.Visit(tokenizer.syntaxTree.GetRoot());
-
-                       Root = bridge.Root;
-
                        
+                       bridge.Visit(await tokenizer.syntaxTree.GetRootAsync());
 
+                       Root = bridge.Root;
                        return Root;
                }
        }
index 5f0b3d42e43bb4874f9a45d699b5f8c2f1bc0fd0..e90d6eccfc77f91b9af914bdfa5464532db52a51 100644 (file)
@@ -16,17 +16,19 @@ namespace CERoslynPlugin
 {
        public class CSTokenizer : Tokenizer
        {
-               protected List<Token> Toks;
                public SyntaxTree syntaxTree;
+               public CSTokenizer(SyntaxTree syntaxTree) {
+                       this.syntaxTree = syntaxTree;
+               }
 
-               public override Token[] Tokenize(ReadOnlySpan<char> source)
+               public override Token[] Tokenize(ReadOnlySpan<char> source = default)
                {
                        /*foreach (var e in Enum.GetNames(typeof(SyntaxKind))) {
                                Console.WriteLine($"case SyntaxKind.{e}:");
                                Console.WriteLine($"\treturn CSTokenType.Unknown;");
                        }*/
 
-                       syntaxTree = CSharpSyntaxTree.ParseText(source.ToString());
+//                     syntaxTree = CSharpSyntaxTree.ParseText(source.ToString());
                        CsharpSyntaxWalkerTokenizer bridge = new CsharpSyntaxWalkerTokenizer();
                        bridge.Visit(syntaxTree.GetRoot());
                        Toks = bridge.Toks;
index ff9f76aa9262d8aaf1b18b8f1c45d11b7eca0c9c..72ff3247b12525cbe5d6d9efc7bc09ae290d2a0d 100644 (file)
@@ -82,9 +82,13 @@ namespace CERoslynPlugin
                                                return "#icons.file_type_csharp.svg";
                                        case ".svg":
                                                return "#icons.file_type_svg.svg";
-                                       case ".crow":
                                        case ".xml":
                                                return "#icons.file_type_xml.svg";
+                                       case ".crow":
+                                       case ".template":
+                                       case ".itemp":
+                                       case ".iml":
+                                               return "#icons.file_type_xml.svg";
                                        default:
                                                return "#icons.blank-file.svg";
                                        }
index 42be30f1cdc700046bfce1558717ec500c8221d1..cf47c950334c1eb16fa04d2b9bf11e55519bd9a8 100644 (file)
@@ -5,6 +5,7 @@ using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Reflection.Metadata.Ecma335;
+using System.Threading.Tasks;
 using CrowEditBase;
 
 namespace CrowEdit.Xml
@@ -14,11 +15,12 @@ namespace CrowEdit.Xml
                public virtual void ProcessAttributeValueSyntax(AttributeSyntax attrib) {
                        attrib.valueTok = tokIdx - attrib.TokenIndexBase;
                }
-               public override SyntaxRootNode Process () {
+               public override async Task<SyntaxRootNode> Process () {
                        Tokenizer tokenizer = new XmlTokenizer();
+                       ReadOnlyMemory<char> source = document.ImmutableBufferCopy;
                        Token[] tokens = tokenizer.Tokenize(source.Span);
-
                        currentNode = Root = new XMLRootSyntax (source, tokens);
+
                        currentLine = 0;
                        tokIdx = 0;
 
index 7f865d421d22f0f296c72586d887a150b3f6714c..aa4a47d2afa11904c7fb16b97cd9a1934edf5042 100644 (file)
@@ -13,6 +13,7 @@ using CrowEditBase;
 using System.Linq;
 using System.Text;
 using Drawing2D;
+using System.Diagnostics;
 
 namespace CrowEdit
 {
@@ -177,6 +178,8 @@ namespace CrowEdit
                        } catch (Exception ex) {
                                MessageBox.ShowModal (this, MessageBox.Type.Alert, $"Unable to open {filePath}.\n{ex.Message}");
                                Log(LogType.Error, $"Unable to open {filePath}.\n{ex.Message}");
+                               Debug.WriteLine(ex.Message);
+                               Debug.WriteLine(ex.StackTrace);
                        }
                        return doc;
                }