-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
11 changed files
with
179 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using sly.lexer; | ||
|
||
namespace ParserTests.Issue485; | ||
|
||
public enum Issue485Lexer | ||
{ | ||
[Sugar(":")] COLON, | ||
[Keyword("Property")] PROPERTY, | ||
[String] STRING | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using sly.lexer; | ||
using sly.parser.generator; | ||
|
||
namespace ParserTests.Issue485; | ||
|
||
[ParserRoot("root")] | ||
public class Issue485Parser | ||
{ | ||
[Production("root : PROPERTY[d] COLON[d] STRING")] | ||
public string Parse(Token<Issue485Lexer> str) | ||
{ | ||
return str.StringWithoutQuotes; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using sly.lexer; | ||
|
||
namespace ParserTests.Issue485; | ||
|
||
public enum Issue485SelfEscapeLexer | ||
{ | ||
[Sugar(":")] COLON, | ||
[Keyword("Property")] PROPERTY, | ||
[String("\"","\"")] STRING | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using sly.lexer; | ||
using sly.parser.generator; | ||
|
||
namespace ParserTests.Issue485; | ||
|
||
[ParserRoot("root")] | ||
public class Issue485SelfEscapeParser | ||
{ | ||
[Production("root : PROPERTY[d] COLON[d] STRING")] | ||
public string Parse(Token<Issue485SelfEscapeLexer> str) | ||
{ | ||
return str.StringWithoutQuotes; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using NFluent; | ||
using sly.parser.generator; | ||
using Xunit; | ||
|
||
namespace ParserTests.Issue485; | ||
|
||
public class Issue485Tests | ||
{ | ||
[Fact] | ||
public void TestIssue485() | ||
{ | ||
var builder = new ParserBuilder<Issue485Lexer, string>(); | ||
var build = builder.BuildParser(new Issue485Parser(), ParserType.EBNF_LL_RECURSIVE_DESCENT,"root"); | ||
Check.That(build).IsOk(); | ||
var parser = build.Result; | ||
Check.That(parser).IsNotNull(); | ||
var parsed = parser.Parse("Property: \"Hello \\\"There\\\"\\nSecond line\""); | ||
Check.That(parsed).IsOkParsing(); | ||
var result = parsed.Result; | ||
Check.That(result).IsNotNull(); | ||
Check.That(result).IsNotEmpty(); | ||
Check.That(result).Equals("Hello \"There\"\\nSecond line"); | ||
} | ||
[Fact] | ||
public void TestIssue485SelfEscape() | ||
{ | ||
var builder = new ParserBuilder<Issue485SelfEscapeLexer, string>(); | ||
var build = builder.BuildParser(new Issue485SelfEscapeParser(), ParserType.EBNF_LL_RECURSIVE_DESCENT,"root"); | ||
Check.That(build).IsOk(); | ||
var parser = build.Result; | ||
Check.That(parser).IsNotNull(); | ||
var parsed = parser.Parse("Property: \"Hello \"\"There\"\"\\nSecond line\""); | ||
Check.That(parsed).IsOkParsing(); | ||
var result = parsed.Result; | ||
Check.That(result).IsNotNull(); | ||
Check.That(result).IsNotEmpty(); | ||
Check.That(result).Equals("Hello \"There\"\\nSecond line"); | ||
} | ||
|
||
[Fact] | ||
public void TestIssue485WithCallback() | ||
{ | ||
var builder = new ParserBuilder<Issue485WithCallbackLexer, string>(); | ||
var build = builder.BuildParser(new Issue485WithCallbackParser(), ParserType.EBNF_LL_RECURSIVE_DESCENT,"root"); | ||
Check.That(build).IsOk(); | ||
var parser = build.Result; | ||
Check.That(parser).IsNotNull(); | ||
var parsed = parser.Parse("Property: \"Hello \\\"There\\\"\\nSecond line\""); | ||
Check.That(parsed).IsOkParsing(); | ||
var result = parsed.Result; | ||
Check.That(result).IsNotNull(); | ||
Check.That(result).IsNotEmpty(); | ||
Check.That(result).Equals("Hello \"There\"\nSecond line"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using sly.lexer; | ||
|
||
namespace ParserTests.Issue485; | ||
|
||
[CallBacks(typeof(Issue485Callbacks))] | ||
public enum Issue485WithCallbackLexer | ||
{ | ||
[Sugar(":")] COLON, | ||
[Keyword("Property")] PROPERTY, | ||
[String] STRING | ||
} | ||
|
||
public class Issue485Callbacks | ||
{ | ||
|
||
[TokenCallback((int)Issue485WithCallbackLexer.STRING)] | ||
public static Token<Issue485WithCallbackLexer> EscapeEscapedSequences(Token<Issue485WithCallbackLexer> token) | ||
{ | ||
string value = token.Value; | ||
|
||
value = value.Replace("\\n", "\n"); | ||
value = value.Replace("\\r", "\r"); | ||
value = value.Replace("\\t", "\t"); | ||
value = value.Replace("\\\\", "\\"); | ||
token.SpanValue = new ReadOnlyMemory<char>(value.ToCharArray()); | ||
return token; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using sly.lexer; | ||
using sly.parser.generator; | ||
|
||
namespace ParserTests.Issue485; | ||
|
||
[ParserRoot("root")] | ||
public class Issue485WithCallbackParser | ||
{ | ||
[Production("root : PROPERTY[d] COLON[d] STRING")] | ||
public string Parse(Token<Issue485WithCallbackLexer> str) | ||
{ | ||
return str.StringWithoutQuotes; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters