]> O.S.I.I.S - jp/crowedit.git/commitdiff
xml parsing debug
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Thu, 3 Jul 2025 20:47:27 +0000 (22:47 +0200)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Thu, 3 Jul 2025 20:47:27 +0000 (22:47 +0200)
15 files changed:
CrowEditBase/src/Compiler/SourceDocument.cs
CrowEditBase/src/Compiler/SyntaxAnalyser.cs
plugins/CECrowPlugin/src/Parsing/IML/ImlDocument.cs
plugins/CECrowPlugin/src/Parsing/IML/ImlSyntaxAnalyser.cs
plugins/CECrowPlugin/src/Parsing/Styling/StyleDocument.cs
plugins/CECrowPlugin/src/Parsing/Styling/StyleSyntaxAnalyser.cs
plugins/CEEbnfPlugin/src/Parsing/EbnfDocument.cs
plugins/CEEbnfPlugin/src/Parsing/EbnfSyntaxAnalyser.cs
plugins/CERoslynPlugin/src/CSDocument.cs
plugins/CERoslynPlugin/src/CSTokenizer.cs
plugins/CERoslynPlugin/src/Parsing/CSSyntaxAnalyser.cs
plugins/CEXmlPlugin/src/Parsing/XmlDocument.cs
plugins/CEXmlPlugin/src/Parsing/XmlSyntaxAnalyser.cs
plugins/CEXmlPlugin/src/Parsing/XmlSyntaxNodes.cs
plugins/CEXmlPlugin/src/Parsing/XmlTokenType.cs

index 1c5f98f60a1ca6ba8d90c3b56636187338599643..cee7da6972051e350290b0ebfae081ed7013f84d 100644 (file)
@@ -144,7 +144,6 @@ namespace CrowEditBase
                }
                public virtual string GetTokenTypeString (TokenType tokenType) => tokenType.ToString();
                //protected abstract Tokenizer CreateTokenizer ();
