Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/danipen/TextMateSharp
Browse files Browse the repository at this point in the history
  • Loading branch information
danipen committed Feb 17, 2022
2 parents abcb8fa + 5315ab8 commit a5ba208
Show file tree
Hide file tree
Showing 60 changed files with 859 additions and 1,015 deletions.
20 changes: 10 additions & 10 deletions src/TextMateSharp.Tests/Internal/Oniguruma/OnigScannerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public void TestOnigScanner()

Assert.AreEqual(2, captureIndices.Length);

Assert.AreEqual(0, captureIndices[0].GetStart());
Assert.AreEqual(2, captureIndices[0].GetLength());
Assert.AreEqual(1, captureIndices[1].GetStart());
Assert.AreEqual(1, captureIndices[1].GetLength());
Assert.AreEqual(0, captureIndices[0].Start);
Assert.AreEqual(2, captureIndices[0].Length);
Assert.AreEqual(1, captureIndices[1].Start);
Assert.AreEqual(1, captureIndices[1].Length);
}

[Test]
Expand All @@ -32,10 +32,10 @@ public void TestOnigScanner2()

Assert.AreEqual(2, captureIndices.Length);

Assert.AreEqual(1, captureIndices[0].GetStart());
Assert.AreEqual(3, captureIndices[0].GetLength());
Assert.AreEqual(2, captureIndices[1].GetStart());
Assert.AreEqual(1, captureIndices[1].GetLength());
Assert.AreEqual(1, captureIndices[0].Start);
Assert.AreEqual(3, captureIndices[0].Length);
Assert.AreEqual(2, captureIndices[1].Start);
Assert.AreEqual(1, captureIndices[1].Length);
}

[Test]
Expand Down Expand Up @@ -72,8 +72,8 @@ static string ExtractCaptureText(
int index)
{
return text.Substring(
captures[index].GetStart(),
captures[index].GetLength());
captures[index].Start,
captures[index].Length);
}
}
}
4 changes: 2 additions & 2 deletions src/TextMateSharp/Grammar/ITokenizeLineResult2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace TextMateSharp.Grammars
{
public interface ITokenizeLineResult2
{
int[] GetTokens();
StackElement GetRuleStack();
int[] Tokens { get; }
StackElement RuleStack { get; }
}
}
19 changes: 10 additions & 9 deletions src/TextMateSharp/Grammar/Injection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,24 @@ namespace TextMateSharp.Grammars
{
public class Injection
{
public int Priority { get; private set; } // -1 | 0 | 1; // 0 is the default. -1 for 'L' and 1 for 'R'
public int? RuleId { get; private set; }
public IRawGrammar Grammar { get; private set; }

private Predicate<List<string>> matcher;
public int priority; // -1 | 0 | 1; // 0 is the default. -1 for 'L' and 1 for 'R'
public int? ruleId;
public IRawGrammar grammar;
private Predicate<List<string>> _matcher;

public Injection(Predicate<List<string>> matcher, int? ruleId, IRawGrammar grammar, int priority)
{
this.matcher = matcher;
this.ruleId = ruleId;
this.grammar = grammar;
this.priority = priority;
RuleId = ruleId;
Grammar = grammar;
Priority = priority;

this._matcher = matcher;
}

public bool Match(List<string> states)
{
return matcher.Invoke(states);
return _matcher.Invoke(states);
}
}
}
74 changes: 38 additions & 36 deletions src/TextMateSharp/Grammar/StackElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ public class StackElement
{
public static StackElement NULL = new StackElement(null, 0, 0, null, null, null);

private int enterPosition;
public StackElement parent;
public int depth;
public int? ruleId;
public string endRule;
public ScopeListElement nameScopesList;
public ScopeListElement contentNameScopesList;
public StackElement Parent { get; private set; }
public int Depth { get; private set; }
public int? RuleId { get; private set; }
public string EndRule { get; private set; }
public ScopeListElement NameScopesList { get; private set; }
public ScopeListElement ContentNameScopesList { get; private set; }

private int _enterPosition;

public StackElement(
StackElement parent,
Expand All @@ -26,13 +27,14 @@ public StackElement(
ScopeListElement nameScopesList,
ScopeListElement contentNameScopesList)
{
this.parent = parent;
this.depth = (this.parent != null ? this.parent.depth + 1 : 1);
this.ruleId = ruleId;
this.enterPosition = enterPos;
this.endRule = endRule;
this.nameScopesList = nameScopesList;
this.contentNameScopesList = contentNameScopesList;
Parent = parent;
Depth = (this.Parent != null ? this.Parent.Depth + 1 : 1);
RuleId = ruleId;
EndRule = endRule;
NameScopesList = nameScopesList;
ContentNameScopesList = contentNameScopesList;

_enterPosition = enterPos;
}

private static bool StructuralEquals(StackElement a, StackElement b)
Expand All @@ -45,7 +47,7 @@ private static bool StructuralEquals(StackElement a, StackElement b)
{
return false;
}
return a.depth == b.depth && a.ruleId == b.ruleId && Equals(a.endRule, b.endRule) && StructuralEquals(a.parent, b.parent);
return a.Depth == b.Depth && a.RuleId == b.RuleId && Equals(a.EndRule, b.EndRule) && StructuralEquals(a.Parent, b.Parent);
}

public override bool Equals(Object other)
Expand All @@ -62,38 +64,38 @@ public override bool Equals(Object other)
return false;
}
StackElement stackElement = (StackElement)other;
return StructuralEquals(this, stackElement) && this.contentNameScopesList.Equals(stackElement.contentNameScopesList);
return StructuralEquals(this, stackElement) && this.ContentNameScopesList.Equals(stackElement.ContentNameScopesList);
}

