: base (fullPath, editorPath) {
}
protected Token[] tokens;
- protected SyntaxNode RootNode;
+ protected SyntaxRootNode root;
+ protected int currentTokenIndex;
+ SyntaxNode currentNode;
+
protected Token currentToken => currentTokenIndex < 0 ? default : tokens[currentTokenIndex];
protected Token? previousToken {
get {
return tokens[currentTokenIndex-1];
}
}
- SyntaxNode currentNode;
public SyntaxNode CurrentNode {
get => currentNode;
set {
NotifyValueChanged ("CurrentNode", currentNode);
}
}
- public string CurrentTokenString => RootNode?.Root.GetTokenStringByIndex (currentTokenIndex);
+ public string CurrentTokenString => root?.GetTokenStringByIndex (currentTokenIndex);
public Token CurrentToken => currentToken;
- public bool IsParsed => tokens.Length > 0 && RootNode != null;
+ public bool IsParsed => tokens.Length > 0 && root != null;
+ public SyntaxRootNode Root => root;
//public SyntaxNode EditedNode { get; protected set; }
- protected int currentTokenIndex;
public Token[] Tokens => tokens;
- public SyntaxNode SyntaxRootNode => RootNode;
- public IEnumerable<SyntaxNode> SyntaxRootChildNodes => RootNode?.children;
+ public IEnumerable<SyntaxNode> SyntaxRootChildNodes => root?.children;
public LineCollection Lines => lines;
public Token FindTokenIncludingPosition (int pos) {
if (pos == 0 || tokens == null || tokens.Length == 0)
/// if outermost is true, return oldest ancestor exept root node, useful for folding.
/// </summary>
public SyntaxNode FindNodeIncludingPosition (int pos, bool outerMost = false) {
- if (RootNode == null)
+ if (root == null)
return null;
- if (!RootNode.Contains (pos))
+ if (!root.Contains (pos))
return null;
- SyntaxNode sn = RootNode.FindNodeIncludingPosition (pos);
+ SyntaxNode sn = root.FindNodeIncludingPosition (pos);
if (outerMost) {
- while (sn.Parent != RootNode && sn.Span.Start == sn.Parent.Span.Start)
+ while (sn.Parent != root && sn.Span.Start == sn.Parent.Span.Start)
sn = sn.Parent;
}
return sn;
}
public T FindNodeIncludingPosition<T> (int pos) {
- if (RootNode == null)
+ if (root == null)
return default;
- if (!RootNode.Contains (pos))
+ if (!root.Contains (pos))
return default;
- return RootNode.FindNodeIncludingPosition<T> (pos);
+ return root.FindNodeIncludingPosition<T> (pos);
}
public SyntaxNode FindNodeIncludingSpan (TextSpan span) {
- if (RootNode == null)
+ if (root == null)
return null;
- if (!RootNode.Contains (span))
+ if (!root.Contains (span))
return null;
- return RootNode.FindNodeIncludingSpan (span);
+ return root.FindNodeIncludingSpan (span);
}
protected override void reloadFromFile () {
base.reloadFromFile ();
SyntaxAnalyser syntaxAnalyser = CreateSyntaxAnalyser ();
if (syntaxAnalyser == null) {
- RootNode = null;
+ root = null;
return;
}
- SyntaxNode changedNode = RootNode.FindNodeIncludingSpan (TextSpan.FromStartAndLength (change.Start, change.ChangedText.Length));
-
+ //SyntaxNode changedNode = root.FindNodeIncludingSpan (TextSpan.FromStartAndLength (change.Start, change.ChangedText.Length));
tokens = tokenizer.Tokenize (buffer.Span);
-
-
syntaxAnalyser.Process ();
- NotifyValueChanged("Exceptions", syntaxAnalyser.Exceptions);
+ root = syntaxAnalyser.Root;
+ NotifyValueChanged("Exceptions", syntaxAnalyser.Exceptions);
+ /*
SyntaxNode newNode = syntaxAnalyser.Root.FindNodeIncludingSpan (TextSpan.FromStartAndLength (change.Start, change.ChangedText.Length));
if (editedNode == null) {
//System.Diagnostics.Debugger.Break ();
- RootNode = syntaxAnalyser.Root;
+ root = syntaxAnalyser.Root;
} else if (newNode.IsSimilar (editedNode)) {
if (!tryReplaceNode (editedNode, newNode))
RootNode = syntaxAnalyser.Root;
//System.Diagnostics.Debugger.Break ();
RootNode = syntaxAnalyser.Root;
}
+ */
//updateCurrentTokAndNode (change.End2);
//EditedNode = editedNode;
Stopwatch sw = Stopwatch.StartNew ();
syntaxAnalyser?.Process ();
sw.Stop();
- RootNode = syntaxAnalyser?.Root;
+ root = syntaxAnalyser?.Root;
//CrowEditBase.App.Log (LogType.Low, $"Syntax Analysis done in {sw.ElapsedMilliseconds}(ms) {sw.ElapsedTicks}(ticks)");
if (syntaxAnalyser == null)
return;
- LogItem log = CrowEditBase.App.GetLog(this.FileName);
- log.ResetLog();
- foreach (SyntaxException ex in syntaxAnalyser.Exceptions)
- log.Add(LogType.Error, $"{ex}");
-
/*foreach (Token t in Tokens)
Console.WriteLine ($"{t,-40} {Source.AsSpan(t.Start, t.Length).ToString()}");
syntaxAnalyser.Root.Dump();*/
public abstract class SyntaxAnalyser {
//protected abstract void Parse(SyntaxNode node);
protected SourceDocument source;
- public abstract SyntaxNode Root { get; }
+ public SyntaxRootNode Root { get; protected set; }
public IEnumerable<SyntaxException> Exceptions => Root?.GetAllExceptions();
public SyntaxAnalyser (SourceDocument source) {
this.source = source;
{
public class SyntaxException : Exception {
public readonly Token Token;
- public SyntaxException(string message, Token token = default, Exception innerException = null)
+ public readonly SyntaxAnalyser SyntaxAnalyser;
+ public SyntaxException(string message, Token token = default, SyntaxAnalyser syntaxAnalyser = null, Exception innerException = null)
: base (message, innerException) {
Token = token;
+ SyntaxAnalyser = syntaxAnalyser;
}
- public override string ToString() => $"{Message}, {Token}";
+ public string TokenString => SyntaxAnalyser.Root.GetTokenString(Token);
+ public override string ToString() => $"{Message}: {TokenString}";
}
}
\ No newline at end of file
Log(LogType.Normal,"Crow edit started");
}
+ protected DockStack mainDock;
+ protected const string _defaultFileName = "unnamed.txt";
+ Document currentDocument;
+ Editor currentEditor;
+ Project currentProject;
+ public CommandGroup CommandsRoot, FileCommands, EditCommands, ViewCommands;
+ public ObservableList<Document> OpenedDocuments = new ObservableList<Document> ();
+ public ObservableList<Service> Services = new ObservableList<Service> ();
+ public ObservableList<Plugin> Plugins = new ObservableList<Plugin> ();
+ public ObservableList<Project> Projects = new ObservableList<Project> ();
+
+
#region logging
LogItem currentLog;
public LogItem CurrentLog {
#endregion
- protected const string _defaultFileName = "unnamed.txt";
- Document currentDocument;
- Editor currentEditor;
- Project currentProject;
- public CommandGroup CommandsRoot, FileCommands, EditCommands, ViewCommands;
- public ObservableList<Document> OpenedDocuments = new ObservableList<Document> ();
- public ObservableList<Service> Services = new ObservableList<Service> ();
- public ObservableList<Plugin> Plugins = new ObservableList<Plugin> ();
- public ObservableList<Project> Projects = new ObservableList<Project> ();
public T GetService<T> () where T : Service {
T service = Services.OfType<T>().FirstOrDefault ();
if (service == null) {
Configuration.Global.Save ();
}
- protected DockStack mainDock;
protected void reloadWinConfigs() {
if (Configuration.Global.TryGet<string>("WinConfigs", out string conf) && !string.IsNullOrEmpty(conf))
public string EditorPath { get; private set; }//the ressource path is used as an id for editor template selection.
public event EventHandler CloseEvent;
- protected ReaderWriterLockSlim editorRWLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
- public void EnterReadLock () => editorRWLock.EnterReadLock ();
- public void ExitReadLock () => editorRWLock.ExitReadLock ();
- public void EnterWriteLock () => editorRWLock.EnterWriteLock ();
- public void ExitWriteLock () => editorRWLock.ExitWriteLock ();
+ protected ReaderWriterLockSlim documentRWLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
+ public void EnterReadLock () => documentRWLock.EnterReadLock ();
+ public void ExitReadLock () => documentRWLock.ExitReadLock ();
+ public void EnterWriteLock () => documentRWLock.EnterWriteLock ();
+ public void ExitWriteLock () => documentRWLock.ExitWriteLock ();
public abstract bool TryGetState<T> (object client, out T state);
public abstract void RegisterClient (object client);
protected abstract void readFromDisk ();
protected abstract void initNewFile ();
protected virtual void reloadFromFile () {
- editorRWLock.EnterWriteLock ();
+ documentRWLock.EnterWriteLock ();
try {
if (File.Exists (FullPath))
readFromDisk ();
else
initNewFile ();
} finally {
- editorRWLock.ExitWriteLock ();
+ documentRWLock.ExitWriteLock ();
}
}
public abstract bool IsDirty { get; }
public override void onKeyPress (object sender, KeyPressEventArgs e) {
base.onKeyPress (sender, e);
- TextSpan selection = Selection;
- update (new TextChange (selection.Start, selection.Length, e.KeyChar.ToString ()));
+ if (!e.Handled) {
+ TextSpan selection = Selection;
+ update (new TextChange (selection.Start, selection.Length, e.KeyChar.ToString ()));
+ e.Handled = true;
+ }
/*Insert (e.KeyChar.ToString());
SelRelease = -1;
if (Document is SourceDocument doc) {
switch (e.Key) {
case Key.F3:
- doc.SyntaxRootNode?.Dump();
+ doc.Root?.Dump();
break;
case Key.Enter:
case Key.KeypadEnter:
SyntaxNode getFoldStartingAt (int line) {
if (!(Document is SourceDocument doc))
return null;
- IEnumerable<SyntaxNode> folds = doc.SyntaxRootNode.FoldableNodes;
+ IEnumerable<SyntaxNode> folds = doc.Root.FoldableNodes;
if (folds == null)
return null;
return folds.FirstOrDefault (n => n.StartLine == line);
return null;
doc.EnterReadLock();
try {
- IEnumerable<SyntaxNode> folds = doc.SyntaxRootNode.FoldableNodes;
+ IEnumerable<SyntaxNode> folds = doc.Root.FoldableNodes;
if (folds == null)
return null;
return folds.LastOrDefault (n => n.StartLine <= line && n.EndLine >= line);
doc.EnterReadLock();
try {
int foldedLines = 0;
- IEnumerator<SyntaxNode> foldsEnum = doc.SyntaxRootNode.FoldableNodes.GetEnumerator();
+ IEnumerator<SyntaxNode> foldsEnum = doc.Root.FoldableNodes.GetEnumerator();
bool notEndOfFolds = foldsEnum.MoveNext();
while (notEndOfFolds && foldsEnum.Current.StartLine < absoluteLine) {
if (foldsEnum.Current.isFolded) {
doc.EnterReadLock();
try {
int foldedLines = 0;
- IEnumerator<SyntaxNode> nodeEnum = doc.SyntaxRootNode.FoldableNodes.GetEnumerator ();
+ IEnumerator<SyntaxNode> nodeEnum = doc.Root.FoldableNodes.GetEnumerator ();
if (!nodeEnum.MoveNext())
return 0;
SyntaxNode curNode = null;
- IEnumerator<SyntaxNode> nodeEnum = doc.SyntaxRootNode.FoldableNodes.GetEnumerator ();
+ IEnumerator<SyntaxNode> nodeEnum = doc.Root.FoldableNodes.GetEnumerator ();
bool notEndOfNodes = nodeEnum.MoveNext();
gr.LineWidth = 1;
Dictionary<object, List<TextChange>> registeredClients = new Dictionary<object, List<TextChange>>();
public override bool TryGetState<T>(object client, out T state) {
state = default;
- if (editorRWLock.TryEnterReadLock (10)) {
+ if (documentRWLock.TryEnterReadLock (10)) {
try {
state = (T)(object)registeredClients[client];
registeredClients[client] = null;
} finally {
- editorRWLock.ExitReadLock ();
+ documentRWLock.ExitReadLock ();
}
}
return state != null;
}
public override void RegisterClient(object client)
{
- editorRWLock.EnterWriteLock ();
+ documentRWLock.EnterWriteLock ();
registeredClients.Add (client, null);
//notifyClient (client, new TextChange (0, 0, source));
- editorRWLock.ExitWriteLock ();
+ documentRWLock.ExitWriteLock ();
}
public override void UnregisterClient(object client)
{
- editorRWLock.EnterWriteLock ();
+ documentRWLock.EnterWriteLock ();
registeredClients.Remove (client);
- editorRWLock.ExitWriteLock ();
+ documentRWLock.ExitWriteLock ();
}
void notifyClients (TextChange tc, object triggeringClient = null) {
object[] clients = registeredClients.Keys.ToArray ();
buffer = new TextBuffer("");
}
protected override void reloadFromFile () {
- editorRWLock.EnterWriteLock ();
+ documentRWLock.EnterWriteLock ();
try {
if (File.Exists (FullPath))
readFromDisk ();
initNewFile ();
resetUndoRedo ();
} finally {
- editorRWLock.ExitWriteLock ();
+ documentRWLock.ExitWriteLock ();
}
}
protected Stack<TextChange> undoStack = new Stack<TextChange> ();
}
protected override void undo () {
- editorRWLock.EnterWriteLock ();
+ documentRWLock.EnterWriteLock ();
try {
if (undoStack.TryPop (out TextChange tc)) {
redoStack.Push (tc.Inverse (source));
if (undoStack.Count == 0)
CMDUndo.CanExecute = false;
} finally {
- editorRWLock.ExitWriteLock ();
+ documentRWLock.ExitWriteLock ();
}
}
protected override void redo () {
- editorRWLock.EnterWriteLock ();
+ documentRWLock.EnterWriteLock ();
try {
if (redoStack.TryPop (out TextChange tc)) {
undoStack.Push (tc.Inverse (source));
if (redoStack.Count == 0)
CMDRedo.CanExecute = false;
} finally {
- editorRWLock.ExitWriteLock ();
+ documentRWLock.ExitWriteLock ();
}
}
CMDSave.CanExecute = IsDirty;
}
protected void applyTextChange (TextChange change, object triggeringEditor = null) {
- editorRWLock.EnterWriteLock ();
+ documentRWLock.EnterWriteLock ();
try {
undoStack.Push (change.Inverse (source));
redoStack.Clear ();
apply (change);
notifyClients (change, triggeringEditor);
} finally {
- editorRWLock.ExitWriteLock ();
+ documentRWLock.ExitWriteLock ();
}
-
}
protected void onTextChanged (object sender, TextChangeEventArgs e) {
applyTextChange (e.Change, sender);
}
protected void getLines () {
- editorRWLock.EnterWriteLock ();
+ documentRWLock.EnterWriteLock ();
if (lines == null)
lines = new LineCollection (10);
else
lines.Add (new TextLine (0, 0, 0));
else
lines.Update (source);
- editorRWLock.ExitWriteLock ();
+ documentRWLock.ExitWriteLock ();
}
public string GetLineBreak () {
- editorRWLock.EnterReadLock ();
+ documentRWLock.EnterReadLock ();
try {
if (string.IsNullOrEmpty (lineBreak)) {
mixedLineBreak = false;
}
return lineBreak;
} finally {
- editorRWLock.ExitReadLock();
+ documentRWLock.ExitReadLock();
}
}
public CharLocation GetLocation (int absolutePosition) {
- editorRWLock.EnterReadLock ();
+ documentRWLock.EnterReadLock ();
try {
return lines.GetLocation (absolutePosition);
} finally {
- editorRWLock.ExitReadLock();
+ documentRWLock.ExitReadLock();
}
}
public int GetAbsolutePosition (CharLocation loc) {
- editorRWLock.EnterReadLock ();
+ documentRWLock.EnterReadLock ();
try {
return lines.GetAbsolutePosition (loc);
} finally {
- editorRWLock.ExitReadLock();
+ documentRWLock.ExitReadLock();
}
}
public CharLocation EndLocation {
get {
- editorRWLock.EnterReadLock ();
+ documentRWLock.EnterReadLock ();
try {
return new CharLocation (lines.Count - 1, lines[lines.Count - 1].Length);
} finally {
- editorRWLock.ExitReadLock();
+ documentRWLock.ExitReadLock();
}
}
}
get {
if (lines == null)
getLines();
- editorRWLock.EnterReadLock ();
+ documentRWLock.EnterReadLock ();
try {
return lines.Count;
} finally {
- editorRWLock.ExitReadLock();
+ documentRWLock.ExitReadLock();
}
}
}
public int Lenght {
get {
- editorRWLock.EnterReadLock ();
+ documentRWLock.EnterReadLock ();
try {
return source.Length;
} finally {
- editorRWLock.ExitReadLock();
+ documentRWLock.ExitReadLock();
}
}
}
public TextLine GetLine (int index) {
- editorRWLock.EnterReadLock ();
+ documentRWLock.EnterReadLock ();
try {
return lines[index];
} finally {
- editorRWLock.ExitReadLock();
+ documentRWLock.ExitReadLock();
}
}
public ReadOnlySpan<char> GetText (TextLine line) {
- editorRWLock.EnterReadLock ();
+ documentRWLock.EnterReadLock ();
try {
return source.GetLine (line);
} finally {
- editorRWLock.ExitReadLock();
+ documentRWLock.ExitReadLock();
}
}
public ReadOnlySpan<char> GetText (TextSpan span) {
- editorRWLock.EnterReadLock ();
+ documentRWLock.EnterReadLock ();
try {
return source.Slice (span.Start, span.Length);
} finally {
- editorRWLock.ExitReadLock();
+ documentRWLock.ExitReadLock();
}
}
public char GetChar (int pos){
- editorRWLock.EnterReadLock ();
+ documentRWLock.EnterReadLock ();
try {
return source[pos];
} finally {
- editorRWLock.ExitReadLock();
+ documentRWLock.ExitReadLock();
}
}
public virtual CharLocation GetWordStart (CharLocation loc) {
- editorRWLock.EnterReadLock ();
+ documentRWLock.EnterReadLock ();
try {
int pos = lines.GetAbsolutePosition (loc);
//skip white spaces
pos--;
return lines.GetLocation (pos);
} finally {
- editorRWLock.ExitReadLock();
+ documentRWLock.ExitReadLock();
}
}
public virtual CharLocation GetWordEnd (CharLocation loc) {
- editorRWLock.EnterReadLock ();
+ documentRWLock.EnterReadLock ();
try {
int pos = lines.GetAbsolutePosition (loc);
//skip white spaces
pos++;
return lines.GetLocation (pos);
} finally {
- editorRWLock.ExitReadLock();
+ documentRWLock.ExitReadLock();
}
}
}
<Label Text="Col:" Foreground="Grey"/>
<Label Text="{../../tb.TabulatedColumn}" Margin="3"/>
</HorizontalStack>
- <Splitter/>
- <ListBox Data='{Exceptions}' Height='100' Width='Stretched'/>
</VerticalStack>
</ListItem>
+++ /dev/null
-// Copyright (c) 2013-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.Linq;
-using Crow.Text;
-using System.Collections.Generic;
-using System.Diagnostics;
-using Crow;
-using IML = Crow.IML;
-using System.Collections;
-using System.Reflection;
-using CrowEditBase;
-using static CrowEditBase.CrowEditBase;
-
-using CrowEdit.Xml;
-
-using AttributeSyntax = CrowEdit.Xml.AttributeSyntax;
-using Drawing2D;
-
-namespace CECrowPlugin
-{
- public class ImlDocument : XmlDocument {
-
-
- public ImlDocument (string fullPath, string editorPath) : base (fullPath, editorPath) {
- App.GetService<CrowService> ()?.Start ();
-
- /*if (project is MSBuildProject msbp) {
- if (msbp.IsCrowProject)
- }*/
- }
- protected override Tokenizer CreateTokenizer() => new ImlTokenizer ();
- protected override SyntaxAnalyser CreateSyntaxAnalyser() => new ImlSyntaxAnalyser (this);
- public override string GetTokenTypeString (TokenType tokenType) => ((ImlTokenType)tokenType).ToString();
-
- string[] allWidgetNames = typeof (Widget).Assembly.GetExportedTypes ().Where(t=>typeof(Widget).IsAssignableFrom (t))
- .Select (s => s.Name).ToArray ();
-
-
- IEnumerable<MemberInfo> getAllCrowTypeMembers (string crowTypeName) {
- Type crowType = IML.Instantiator.GetWidgetTypeFromName (crowTypeName);
- return crowType?.GetMembers (BindingFlags.Public | BindingFlags.Instance).
- Where (m=>((m is PropertyInfo pi && pi.CanWrite) || (m is EventInfo)) &&
- m.GetCustomAttribute<XmlIgnoreAttribute>() == null);
- }
- MemberInfo getCrowTypeMember (string crowTypeName, string memberName) {
- Type crowType = IML.Instantiator.GetWidgetTypeFromName (crowTypeName);
- return crowType.GetMember (memberName, BindingFlags.Public | BindingFlags.Instance).FirstOrDefault ();
- }
-
- protected bool previousTokHasFlag(ImlTokenType flag) => previousToken.HasValue && previousToken.Value.Type.HasFlag(flag);
-
- protected bool tryCast<TOUT> (object objectToCast, out TOUT result) {
- result = default;
- if (typeof(TOUT).IsAssignableFrom(objectToCast.GetType())) {
- result = (TOUT)objectToCast;
- return true;
- }
-
- return false;
- }
- public override IList GetSuggestions (CharLocation loc) {
- IList sugs = base.GetSuggestions (loc);
- if (sugs != null)
- return sugs;
-
- //Token tok = currentToken.Length == 0 || currentToken.Type.HasFlag(TokenType.Trivia) ? previousToken : currentToken;
- Token tok = currentToken;
-
- if (tok.GetTokenType() == XmlTokenType.ElementOpen)
- return new List<string> (allWidgetNames);
- if (tok.GetTokenType() == XmlTokenType.ElementName)
- return allWidgetNames.Where (s => s.StartsWith (RootNode.Root.GetTokenString(tok), StringComparison.OrdinalIgnoreCase)).ToList ();
- if ((tok.Type.HasFlag(TokenType.WhiteSpace) || previousTokHasFlag(TokenType.WhiteSpace)) &&
- tryCast(CurrentNode, out ElementTagSyntax ets)) {
- if (ets.name.HasValue)
- return getAllCrowTypeMembers (ets.Name).ToList();
- return null;
- }
-
- if (CurrentNode is CrowEdit.Xml.AttributeSyntax attribNode) {
- if (CurrentNode.Parent is ElementTagSyntax eltTag) {
- if (!string.IsNullOrEmpty (eltTag.Name)) {
- if (tok.GetTokenType() == XmlTokenType.AttributeName) {
- return getAllCrowTypeMembers (eltTag.Name)
- .Where (s => s.Name.StartsWith (RootNode.Root.GetTokenString(tok), StringComparison.OrdinalIgnoreCase)).ToList ();
- } else if (!string.IsNullOrEmpty (attribNode.Name)) {
- if (tok.GetTokenType() == XmlTokenType.AttributeValue) {
- MemberInfo mi = getCrowTypeMember (
- eltTag.Name, attribNode.Name);
- if (mi is PropertyInfo pi) {
- if (pi.Name == "Style")
- return App.Styling.Keys
- .Where (s => s.StartsWith (RootNode.Root.GetTokenString(tok), StringComparison.OrdinalIgnoreCase)).ToList ();
- if (pi.PropertyType.IsEnum)
- return Enum.GetNames (pi.PropertyType)
- .Where (s => s.StartsWith (RootNode.Root.GetTokenString(tok), StringComparison.OrdinalIgnoreCase)).ToList ();
- if (pi.PropertyType == typeof(bool))
- return (new string[] {"true", "false"}).
- Where (s => s.StartsWith (RootNode.Root.GetTokenString(tok), StringComparison.OrdinalIgnoreCase)).ToList ();
- if (pi.PropertyType == typeof (Measure))
- return (new string[] {"Stretched", "Fit"}).
- Where (s => s.StartsWith (RootNode.Root.GetTokenString(tok), StringComparison.OrdinalIgnoreCase)).ToList ();
- if (pi.PropertyType == typeof (Fill))
- return EnumsNET.Enums.GetValues<Colors> ()
- .Where (s => s.ToString().StartsWith (RootNode.Root.GetTokenString(tok), StringComparison.OrdinalIgnoreCase)).ToList ();
- }
- } else if (tok.GetTokenType() == XmlTokenType.AttributeValueOpen) {
- MemberInfo mi = getCrowTypeMember (
- eltTag.Name, attribNode.Name);
- if (mi is PropertyInfo pi) {
- if (pi.Name == "Style")
- return App.Styling.Keys.ToList ();
- if (pi.PropertyType.IsEnum)
- return Enum.GetNames (pi.PropertyType).ToList ();
- if (pi.PropertyType == typeof(bool))
- return new List<string> (new string[] {"true", "false"});
- if (pi.PropertyType == typeof (Fill))
- return EnumsNET.Enums.GetValues<Colors> ().ToList ();
- if (pi.PropertyType == typeof (Measure))
- return new List<string> (new string[] {"Stretched", "Fit"});
- }
- }
- }
- }
- }
- } /*else if (tok.GetTokenType() != XmlTokenType.AttributeValueClose &&
- tok.GetTokenType() != XmlTokenType.EmptyElementClosing &&
- tok.GetTokenType() != XmlTokenType.ClosingSign &&
- CurrentNode is ElementStartTagSyntax eltStartTag) {
- if (tok.GetTokenType() == XmlTokenType.AttributeName)
- return getAllCrowTypeMembers (eltStartTag.Name)
- .Where (s => s.Name.StartsWith (tok.AsString (Source), StringComparison.OrdinalIgnoreCase)).ToList ();
- //else if (tok.Type == TokenType.ElementName)
- // Suggestions = getAllCrowTypeMembers (eltStartTag.NameToken.Value.AsString (Source)).ToList ();
- } else {
- }*/
- return null;
- }
- public override bool TryGetCompletionForCurrentToken (object suggestion, out TextChange change, out TextSpan? newSelection) {
- return base.TryGetCompletionForCurrentToken (suggestion is MemberInfo mi ? mi.Name : suggestion, out change, out newSelection);
- }
-
- public override Color GetColorForToken(TokenType tokType)
- {
- switch ((ImlTokenType)tokType) {
- case ImlTokenType.BindingOpen:
- case ImlTokenType.BindingClose:
- return Colors.DarkGreen;
- case ImlTokenType.BindingName: return Colors.RoyalBlue;
- case ImlTokenType.BindingDot:
- case ImlTokenType.BindingDoubleDot:
- case ImlTokenType.BindingLevel:
- return Colors.MediumVioletRed;
- case ImlTokenType.ConstantName:
- case ImlTokenType.ConstantRefOpen:
- case ImlTokenType.ConstantRefClose:
- return Colors.Brown;
- }
- return base.GetColorForToken (tokType);
- }
- }
-}
\ No newline at end of file
--- /dev/null
+// Copyright (c) 2013-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.Linq;
+using Crow.Text;
+using System.Collections.Generic;
+using System.Diagnostics;
+using Crow;
+using IML = Crow.IML;
+using System.Collections;
+using System.Reflection;
+using CrowEditBase;
+using static CrowEditBase.CrowEditBase;
+
+using CrowEdit.Xml;
+
+using AttributeSyntax = CrowEdit.Xml.AttributeSyntax;
+using Drawing2D;
+
+namespace CECrowPlugin
+{
+ public class ImlDocument : XmlDocument {
+
+
+ public ImlDocument (string fullPath, string editorPath) : base (fullPath, editorPath) {
+ App.GetService<CrowService> ()?.Start ();
+
+ /*if (project is MSBuildProject msbp) {
+ if (msbp.IsCrowProject)
+ }*/
+ }
+ protected override Tokenizer CreateTokenizer() => new ImlTokenizer ();
+ protected override SyntaxAnalyser CreateSyntaxAnalyser() => new ImlSyntaxAnalyser (this);
+ public override string GetTokenTypeString (TokenType tokenType) => ((ImlTokenType)tokenType).ToString();
+
+ string[] allWidgetNames = typeof (Widget).Assembly.GetExportedTypes ().Where(t=>typeof(Widget).IsAssignableFrom (t))
+ .Select (s => s.Name).ToArray ();
+
+
+ IEnumerable<MemberInfo> getAllCrowTypeMembers (string crowTypeName) {
+ Type crowType = IML.Instantiator.GetWidgetTypeFromName (crowTypeName);
+ return crowType?.GetMembers (BindingFlags.Public | BindingFlags.Instance).
+ Where (m=>((m is PropertyInfo pi && pi.CanWrite) || (m is EventInfo)) &&
+ m.GetCustomAttribute<XmlIgnoreAttribute>() == null);
+ }
+ MemberInfo getCrowTypeMember (string crowTypeName, string memberName) {
+ Type crowType = IML.Instantiator.GetWidgetTypeFromName (crowTypeName);
+ return crowType.GetMember (memberName, BindingFlags.Public | BindingFlags.Instance).FirstOrDefault ();
+ }
+
+ protected bool previousTokHasFlag(ImlTokenType flag) => previousToken.HasValue && previousToken.Value.Type.HasFlag(flag);
+
+ protected bool tryCast<TOUT> (object objectToCast, out TOUT result) {
+ result = default;
+ if (typeof(TOUT).IsAssignableFrom(objectToCast.GetType())) {
+ result = (TOUT)objectToCast;
+ return true;
+ }
+
+ return false;
+ }
+ public override IList GetSuggestions (CharLocation loc) {
+ IList sugs = base.GetSuggestions (loc);
+ if (sugs != null)
+ return sugs;
+
+ //Token tok = currentToken.Length == 0 || currentToken.Type.HasFlag(TokenType.Trivia) ? previousToken : currentToken;
+ Token tok = currentToken;
+
+ if (tok.GetTokenType() == XmlTokenType.ElementOpen)
+ return new List<string> (allWidgetNames);
+ if (tok.GetTokenType() == XmlTokenType.ElementName)
+ return allWidgetNames.Where (s => s.StartsWith (root.GetTokenString(tok), StringComparison.OrdinalIgnoreCase)).ToList ();
+ if ((tok.Type.HasFlag(TokenType.WhiteSpace) || previousTokHasFlag(TokenType.WhiteSpace)) &&
+ tryCast(CurrentNode, out ElementTagSyntax ets)) {
+ if (ets.name.HasValue)
+ return getAllCrowTypeMembers (ets.Name).ToList();
+ return null;
+ }
+
+ if (CurrentNode is CrowEdit.Xml.AttributeSyntax attribNode) {
+ if (CurrentNode.Parent is ElementTagSyntax eltTag) {
+ if (!string.IsNullOrEmpty (eltTag.Name)) {
+ if (tok.GetTokenType() == XmlTokenType.AttributeName) {
+ return getAllCrowTypeMembers (eltTag.Name)
+ .Where (s => s.Name.StartsWith (root.GetTokenString(tok), StringComparison.OrdinalIgnoreCase)).ToList ();
+ } else if (!string.IsNullOrEmpty (attribNode.Name)) {
+ if (tok.GetTokenType() == XmlTokenType.AttributeValue) {
+ MemberInfo mi = getCrowTypeMember (
+ eltTag.Name, attribNode.Name);
+ if (mi is PropertyInfo pi) {
+ if (pi.Name == "Style")
+ return App.Styling.Keys
+ .Where (s => s.StartsWith (root.GetTokenString(tok), StringComparison.OrdinalIgnoreCase)).ToList ();
+ if (pi.PropertyType.IsEnum)
+ return Enum.GetNames (pi.PropertyType)
+ .Where (s => s.StartsWith (root.GetTokenString(tok), StringComparison.OrdinalIgnoreCase)).ToList ();
+ if (pi.PropertyType == typeof(bool))
+ return (new string[] {"true", "false"}).
+ Where (s => s.StartsWith (root.GetTokenString(tok), StringComparison.OrdinalIgnoreCase)).ToList ();
+ if (pi.PropertyType == typeof (Measure))
+ return (new string[] {"Stretched", "Fit"}).
+ Where (s => s.StartsWith (root.GetTokenString(tok), StringComparison.OrdinalIgnoreCase)).ToList ();
+ if (pi.PropertyType == typeof (Fill))
+ return EnumsNET.Enums.GetValues<Colors> ()
+ .Where (s => s.ToString().StartsWith (root.GetTokenString(tok), StringComparison.OrdinalIgnoreCase)).ToList ();
+ }
+ } else if (tok.GetTokenType() == XmlTokenType.AttributeValueOpen) {
+ MemberInfo mi = getCrowTypeMember (
+ eltTag.Name, attribNode.Name);
+ if (mi is PropertyInfo pi) {
+ if (pi.Name == "Style")
+ return App.Styling.Keys.ToList ();
+ if (pi.PropertyType.IsEnum)
+ return Enum.GetNames (pi.PropertyType).ToList ();
+ if (pi.PropertyType == typeof(bool))
+ return new List<string> (new string[] {"true", "false"});
+ if (pi.PropertyType == typeof (Fill))
+ return EnumsNET.Enums.GetValues<Colors> ().ToList ();
+ if (pi.PropertyType == typeof (Measure))
+ return new List<string> (new string[] {"Stretched", "Fit"});
+ }
+ }
+ }
+ }
+ }
+ } /*else if (tok.GetTokenType() != XmlTokenType.AttributeValueClose &&
+ tok.GetTokenType() != XmlTokenType.EmptyElementClosing &&
+ tok.GetTokenType() != XmlTokenType.ClosingSign &&
+ CurrentNode is ElementStartTagSyntax eltStartTag) {
+ if (tok.GetTokenType() == XmlTokenType.AttributeName)
+ return getAllCrowTypeMembers (eltStartTag.Name)
+ .Where (s => s.Name.StartsWith (tok.AsString (Source), StringComparison.OrdinalIgnoreCase)).ToList ();
+ //else if (tok.Type == TokenType.ElementName)
+ // Suggestions = getAllCrowTypeMembers (eltStartTag.NameToken.Value.AsString (Source)).ToList ();
+ } else {
+ }*/
+ return null;
+ }
+ public override bool TryGetCompletionForCurrentToken (object suggestion, out TextChange change, out TextSpan? newSelection) {
+ return base.TryGetCompletionForCurrentToken (suggestion is MemberInfo mi ? mi.Name : suggestion, out change, out newSelection);
+ }
+
+ public override Color GetColorForToken(TokenType tokType)
+ {
+ switch ((ImlTokenType)tokType) {
+ case ImlTokenType.BindingOpen:
+ case ImlTokenType.BindingClose:
+ return Colors.DarkGreen;
+ case ImlTokenType.BindingName: return Colors.RoyalBlue;
+ case ImlTokenType.BindingDot:
+ case ImlTokenType.BindingDoubleDot:
+ case ImlTokenType.BindingLevel:
+ return Colors.MediumVioletRed;
+ case ImlTokenType.ConstantName:
+ case ImlTokenType.ConstantRefOpen:
+ case ImlTokenType.ConstantRefClose:
+ return Colors.Brown;
+ }
+ return base.GetColorForToken (tokType);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+// 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;
+using CrowEdit.Xml;
+
+namespace CECrowPlugin
+{
+ public class ImlSyntaxAnalyser : XmlSyntaxAnalyser {
+ public ImlSyntaxAnalyser (ImlDocument source) : base (source) {
+ this.source = source;
+ }
+
+
+ public override void Process () {
+
+ base.Process();
+
+/*
+ ImlDocument xmlDoc = source as ImlDocument;
+ Exceptions = new List<SyntaxException> ();
+ currentNode = new XMLRootSyntax (xmlDoc);
+ currentLine = 0;
+ Span<Token> toks = source.Tokens;
+ tokIdx = 0;
+
+ while (tokIdx < toks.Length) {
+ Token curTok = toks[tokIdx];
+ if (curTok.Type == TokenType.LineBreak)
+ currentLine++;
+ else if (!curTok.Type.HasFlag (TokenType.Trivia)) {
+ if (currentNode is ElementStartTagSyntax tag) {
+ if (curTok.GetTokenType() == XmlTokenType.AttributeName) {
+ AttributeSyntax attribute = new AttributeSyntax (currentLine, tokIdx);
+ attribute.name = 0;
+ currentNode = currentNode.AddChild (attribute);
+ } else if (curTok.GetTokenType() == XmlTokenType.ElementName)
+ tag.name = tokIdx - tag.TokenIndexBase;
+ else if (curTok.GetTokenType() == XmlTokenType.ClosingSign) {
+ storeCurrentNode ();
+ currentNode.RemoveChild (tag);
+ currentNode = currentNode.AddChild (new ElementSyntax (tag));
+ } else if (curTok.GetTokenType() == XmlTokenType.EmptyElementClosing) {
+ storeCurrentNode ();
+ currentNode.RemoveChild (tag);
+ currentNode = currentNode.AddChild (new EmptyElementSyntax (tag));
+ setCurrentNodeEndLine (currentLine);
+ currentNode = currentNode.Parent;
+ } else {
+ Exceptions.Add (new SyntaxException ("Unexpected Token", curTok));
+ storeCurrentNode (-1);
+ continue;
+ }
+ } else if (currentNode is ElementSyntax elt) {
+ if (curTok.GetTokenType() == XmlTokenType.ElementOpen)
+ currentNode = currentNode.AddChild (new ElementStartTagSyntax (currentLine, tokIdx));
+ else if (curTok.GetTokenType() == XmlTokenType.EndElementOpen) {
+ elt.EndTag = new ElementEndTagSyntax (currentLine, tokIdx);
+ currentNode = elt.AddChild (elt.EndTag);
+ }
+ } else if (currentNode is AttributeSyntax attrib) {
+ if (curTok.GetTokenType() == XmlTokenType.EqualSign)
+ if (attrib.equal.HasValue)
+ Exceptions.Add (new SyntaxException ("Extra equal sign in attribute syntax", curTok));
+ else
+ attrib.equal = tokIdx - attrib.TokenIndexBase;
+ else if (curTok.GetTokenType() == XmlTokenType.AttributeValueOpen)
+ attrib.valueOpen = tokIdx - attrib.TokenIndexBase;
+ else if (curTok.GetTokenType() == XmlTokenType.AttributeValue)
+ attrib.valueTok = tokIdx - attrib.TokenIndexBase;
+ else if (curTok.GetTokenType() == XmlTokenType.AttributeValueClose) {
+ attrib.valueClose = tokIdx - attrib.TokenIndexBase;
+ storeCurrentNode ();
+ } else {
+ Exceptions.Add (new SyntaxException ("Unexpected Token", curTok));
+ storeCurrentNode (-1);
+ continue;
+ }
+ } else if (currentNode is ElementEndTagSyntax eltEndTag) {
+ if (curTok.GetTokenType() == XmlTokenType.ElementName)
+ eltEndTag.name = tokIdx - eltEndTag.TokenIndexBase;
+ else if (curTok.GetTokenType() == XmlTokenType.ClosingSign) {
+ //go up 2 times
+ storeCurrentNode (); storeCurrentNode ();
+ } else {
+ Exceptions.Add (new SyntaxException ("Unexpected Token", curTok));
+ storeCurrentNode (-1);
+ storeCurrentNode (-1);
+ continue;
+ }
+ } else if (currentNode is XMLRootSyntax) {
+ switch (curTok.GetTokenType()) {
+ case XmlTokenType.ElementOpen:
+ currentNode = currentNode.AddChild (new ElementStartTagSyntax (currentLine, tokIdx));
+ break;
+ case XmlTokenType.PI_Start:
+ currentNode = currentNode.AddChild (new ProcessingInstructionSyntax (currentLine, tokIdx));
+ break;
+ default:
+ Exceptions.Add (new SyntaxException ("Unexpected Token", curTok));
+ break;
+ }
+ } else if (currentNode is ProcessingInstructionSyntax pi) {
+ if (curTok.GetTokenType() == XmlTokenType.PI_Target)
+ pi.name = tokIdx - pi.TokenIndexBase;
+ else if (curTok.GetTokenType() == XmlTokenType.PI_End) {
+ storeCurrentNode ();
+ } else if (curTok.GetTokenType() == XmlTokenType.AttributeName) {
+ AttributeSyntax attribute = new AttributeSyntax (currentLine, tokIdx);
+ attribute.name = 0;
+ currentNode = currentNode.AddChild (attribute);
+ } else {
+ Exceptions.Add (new SyntaxException ("Unexpected Token", curTok));
+ storeCurrentNode (-1);
+ continue;
+ }
+ }
+ }
+ tokIdx++;
+ }
+ while (currentNode.Parent != null) {
+ if (!currentNode.LastTokenOffset.HasValue)
+ storeCurrentNode (-1);
+ else
+ currentNode = currentNode.Parent;
+ }
+ setCurrentNodeEndLine (currentLine);
+ */
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+// Copyright (c) 2013-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.Linq;
+using Crow.Text;
+using CrowEditBase;
+
+namespace CECrowPlugin
+{
+
+
+
+ public class AttributeSyntax : SyntaxNode {
+ internal int? name, equal, valueOpen, valueClose, valueTok;
+ public string Name => name.HasValue ? Root.GetTokenStringByIndex (TokenIndexBase + name.Value) : null;
+ public string Value => valueTok.HasValue ? Root.GetTokenStringByIndex (TokenIndexBase + valueTok.Value) : null;
+ public Token? ValueToken => valueTok.HasValue ? Root.GetTokenByIndex (TokenIndexBase + valueTok.Value) : null;
+ public AttributeSyntax (int startLine, int tokenBase)
+ : base (startLine, tokenBase) {}
+ public override bool IsComplete => base.IsComplete & name.HasValue & equal.HasValue & valueTok.HasValue & valueOpen.HasValue & valueClose.HasValue;
+ }
+}
\ No newline at end of file
+++ /dev/null
-// 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;
-using CrowEdit.Xml;
-
-namespace CECrowPlugin
-{
- public class ImlSyntaxAnalyser : XmlSyntaxAnalyser {
- public ImlSyntaxAnalyser (ImlDocument source) : base (source) {
- this.source = source;
- }
-
-
- public override void Process () {
-
- base.Process();
-
-/*
- ImlDocument xmlDoc = source as ImlDocument;
- Exceptions = new List<SyntaxException> ();
- currentNode = new XMLRootSyntax (xmlDoc);
- currentLine = 0;
- Span<Token> toks = source.Tokens;
- tokIdx = 0;
-
- while (tokIdx < toks.Length) {
- Token curTok = toks[tokIdx];
- if (curTok.Type == TokenType.LineBreak)
- currentLine++;
- else if (!curTok.Type.HasFlag (TokenType.Trivia)) {
- if (currentNode is ElementStartTagSyntax tag) {
- if (curTok.GetTokenType() == XmlTokenType.AttributeName) {
- AttributeSyntax attribute = new AttributeSyntax (currentLine, tokIdx);
- attribute.name = 0;
- currentNode = currentNode.AddChild (attribute);
- } else if (curTok.GetTokenType() == XmlTokenType.ElementName)
- tag.name = tokIdx - tag.TokenIndexBase;
- else if (curTok.GetTokenType() == XmlTokenType.ClosingSign) {
- storeCurrentNode ();
- currentNode.RemoveChild (tag);
- currentNode = currentNode.AddChild (new ElementSyntax (tag));
- } else if (curTok.GetTokenType() == XmlTokenType.EmptyElementClosing) {
- storeCurrentNode ();
- currentNode.RemoveChild (tag);
- currentNode = currentNode.AddChild (new EmptyElementSyntax (tag));
- setCurrentNodeEndLine (currentLine);
- currentNode = currentNode.Parent;
- } else {
- Exceptions.Add (new SyntaxException ("Unexpected Token", curTok));
- storeCurrentNode (-1);
- continue;
- }
- } else if (currentNode is ElementSyntax elt) {
- if (curTok.GetTokenType() == XmlTokenType.ElementOpen)
- currentNode = currentNode.AddChild (new ElementStartTagSyntax (currentLine, tokIdx));
- else if (curTok.GetTokenType() == XmlTokenType.EndElementOpen) {
- elt.EndTag = new ElementEndTagSyntax (currentLine, tokIdx);
- currentNode = elt.AddChild (elt.EndTag);
- }
- } else if (currentNode is AttributeSyntax attrib) {
- if (curTok.GetTokenType() == XmlTokenType.EqualSign)
- if (attrib.equal.HasValue)
- Exceptions.Add (new SyntaxException ("Extra equal sign in attribute syntax", curTok));
- else
- attrib.equal = tokIdx - attrib.TokenIndexBase;
- else if (curTok.GetTokenType() == XmlTokenType.AttributeValueOpen)
- attrib.valueOpen = tokIdx - attrib.TokenIndexBase;
- else if (curTok.GetTokenType() == XmlTokenType.AttributeValue)
- attrib.valueTok = tokIdx - attrib.TokenIndexBase;
- else if (curTok.GetTokenType() == XmlTokenType.AttributeValueClose) {
- attrib.valueClose = tokIdx - attrib.TokenIndexBase;
- storeCurrentNode ();
- } else {
- Exceptions.Add (new SyntaxException ("Unexpected Token", curTok));
- storeCurrentNode (-1);
- continue;
- }
- } else if (currentNode is ElementEndTagSyntax eltEndTag) {
- if (curTok.GetTokenType() == XmlTokenType.ElementName)
- eltEndTag.name = tokIdx - eltEndTag.TokenIndexBase;
- else if (curTok.GetTokenType() == XmlTokenType.ClosingSign) {
- //go up 2 times
- storeCurrentNode (); storeCurrentNode ();
- } else {
- Exceptions.Add (new SyntaxException ("Unexpected Token", curTok));
- storeCurrentNode (-1);
- storeCurrentNode (-1);
- continue;
- }
- } else if (currentNode is XMLRootSyntax) {
- switch (curTok.GetTokenType()) {
- case XmlTokenType.ElementOpen:
- currentNode = currentNode.AddChild (new ElementStartTagSyntax (currentLine, tokIdx));
- break;
- case XmlTokenType.PI_Start:
- currentNode = currentNode.AddChild (new ProcessingInstructionSyntax (currentLine, tokIdx));
- break;
- default:
- Exceptions.Add (new SyntaxException ("Unexpected Token", curTok));
- break;
- }
- } else if (currentNode is ProcessingInstructionSyntax pi) {
- if (curTok.GetTokenType() == XmlTokenType.PI_Target)
- pi.name = tokIdx - pi.TokenIndexBase;
- else if (curTok.GetTokenType() == XmlTokenType.PI_End) {
- storeCurrentNode ();
- } else if (curTok.GetTokenType() == XmlTokenType.AttributeName) {
- AttributeSyntax attribute = new AttributeSyntax (currentLine, tokIdx);
- attribute.name = 0;
- currentNode = currentNode.AddChild (attribute);
- } else {
- Exceptions.Add (new SyntaxException ("Unexpected Token", curTok));
- storeCurrentNode (-1);
- continue;
- }
- }
- }
- tokIdx++;
- }
- while (currentNode.Parent != null) {
- if (!currentNode.LastTokenOffset.HasValue)
- storeCurrentNode (-1);
- else
- currentNode = currentNode.Parent;
- }
- setCurrentNodeEndLine (currentLine);
- */
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-// Copyright (c) 2013-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.Linq;
-using Crow.Text;
-using CrowEditBase;
-
-namespace CECrowPlugin
-{
-
-
-
- public class AttributeSyntax : SyntaxNode {
- internal int? name, equal, valueOpen, valueClose, valueTok;
- public string Name => name.HasValue ? Root.GetTokenStringByIndex (TokenIndexBase + name.Value) : null;
- public string Value => valueTok.HasValue ? Root.GetTokenStringByIndex (TokenIndexBase + valueTok.Value) : null;
- public Token? ValueToken => valueTok.HasValue ? Root.GetTokenByIndex (TokenIndexBase + valueTok.Value) : null;
- public AttributeSyntax (int startLine, int tokenBase)
- : base (startLine, tokenBase) {}
- public override bool IsComplete => base.IsComplete & name.HasValue & equal.HasValue & valueTok.HasValue & valueOpen.HasValue & valueClose.HasValue;
- }
-}
\ No newline at end of file
--- /dev/null
+// Copyright (c) 2013-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 Crow.Text;
+using Crow;
+using System.Collections;
+using CrowEditBase;
+using static CrowEditBase.CrowEditBase;
+using Drawing2D;
+
+namespace CECrowPlugin.Style
+{
+ public class StyleDocument : SourceDocument {
+
+
+ public StyleDocument (string fullPath, string editorPath) : base (fullPath, editorPath) {
+ App.GetService<CrowService> ()?.Start ();
+
+ /*if (project is MSBuildProject msbp) {
+ if (msbp.IsCrowProject)
+ }*/
+ }
+
+ protected override Tokenizer CreateTokenizer() => new StyleTokenizer ();
+ protected override SyntaxAnalyser CreateSyntaxAnalyser() => new StyleSyntaxAnalyser (this);
+
+ public override IList GetSuggestions (CharLocation loc) {
+ Console.ForegroundColor = ConsoleColor.DarkYellow;
+ Console.WriteLine ($"Tok: {this.CurrentTokenString} {((StyleTokenType)CurrentToken.Type).ToString()}");
+ Console.ResetColor();
+ return null;
+ }
+ public override bool TryGetCompletionForCurrentToken(object suggestion, out TextChange change, out TextSpan? newSelection)
+ {
+ change = default;
+ newSelection = null;
+ return false;
+ }
+ public override Color GetColorForToken(TokenType tokType)
+ {
+ StyleTokenType xmlTokType = (StyleTokenType)tokType;
+ if (xmlTokType.HasFlag (StyleTokenType.Punctuation))
+ return Colors.DarkGrey;
+ if (xmlTokType.HasFlag (StyleTokenType.Trivia))
+ return Colors.DimGrey;
+ if (xmlTokType == StyleTokenType.MemberName)
+ return Colors.Blue;
+ if (xmlTokType == StyleTokenType.ConstantName)
+ return Colors.DarkCyan;
+ else if (xmlTokType.HasFlag (StyleTokenType.Name))
+ return Colors.Green;
+ if (xmlTokType == StyleTokenType.MemberValuePart)
+ return Colors.OrangeRed;
+ if (xmlTokType == StyleTokenType.EqualSign)
+ return Colors.Black;
+ if (xmlTokType == StyleTokenType.Unknown)
+ return Colors.Red;
+ return Colors.YellowGreen;
+ }
+ }
+}
\ No newline at end of file
}
}
public class StyleSyntaxAnalyser : SyntaxAnalyser {
- public override SyntaxNode Root => currentNode;
public StyleSyntaxAnalyser (StyleDocument source) : base (source) {
this.source = source;
}
public override void Process () {
StyleDocument doc = source as StyleDocument;
- currentNode = new StyleRootSyntax (doc);
+ currentNode = Root = new StyleRootSyntax (doc);
currentLine = 0;
Span<Token> toks = source.Tokens;
tokIdx = 0;
+++ /dev/null
-// Copyright (c) 2013-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 Crow.Text;
-using Crow;
-using System.Collections;
-using CrowEditBase;
-using static CrowEditBase.CrowEditBase;
-using Drawing2D;
-
-namespace CECrowPlugin.Style
-{
- public class StyleDocument : SourceDocument {
-
-
- public StyleDocument (string fullPath, string editorPath) : base (fullPath, editorPath) {
- App.GetService<CrowService> ()?.Start ();
-
- /*if (project is MSBuildProject msbp) {
- if (msbp.IsCrowProject)
- }*/
- }
-
- protected override Tokenizer CreateTokenizer() => new StyleTokenizer ();
- protected override SyntaxAnalyser CreateSyntaxAnalyser() => new StyleSyntaxAnalyser (this);
-
- public override IList GetSuggestions (CharLocation loc) {
- Console.ForegroundColor = ConsoleColor.DarkYellow;
- Console.WriteLine ($"Tok: {this.CurrentTokenString} {((StyleTokenType)CurrentToken.Type).ToString()}");
- Console.ResetColor();
- return null;
- }
- public override bool TryGetCompletionForCurrentToken(object suggestion, out TextChange change, out TextSpan? newSelection)
- {
- change = default;
- newSelection = null;
- return false;
- }
- public override Color GetColorForToken(TokenType tokType)
- {
- StyleTokenType xmlTokType = (StyleTokenType)tokType;
- if (xmlTokType.HasFlag (StyleTokenType.Punctuation))
- return Colors.DarkGrey;
- if (xmlTokType.HasFlag (StyleTokenType.Trivia))
- return Colors.DimGrey;
- if (xmlTokType == StyleTokenType.MemberName)
- return Colors.Blue;
- if (xmlTokType == StyleTokenType.ConstantName)
- return Colors.DarkCyan;
- else if (xmlTokType.HasFlag (StyleTokenType.Name))
- return Colors.Green;
- if (xmlTokType == StyleTokenType.MemberValuePart)
- return Colors.OrangeRed;
- if (xmlTokType == StyleTokenType.EqualSign)
- return Colors.Black;
- if (xmlTokType == StyleTokenType.Unknown)
- return Colors.Red;
- return Colors.YellowGreen;
- }
- }
-}
\ No newline at end of file
{
public class EbnfSyntaxAnalyser : SyntaxAnalyser {
- public override SyntaxNode Root => currentNode;
public EbnfSyntaxAnalyser (EbnfDocument source) : base (source) {
this.source = source;
}
public override void Process()
{
EbnfDocument doc = source as EbnfDocument;
- currentNode = new EbnfRootSyntax (doc);
+ currentNode = Root = new EbnfRootSyntax (doc);
currentLine = 0;
tokIdx = 0;
tokens = doc.Tokens;
--- /dev/null
+// 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 CERoslynPlugin
+{
+ public class CSRootSyntax : SyntaxRootNode {
+ public CSRootSyntax (SourceDocument source)
+ : base (source) {
+ }
+ }
+ public class CSSyntaxAnalyser : SyntaxAnalyser {
+ /*protected override void Parse(SyntaxNode node)
+ {
+ throw new NotImplementedException();
+ }*/
+
+ public CSSyntaxAnalyser (CSDocument source) : base (source) {
+ this.source = source;
+ }
+
+ public override void Process () {
+ currentNode = Root = new CSRootSyntax (source);
+ }
+ }
+}
\ No newline at end of file
+++ /dev/null
-// 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 CERoslynPlugin
-{
- public class CSRootSyntax : SyntaxRootNode {
- public CSRootSyntax (SourceDocument source)
- : base (source) {
- }
- }
- public class CSSyntaxAnalyser : SyntaxAnalyser {
- public override SyntaxNode Root => currentNode;
- /*protected override void Parse(SyntaxNode node)
- {
- throw new NotImplementedException();
- }*/
-
- public CSSyntaxAnalyser (CSDocument source) : base (source) {
- this.source = source;
- }
-
- public override void Process () {
- currentNode = new CSRootSyntax (source);
- }
- }
-}
\ No newline at end of file
} else {
int offset = 1;
if (!attrib.valueClose.HasValue) {
- selectedSugg += RootNode.Root.GetTokenStringByIndex(attrib.valueClose.Value);
+ selectedSugg += root.GetTokenStringByIndex(attrib.valueClose.Value);
offset = 0;
}
if (tokType == XmlTokenType.AttributeValueOpen)
namespace CrowEdit.Xml
{
public class XmlSyntaxAnalyser : SyntaxAnalyser {
- public override SyntaxNode Root => currentNode;
- /*protected override void Parse(SyntaxNode node)
- {
- throw new NotImplementedException();
- }*/
public XmlSyntaxAnalyser (XmlDocument source) : base (source) {
this.source = source;
}
-
- /*public virtual SyntaxNode Process (SyntaxNode startingNode) {
-
- }*/
public virtual void ProcessAttributeValueSyntax(AttributeSyntax attrib) {
attrib.valueTok = tokIdx - attrib.TokenIndexBase;
}
public override void Process () {
XmlDocument xmlDoc = source as XmlDocument;
- currentNode = new XMLRootSyntax (xmlDoc);
+ currentNode = Root = new XMLRootSyntax (xmlDoc);
currentLine = 0;
tokIdx = 0;
tokens = source.Tokens;
ViewCommands = new CommandGroup ("View",
new ActionCommand("Explorer", () => LoadWindow ("#CrowEdit.ui.windows.winFileExplorer.crow", this)),
new ActionCommand("Editors", () => LoadWindow ("#CrowEdit.ui.windows.winEditor.crow", this)),
+ new ActionCommand("Exceptions", () => LoadWindow ("#CrowEdit.ui.windows.winExceptions.crow", this)),
new ActionCommand("Projects", () => LoadWindow ("#CrowEdit.ui.windows.winProjects.crow", this)),
new ActionCommand("Logs", () => LoadWindow ("#CrowEdit.ui.windows.winLogs.crow", this), "#icons.log.svg"),
new ActionCommand("Services", () => LoadWindow ("#CrowEdit.ui.windows.winServices.crow", this), "#icons.services.svg"),
--- /dev/null
+<?xml version="1.0"?>
+<DockWindow Caption="Exceptions" Width="40%" Height="20%">
+ <ListBox DataSource="{CurrentDocument}" Data='{Exceptions}' Height='Stretched' Width='Stretched'/>
+</DockWindow>
+
+