Skip to content

Commit

Permalink
Исправил баг.
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-raevskiy committed Sep 22, 2014
1 parent 5b4ab7b commit a8241b0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
11 changes: 9 additions & 2 deletions dwarf-cs/dwarf.core/lang/Lexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ internal class Matcher
public Token Token { get; private set; }
public bool Stop { get; private set; }

public int MatchedLen
{
get { return matched.Length; }
}

public Matcher(ITokenRule rule)
{
this.rule = rule;
Expand Down Expand Up @@ -208,12 +213,14 @@ public IEnumerable<Token> Tokenize(string source)

if (matchers.All(m => m.Stop))
{
int len = 0;

foreach (var matcher in matchers)
{
if (matcher.Token != null)
if (matcher.Token != null && matcher.MatchedLen > len)
{
token = matcher.Token;
break;
len = matcher.MatchedLen;
}
}

Expand Down
14 changes: 14 additions & 0 deletions dwarf-cs/tests/LexerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ public void IfThenElseTest()
Assert.AreEqual(expected, actual);
}

[Test]
public void AmbiguousIdentifiersTest()
{
var source = Multiline(
"if iff");

var lexer = new Lexer();
var actual = String.Join("", lexer.Tokenize(source));

const string expected = "if [iff] ";

Assert.AreEqual(expected, actual);
}

[Test]
public void ConstTest()
{
Expand Down

0 comments on commit a8241b0

Please sign in to comment.