public override int GetHashCode()
{
return depth.GetHashCode() +
ruleId.GetHashCode() +
endRule.GetHashCode() +
parent.GetHashCode() +
contentNameScopesList.GetHashCode();
return Depth.GetHashCode() +
RuleId.GetHashCode() +
EndRule.GetHashCode() +
Parent.GetHashCode() +
ContentNameScopesList.GetHashCode();
}

public void Reset()
{
StackElement el = this;
while (el != null)
{
el.enterPosition = -1;
el = el.parent;
el._enterPosition = -1;
el = el.Parent;
}
}

public StackElement Pop()
{
return this.parent;
return this.Parent;
}

public StackElement SafePop()
{
if (this.parent != null)
if (this.Parent != null)
{
return this.parent;
return this.Parent;
}
return this;
}
Expand All @@ -105,22 +107,22 @@ public StackElement Push(int? ruleId, int enterPos, string endRule, ScopeListEle

public int GetEnterPos()
{
return this.enterPosition;
return this._enterPosition;
}

public Rule GetRule(IRuleRegistry grammar)
{
return grammar.GetRule(this.ruleId);
return grammar.GetRule(this.RuleId);
}

private void AppendString(List<string> res)
{
if (this.parent != null)
if (this.Parent != null)
{
this.parent.AppendString(res);
this.Parent.AppendString(res);
}

res.Add('(' + this.ruleId.ToString() + ')'); //, TODO-${this.nameScopesList}, TODO-${this.contentNameScopesList})`;
res.Add('(' + this.RuleId.ToString() + ')'); //, TODO-${this.nameScopesList}, TODO-${this.contentNameScopesList})`;
}

public override string ToString()
Expand All @@ -132,25 +134,25 @@ public override string ToString()

public StackElement setContentNameScopesList(ScopeListElement contentNameScopesList)
{
if (this.contentNameScopesList.Equals(contentNameScopesList))
if (this.ContentNameScopesList.Equals(contentNameScopesList))
{
return this;
}
return this.parent.Push(this.ruleId, this.enterPosition, this.endRule, this.nameScopesList, contentNameScopesList);
return this.Parent.Push(this.RuleId, this._enterPosition, this.EndRule, this.NameScopesList, contentNameScopesList);
}

public StackElement SetEndRule(string endRule)
{
if (this.endRule != null && this.endRule.Equals(endRule))
if (this.EndRule != null && this.EndRule.Equals(endRule))
{
return this;
}
return new StackElement(this.parent, this.ruleId, this.enterPosition, endRule, this.nameScopesList, this.contentNameScopesList);
return new StackElement(this.Parent, this.RuleId, this._enterPosition, endRule, this.NameScopesList, this.ContentNameScopesList);
}

public bool HasSameRuleAs(StackElement other)
{
return this.ruleId == other.ruleId;
return this.RuleId == other.RuleId;
}
}
}
Loading

0 comments on commit a5ba208

Please sign in to comment.