-               protected abstract SyntaxAnalyser CreateSyntaxAnalyser ();
                public abstract IList GetSuggestions (int absoluteTextPos, int currentTokenIndex, SyntaxNode currentNode, CharLocation loc);
                protected virtual async void parse () {
                        if (backgroundCompilationTask != null && !backgroundCompilationTask.IsCompleted) {
@@ -159,6 +158,7 @@ namespace CrowEditBase
                        
                        //CrowEditBase.App.Log (LogType.Low, $"Syntax Analysis done in {sw.ElapsedMilliseconds}(ms) {sw.ElapsedTicks}(ticks)");
                }
+               protected abstract SyntaxAnalyser CreateSyntaxAnalyser ();
 
                async void parseAssync(CancellationToken cancel) {
                        SyntaxAnalyser syntaxAnalyser = CreateSyntaxAnalyser ();
index 33392d5088399bf3e877286bbb79a22d14b64ead..9496f9f3fc320c8cfc9be5412fd080a731bdd81e 100644 (file)
@@ -3,21 +3,22 @@
 // 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;
 using System.Threading.Tasks;
-using Crow.Text;
 
 namespace CrowEditBase
 {
        public abstract class SyntaxAnalyser {
-               protected SourceDocument document;
+               #region CTOR
+               public SyntaxAnalyser (ReadOnlyTextBuffer source) {
+                       this.source = source;
+               }
+               #endregion
+
+               protected ReadOnlyTextBuffer source;
                protected SyntaxRootNode Root;
                protected CancellationToken cancel;
                public IEnumerable<SyntaxException> Exceptions => null;// Root?.GetAllExceptions();
-               public SyntaxAnalyser (SourceDocument document) {
-                       this.document = document;
-               }
                public abstract Task<SyntaxRootNode> Process (CancellationToken cancel = default);
                
                #region Token handling
index 1c2c9d8ce1bf53fbef043cbf1f83fda0d761e033..f4c42a396d9afae5b8c1af8c221669694a173b14 100644 (file)
@@ -28,7 +28,7 @@ namespace CECrowPlugin
                                if (msbp.IsCrowProject)
                        }*/
                }
-               protected override SyntaxAnalyser CreateSyntaxAnalyser() => new ImlSyntaxAnalyser (this);
+               protected override SyntaxAnalyser CreateSyntaxAnalyser() => new ImlSyntaxAnalyser (ImmutableBufferCopy);
                public override string GetTokenTypeString (TokenType tokenType) => ((ImlTokenType)tokenType).ToString();
 
 
index 196f0bf69e2d95c4d1e7d6045d21182d6a37d702..5c1fb3d80ef5600500966192c8563d0c3e0c6ec7 100644 (file)
@@ -12,7 +12,7 @@ using System.Threading;
 namespace CECrowPlugin
 {
        public class ImlSyntaxAnalyser : XmlSyntaxAnalyser {
-               public ImlSyntaxAnalyser (ImlDocument document) : base (document) {}
+               public ImlSyntaxAnalyser (ReadOnlyTextBuffer document) : base (document) {}
 
 
                public override async Task<SyntaxRootNode> Process (CancellationToken cancel = default) {
index 31a3b8a4abc48f36b3b7b38f74e009200df5b506..98c95535078acca6f17d4f856c63e56ed2ff2319 100644 (file)
@@ -22,7 +22,7 @@ namespace CECrowPlugin.Style
                        }*/
                }
 
-               protected override SyntaxAnalyser CreateSyntaxAnalyser() => new StyleSyntaxAnalyser (this);
+               protected override SyntaxAnalyser CreateSyntaxAnalyser() => new StyleSyntaxAnalyser (ImmutableBufferCopy);
 
                public override IList GetSuggestions (int absoluteTextPos, int currentTokenIndex, SyntaxNode CurrentNode, CharLocation loc) {
                        Token currentToken = GetTokenByIndex(currentTokenIndex);
index 24f15d57cc0ed54d65753b1ec64a56e06a21870d..2fce5e23da9b8ae93d047a1f2bd61f6bff5fc831 100644 (file)
@@ -22,7 +22,7 @@ namespace CECrowPlugin.Style
                public static bool Is(this Token tok, StyleTokenType type) => (StyleTokenType)tok.Type == type;
        }
        public class StyleSyntaxAnalyser : SyntaxAnalyser {
-               public StyleSyntaxAnalyser (StyleDocument document) : base (document) {}
+               public StyleSyntaxAnalyser (ReadOnlyTextBuffer document) : base (document) {}
 
                bool skipTriviaAndComments(MultiNodeSyntax currentNode) {
                        while (tryPeekFlag(out Token token, TokenType.Trivia)) {
@@ -153,12 +153,11 @@ namespace CECrowPlugin.Style
                
                public override async Task<SyntaxRootNode> Process (CancellationToken cancel = default) {
                        Tokenizer tokenizer = new StyleTokenizer();
-                       ReadOnlyTextBuffer buff = document.ImmutableBufferCopy;
-                       Token[] tokens = tokenizer.Tokenize(buff.Source.Span);
+                       Token[] tokens = tokenizer.Tokenize(source.Source.Span);
                        tokIdx = 0;
                        this.cancel = cancel;
 
-                       Root = new StyleRootSyntax (buff, tokens);
+                       Root = new StyleRootSyntax (source, tokens);
                        while (!EOF) {
                                if (cancel.IsCancellationRequested)
                                        break;
index cd1da2f9443fe57453cdd55dc34a042d0a54a71d..010a6ff2823ad4784edc981bf7618a5f05ac7a6a 100644 (file)
@@ -15,7 +15,7 @@ namespace CrowEdit.Ebnf
                public EbnfDocument (string fullPath, string editorPath) : base (fullPath, editorPath) {
 
                }
-               protected override SyntaxAnalyser CreateSyntaxAnalyser() => new EbnfSyntaxAnalyser (this);
+               protected override SyntaxAnalyser CreateSyntaxAnalyser() => new EbnfSyntaxAnalyser (ImmutableBufferCopy);
                public override string GetTokenTypeString (TokenType tokenType) => ((EbnfTokenType)tokenType).ToString();
 
                public override IList GetSuggestions (int absoluteTextPos, int currentTokenIndex, SyntaxNode CurrentNode, CharLocation loc) {
index 26d3c664ff3cefeeec31325b2cee6614063590a7..1d66375886abb1b43f767d7b338c8c5fa21e811e 100644 (file)
@@ -22,7 +22,7 @@ namespace CrowEdit.Ebnf
        }
 
        public class EbnfSyntaxAnalyser : SyntaxAnalyser {
-               public EbnfSyntaxAnalyser  (EbnfDocument document) : base (document) {}
+               public EbnfSyntaxAnalyser  (ReadOnlyTextBuffer document) : base (document) {}
                
 
                bool skipTriviaAndComments(MultiNodeSyntax currentNode) {
@@ -104,13 +104,12 @@ namespace CrowEdit.Ebnf
         public override async Task<SyntaxRootNode> Process(CancellationToken cancel = default)
         {
                        Tokenizer tokenizer = new EbnfTokenizer();
-                       ReadOnlyTextBuffer buff = document.ImmutableBufferCopy;
-                       Token[] tokens = tokenizer.Tokenize(buff.Source.Span);                  
+                       Token[] tokens = tokenizer.Tokenize(source.Source.Span);                        
 
                        tokIdx = 0;
                        this.cancel = cancel;
 
-                       Root = new EbnfRootSyntax (buff, tokens);
+                       Root = new EbnfRootSyntax (source, tokens);
 
 
                        /*while (!EOF) {
index d38afb9813e93e5ddc33928b7f9024376f2a0ee0..bf0bbcb1508fc675938a840921caec2ba9ec6814 100644 (file)
@@ -34,14 +34,10 @@ namespace CERoslynPlugin
                        App.GetService<RoslynService> ()?.Start ();
                }
 
-               internal CSharpSyntaxTree tree;
-               public CSDocument (string fullPath, string editorPath)  : base (fullPath, editorPath) {
-
-                       tree = (CSharpSyntaxTree)CSharpSyntaxTree.ParseText (source.ToString(), CSharpParseOptions.Default);
-               }
+               public CSDocument (string fullPath, string editorPath)  : base (fullPath, editorPath) { }
 
                #region SourceDocument abstract class implementation
-               protected override SyntaxAnalyser CreateSyntaxAnalyser() => new CSSyntaxAnalyser (this);
+               protected override SyntaxAnalyser CreateSyntaxAnalyser() => new CSSyntaxAnalyser (ImmutableBufferCopy);
 
                public override IList GetSuggestions (int absoluteTextPos, int currentTokenIndex, SyntaxNode CurrentNode, CharLocation loc)
                {
@@ -51,24 +47,6 @@ namespace CERoslynPlugin
                }
                #endregion
 
-               /*public override Color GetColorForToken (TokenType tokType) {
-                       uint rawkind = (uint)tokType;
-                       uint tokCat = rawkind & 0xFF;
-                       CSTokenType cat = (CSTokenType)tokCat;
-
-                       SyntaxKind k = (SyntaxKind)tokType;
-
-                       //Console.WriteLine($"{k,50} {(((uint)tokType) ).ToString("B16") } {cat}");
-                       
-                       switch (cat) {
-                               case CSTokenType.Trivia:
-                                       return Colors.Grey;
-                               case CSTokenType.Keyword:
-                                       return Colors.DarkSlateBlue;
-                               default:
-                                       return Colors.Black;
-                       }
-               }*/
                public override string GetTokenTypeString (TokenType tokenType) => ((SyntaxKind)tokenType).ToString();
                public override Color GetColorForToken(Token token)
                {
@@ -108,10 +86,5 @@ namespace CERoslynPlugin
 
                        parse();
         }
-        protected override void parse()
-        {      
-                       tree = (CSharpSyntaxTree)CSharpSyntaxTree.ParseText (source.ToString(), CSharpParseOptions.Default, "", null);
-            base.parse();
-        }
     }
 }
\ No newline at end of file
index e90d6eccfc77f91b9af914bdfa5464532db52a51..90766391448a7b542e7de6126314df0dc32e4c8d 100644 (file)
@@ -124,7 +124,7 @@ namespace CERoslynPlugin
                }
                CSTokenType convertTokenType(SyntaxKind kind) {
                        return (CSTokenType)kind;
-                       switch (kind) {
+                       /*switch (kind) {
                                case SyntaxKind.None:
                                        return CSTokenType.Unknown;
                                case SyntaxKind.List:
@@ -1117,7 +1117,7 @@ namespace CERoslynPlugin
                                        return CSTokenType.Unknown;
                                default:
                                        return CSTokenType.Unknown;
-                       }
+                       }*/
                }
        }
 }
\ No newline at end of file
index e797873e490ec93f23595b8d3cfcefbf369508c9..41698cbfbdebd74cb7c463a1c54601cf289e7ad1 100644 (file)
@@ -9,15 +9,12 @@ using Microsoft.CodeAnalysis.CSharp;
 namespace CERoslynPlugin
 {
        public class CSSyntaxAnalyser : SyntaxAnalyser {
-               CSDocument csdoc;
-               public CSSyntaxAnalyser (CSDocument document) : base (document) {
-                       csdoc = document;
-               }
+               public CSSyntaxAnalyser (ReadOnlyTextBuffer document) : base (document) { }
 
                public override async Task<SyntaxRootNode> Process (CancellationToken cancel = default) {
-                       ReadOnlyTextBuffer buff = document.ImmutableBufferCopy;
-                       CsharpSyntaxWalkerBridge bridge = new CsharpSyntaxWalkerBridge(new CSRootSyntax (buff), cancel);
-                       CSharpSyntaxNode csroot = await csdoc.tree.GetRootAsync(cancel);
+                       CSharpSyntaxTree tree = (CSharpSyntaxTree)CSharpSyntaxTree.ParseText (source.Source.Span.ToString(), CSharpParseOptions.Default, "", null);
+                       CsharpSyntaxWalkerBridge bridge = new CsharpSyntaxWalkerBridge(new CSRootSyntax (source), cancel);
+                       CSharpSyntaxNode csroot = await tree.GetRootAsync(cancel);
 
                        if (cancel.IsCancellationRequested)
                                return null;
index b05abb097b86cd175e47591869d65b3240f3082a..38d70f703c71028655b2e3be86dd2acf8ddedf6d 100644 (file)
@@ -16,7 +16,7 @@ namespace CrowEdit.Xml
        public class XmlDocument : SourceDocument {
 
                public XmlDocument (string fullPath, string editorPath) : base (fullPath, editorPath) { }
-               protected override SyntaxAnalyser CreateSyntaxAnalyser() => new XmlSyntaxAnalyser (this);
+               protected override SyntaxAnalyser CreateSyntaxAnalyser() => new XmlSyntaxAnalyser (ImmutableBufferCopy);
                public override string GetTokenTypeString (TokenType tokenType) => ((XmlTokenType)tokenType).ToString();
 
                protected virtual IEnumerable<Suggestion> getElementNameSuggestions(string curName, TextChange change) => null;
index 419ba8dcf8fe3af34ea6f5b01bf5987eeee372fd..96bb444dbd9c9af44f6950fe0e3cadd35a54df1a 100644 (file)
@@ -21,7 +21,7 @@ namespace CrowEdit.Xml
                public static bool Is(this Token tok, XmlTokenType type) => (XmlTokenType)tok.Type == type;
        }       
        public class XmlSyntaxAnalyser : SyntaxAnalyser {
-        public XmlSyntaxAnalyser (XmlDocument document) : base (document) {}
+        public XmlSyntaxAnalyser (ReadOnlyTextBuffer document) : base (document) {}
                bool skipTriviaAndComments(MultiNodeSyntax currentNode, bool skipLineBreaks = true) {
                        while (tryPeekFlag(out Token token, TokenType.Trivia)) {
                                switch(token.GetTokenType()) {
@@ -96,7 +96,25 @@ namespace CrowEdit.Xml
                        }
                        return pi;
                }
-
+               ElementSyntax processElement(ElementSyntax elt) {
+                       while (!EOF) {
+                               if (cancel.IsCancellationRequested)
+                                       break;
+                               if (!skipTriviaAndComments(elt))
+                                       break;
+                               if (Peek().Is(XmlTokenType.ElementOpen)) {
+                                       processElementNode(elt);
+                               } else if (Peek().Is(XmlTokenType.EndElementOpen)) {
+                                       elt.AddChild(processNode(new ElementEndTagSyntax(Read())));
+                                       break;
+                               } else if (Peek().Is(XmlTokenType.PI_Start)) {
+                                       elt.AddChild(processNode(new ProcessingInstructionSyntax(Read())));
+                               } else {
+                                       elt.AddChild(new UnexpectedTokenSyntax(Read()));
+                               }
+                       }                       
+                       return elt;
+               }
                void processElementNode(MultiNodeSyntax node) {
                        ElementStartTagSyntax start = new ElementStartTagSyntax(Read());
                        if (accept (start, XmlTokenType.ElementName)) {
@@ -118,34 +136,14 @@ namespace CrowEdit.Xml
                                start.AddChild(new UnexpectedTokenSyntax(Read()));
                                node.AddChild(new ElementSyntax(start));
                        }
-               }
-               ElementSyntax processElement(ElementSyntax elt) {
-                       while (!EOF) {
-                               if (cancel.IsCancellationRequested)
-                                       break;
-                               if (!skipTriviaAndComments(elt))
-                                       break;
-                               if (Peek().Is(XmlTokenType.ElementOpen)) {
-                                       processElementNode(elt);
-                               } else if (Peek().Is(XmlTokenType.EndElementOpen)) {
-                                       elt.AddChild(processNode(new ElementEndTagSyntax(Read())));
-                                       break;
-                               } else if (Peek().Is(XmlTokenType.PI_Start)) {
-                                       elt.AddChild(processNode(new ProcessingInstructionSyntax(Read())));
-                               } else {
-                                       elt.AddChild(new UnexpectedTokenSyntax(Read()));
-                               }
-                       }                       
-                       return elt;
-               }
+               }               
                public override async Task<SyntaxRootNode> Process (CancellationToken cancel = default) {
                        Tokenizer tokenizer = new XmlTokenizer();
-                       ReadOnlyTextBuffer buff = document.ImmutableBufferCopy;
-                       Token[] tokens = tokenizer.Tokenize(buff.Source.Span);
+                       Token[] tokens = tokenizer.Tokenize(source.Source.Span);
                        tokIdx = 0;
                        this.cancel = cancel;//?
                        
-                       Root = new XMLRootSyntax (buff, tokens);
+                       Root = new XMLRootSyntax (source, tokens);
                        while (!EOF) {
                                if (cancel.IsCancellationRequested)
                                        break;
index 4fc91f1bc7f02ca513422f6fc67ce779518c6366..7e870c25d6abae48cb6cc6c4a52062863ff6046c 100644 (file)
@@ -42,7 +42,8 @@ namespace CrowEdit.Xml
 
        public class EmptyElementSyntax : MultiNodeSyntax {
                public EmptyElementSyntax (ElementStartTagSyntax startNode) {
-                       AddChild (startNode);
+                       foreach (var child in startNode.Children)
+                               AddChild(child);
                }
         //public override bool IsComplete => base.IsComplete && StartTag != null;
     }
index 18d4c4945afc5c8649a7b9dbaf027b282eb4887b..4cbd24459ab87c49bf7ab7e83f15bf5f0e63a190 100644 (file)
@@ -18,24 +18,24 @@ namespace CrowEdit.Xml
                BlockComment                    = 0x0105,
                BlockCommentEnd                 = 0x0106,
                Name                                    = 0x0200,
-               ElementName                             = 0x8201,
-               AttributeName                   = 0x8202,
-               PI_Target                               = 0x8203,
+               ElementName                             = 0x0201,
+               AttributeName                   = 0x0202,
+               PI_Target                               = 0x0203,
+               ConstantName                    = 0x0204,
                Punctuation                             = 0x0400,
-
-               PI_Start                                = 0x8401,// '<?'
-               PI_End                                  = 0x8402,// '?>'
-               ElementOpen                     = 0x8403,// '<'
-               EndElementOpen                  = 0x8404,// '</'
-               EmptyElementClosing             = 0x8405,// '/>'
-               ClosingSign                             = 0x8406,// '>'
-               DTDObjectOpen                   = 0x84A0,// '<!'
+               PI_Start                                = 0x0401,// '<?'
+               PI_End                                  = 0x0402,// '?>'
+               ElementOpen                     = 0x0403,// '<'
+               EndElementOpen                  = 0x0404,// '</'
+               EmptyElementClosing             = 0x0405,// '/>'
+               ClosingSign                             = 0x0406,// '>'
+               DTDObjectOpen                   = 0x04A0,// '<!'
                Operator                                = 0x0800,
                EqualSign                               = 0x0801,
                Keyword                                 = 0x1000,
-               AttributeValue                  = 0x8000,
-               AttributeValueOpen              = 0x8401,
-               AttributeValueClose             = 0x8402,
+               AttributeValue                  = 0x2000,
+               AttributeValueOpen              = 0x2001,
+               AttributeValueClose             = 0x2002,
 
 
                Content,