Skip to content

Commit

Permalink
Merge pull request #12 from rpinchbeck/1.7.2
Browse files Browse the repository at this point in the history
Support case-insensitive prefixes on num-val and char-val
  • Loading branch information
rpinchbeck authored Jan 11, 2020
2 parents 819645a + 3a68788 commit 9b4893a
Show file tree
Hide file tree
Showing 134 changed files with 1,650 additions and 925 deletions.
850 changes: 564 additions & 286 deletions AbnfToAntlr.Common/AbnfAstLexer.cs

Large diffs are not rendered by default.

1,062 changes: 568 additions & 494 deletions AbnfToAntlr.Common/AbnfAstParser.cs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions AbnfToAntlr.Common/AbnfToAntlrTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ void OutputLiteralRules(IDictionary<char, NamedCharacter> literals, TextWriter w

if (literals.Count > 0)
{
writer.WriteLine("");
writer.WriteLine("");
writer.WriteLine(@"////////////////////////////////////////////////////////////////////////////////////////////");
writer.WriteLine(@"// Lexer rules generated for each distinct character in original grammar");
Expand Down
16 changes: 8 additions & 8 deletions AbnfToAntlr.Generator/AbnfAst.g3
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,12 @@ char_val

case_insensitive_string
:
'%i'? QUOTED_STRING -> ^(CASE_INSENSITIVE_STRING_NODE QUOTED_STRING)
('%I'|'%i')? QUOTED_STRING -> ^(CASE_INSENSITIVE_STRING_NODE QUOTED_STRING)
;

case_sensitive_string
:
('%s' QUOTED_STRING) -> ^(CASE_SENSITIVE_STRING_NODE QUOTED_STRING)
(('%S'|'%s') QUOTED_STRING) -> ^(CASE_SENSITIVE_STRING_NODE QUOTED_STRING)
| SINGLE_QUOTED_STRING -> ^(CASE_SENSITIVE_STRING_NODE SINGLE_QUOTED_STRING)
;

Expand Down Expand Up @@ -287,22 +287,22 @@ prose_val

COMMENT
:
';' ( WSP | VCHAR )* CRLF
';' ( WSP | VCHAR )* (CRLF | EOF)
;

BIN_VAL_PREFIX
:
'%b'
'%B' | '%b'
;

DEC_VAL_PREFIX
:
'%d'
'%D' | '%d'
;

HEX_VAL_PREFIX
:
'%x'
'%X' | '%x'
;

PROSE_VAL
Expand All @@ -312,12 +312,12 @@ PROSE_VAL

HEX_ALPHA
:
'A'..'F'
'A'..'F' | 'a'..'f'
;

OTHER_ALPHA
:
'G'..'Z' | 'a'..'z'
'G'..'Z' | 'g'..'z'
;

ASTERISK
Expand Down
293 changes: 276 additions & 17 deletions AbnfToAntlr.Tests/AbnfToAntlr.Tests.csproj

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions AbnfToAntlr.Tests/ExpectedReturnValueEnum.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AbnfToAntlr.Tests
{
public enum ExpectedReturnValueEnum
{
Success = 0,
SyntaxError = 1,
RecognitionError = 2
}

}
24 changes: 4 additions & 20 deletions AbnfToAntlr.Tests/FileDrivenTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,6 @@ private void PerformTranslationTest(string testName, string folderName, Translat

inputText = File.ReadAllText(inputPath);

if (inputText.EndsWith("\r\n"))
{
// do nothing
}
else
{
inputText = inputText + "\r\n";
}

if (string.IsNullOrWhiteSpace(inputText))
{
TestContext.WriteLine(inputPath);
Expand Down Expand Up @@ -114,7 +105,7 @@ private void PerformTranslationTest(string testName, string folderName, Translat
}
}

protected void PerformConsoleTest(string testName, string folderName)
protected void PerformConsoleTest(string testName, string folderName, ExpectedReturnValueEnum expectedReturnValue = ExpectedReturnValueEnum.Success)
{
var pathPrefix = Path.Combine(@"..\..\FileDrivenTests", folderName);

Expand Down Expand Up @@ -150,15 +141,6 @@ protected void PerformConsoleTest(string testName, string folderName)

var inputText = File.ReadAllText(inputPath);

if (inputText.EndsWith("\r\n"))
{
// do nothing
}
else
{
inputText = inputText + "\r\n";
}

if (string.IsNullOrWhiteSpace(inputText))
{
TestContext.WriteLine(inputPath);
Expand All @@ -174,7 +156,9 @@ protected void PerformConsoleTest(string testName, string folderName)
{
var program = new Program();

program.ConsoleMain(args, stdin, stdout, stderr);
var returnValue = program.ConsoleMain(args, stdin, stdout, stderr);

Assert.AreEqual((int)expectedReturnValue, returnValue);
}

var actualOutput = stdoutBuilder.ToString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ rule-with-three-alternatives-3 = "1" / "2"/ "3"
rule-with-three-alternatives-4 = "1" / "2"/"3"
rule-with-three-alternatives-5 = "1" /"2"/"3"
rule-with-three-alternatives-6 = "1"/ "2"/"3"
rule-with-three-alternatives-7 = "1"/"2"/"3"
rule-with-three-alternatives-7 = "1"/"2"/"3"
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ RULE_WITH_THREE_ALTERNATIVES_3 : '1' | '2'| '3';
RULE_WITH_THREE_ALTERNATIVES_4 : '1' | '2'|'3';
RULE_WITH_THREE_ALTERNATIVES_5 : '1' |'2'|'3';
RULE_WITH_THREE_ALTERNATIVES_6 : '1'| '2'|'3';
RULE_WITH_THREE_ALTERNATIVES_7 : '1'|'2'|'3';
RULE_WITH_THREE_ALTERNATIVES_7 : '1'|'2'|'3';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
rule-with-two-alternatives-1 = "1" / "2"
rule-with-two-alternatives-2 = "1" /"2"
rule-with-two-alternatives-3 = "1"/ "2"
rule-with-two-alternatives-4 = "1"/"2"
rule-with-two-alternatives-4 = "1"/"2"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
RULE_WITH_TWO_ALTERNATIVES_1 : '1' | '2';
RULE_WITH_TWO_ALTERNATIVES_2 : '1' |'2';
RULE_WITH_TWO_ALTERNATIVES_3 : '1'| '2';
RULE_WITH_TWO_ALTERNATIVES_4 : '1'|'2';
RULE_WITH_TWO_ALTERNATIVES_4 : '1'|'2';
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
case-insensitive-string-with-no-characters = %i""
case-insensitive-string-with-no-characters = %i""

case-insensitive-string-with-no-characters = %I""
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
CASE_INSENSITIVE_STRING_WITH_NO_CHARACTERS : ;

CASE_INSENSITIVE_STRING_WITH_NO_CHARACTERS : ;
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
case_insensitive_string_with_no_characters : ;

case_insensitive_string_with_no_characters : ;
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
case-insensitive-string-with-one-character = %i"A"
case-insensitive-string-with-one-character = %i"A"

case-insensitive-string-with-one-character = %I"A"
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
CASE_INSENSITIVE_STRING_WITH_ONE_CHARACTER : ('A' | 'a');

CASE_INSENSITIVE_STRING_WITH_ONE_CHARACTER : ('A' | 'a');
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
case_insensitive_string_with_one_character : (CAP_A | A);

case_insensitive_string_with_one_character : (CAP_A | A);

////////////////////////////////////////////////////////////////////////////////////////////
// Lexer rules generated for each distinct character in original grammar
// Simplified character names based on Unicode (http://www.unicode.org/charts/PDF/U0000.pdf)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
case-insensitive-string-with-one-digit = %i"1"
case-insensitive-string-with-one-digit = %i"1"

case-insensitive-string-with-one-digit = %I"1"
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
CASE_INSENSITIVE_STRING_WITH_ONE_DIGIT : '1';

CASE_INSENSITIVE_STRING_WITH_ONE_DIGIT : '1';
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
case_insensitive_string_with_one_digit : ONE;

case_insensitive_string_with_one_digit : ONE;

////////////////////////////////////////////////////////////////////////////////////////////
// Lexer rules generated for each distinct character in original grammar
// Simplified character names based on Unicode (http://www.unicode.org/charts/PDF/U0000.pdf)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
case-insensitive-string-with-two-characters = %i"Ab"
case-insensitive-string-with-two-characters = %i"Ab"

case-insensitive-string-with-two-characters = %I"Ab"
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
CASE_INSENSITIVE_STRING_WITH_TWO_CHARACTERS : (('A' | 'a') ('B' | 'b'));

CASE_INSENSITIVE_STRING_WITH_TWO_CHARACTERS : (('A' | 'a') ('B' | 'b'));
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
case_insensitive_string_with_two_characters : ((CAP_A | A) (CAP_B | B));

case_insensitive_string_with_two_characters : ((CAP_A | A) (CAP_B | B));

////////////////////////////////////////////////////////////////////////////////////////////
// Lexer rules generated for each distinct character in original grammar
// Simplified character names based on Unicode (http://www.unicode.org/charts/PDF/U0000.pdf)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
case-insensitive-string-with-two-digits = %i"12"
case-insensitive-string-with-two-digits = %i"12"

case-insensitive-string-with-two-digits = %I"12"
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
CASE_INSENSITIVE_STRING_WITH_TWO_DIGITS : ('1' '2');

CASE_INSENSITIVE_STRING_WITH_TWO_DIGITS : ('1' '2');
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
case_insensitive_string_with_two_digits : (ONE TWO);

case_insensitive_string_with_two_digits : (ONE TWO);

////////////////////////////////////////////////////////////////////////////////////////////
// Lexer rules generated for each distinct character in original grammar
// Simplified character names based on Unicode (http://www.unicode.org/charts/PDF/U0000.pdf)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
case-sensitive-string-with-no-characters = %s""
case-sensitive-string-with-no-characters = %s""

case-sensitive-string-with-no-characters = %S""
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
CASE_SENSITIVE_STRING_WITH_NO_CHARACTERS : ;

CASE_SENSITIVE_STRING_WITH_NO_CHARACTERS : ;
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
case_sensitive_string_with_no_characters : ;

case_sensitive_string_with_no_characters : ;
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
case-sensitive-string-with-one-character = %s"A"
case-sensitive-string-with-one-character = %s"A"

case-sensitive-string-with-one-character = %S"A"
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
CASE_SENSITIVE_STRING_WITH_ONE_CHARACTER : 'A';

CASE_SENSITIVE_STRING_WITH_ONE_CHARACTER : 'A';
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
case_sensitive_string_with_one_character : CAP_A;

case_sensitive_string_with_one_character : CAP_A;

////////////////////////////////////////////////////////////////////////////////////////////
// Lexer rules generated for each distinct character in original grammar
// Simplified character names based on Unicode (http://www.unicode.org/charts/PDF/U0000.pdf)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
case-sensitive-string-with-one-digit = %s"1"
case-sensitive-string-with-one-digit = %s"1"

case-sensitive-string-with-one-digit = %S"1"
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
CASE_SENSITIVE_STRING_WITH_ONE_DIGIT : '1';

CASE_SENSITIVE_STRING_WITH_ONE_DIGIT : '1';
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
case_sensitive_string_with_one_digit : ONE;

case_sensitive_string_with_one_digit : ONE;

////////////////////////////////////////////////////////////////////////////////////////////
// Lexer rules generated for each distinct character in original grammar
// Simplified character names based on Unicode (http://www.unicode.org/charts/PDF/U0000.pdf)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
case-sensitive-string-with-two-characters = %s"Ab"
case-sensitive-string-with-two-characters = %s"Ab"

case-sensitive-string-with-two-characters = %S"Ab"
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
CASE_SENSITIVE_STRING_WITH_TWO_CHARACTERS : 'Ab';

CASE_SENSITIVE_STRING_WITH_TWO_CHARACTERS : 'Ab';
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
case_sensitive_string_with_two_characters : (CAP_A B);

case_sensitive_string_with_two_characters : (CAP_A B);

////////////////////////////////////////////////////////////////////////////////////////////
// Lexer rules generated for each distinct character in original grammar
// Simplified character names based on Unicode (http://www.unicode.org/charts/PDF/U0000.pdf)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
case-sensitive-string-with-two-digits = %s"12"
case-sensitive-string-with-two-digits = %s"12"

case-sensitive-string-with-two-digits = %S"12"
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
CASE_SENSITIVE_STRING_WITH_TWO_DIGITS : '12';

CASE_SENSITIVE_STRING_WITH_TWO_DIGITS : '12';
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
case_sensitive_string_with_two_digits : (ONE TWO);

case_sensitive_string_with_two_digits : (ONE TWO);

////////////////////////////////////////////////////////////////////////////////////////////
// Lexer rules generated for each distinct character in original grammar
// Simplified character names based on Unicode (http://www.unicode.org/charts/PDF/U0000.pdf)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CHAR_VAL_WITH_NO_CHARACTERS : ;
CHAR_VAL_WITH_NO_CHARACTERS : ;
Original file line number Diff line number Diff line change
@@ -1 +1 @@
char_val_with_no_characters : ;
char_val_with_no_characters : ;
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CHAR_VAL_WITH_ONE_CHARACTER : ('A' | 'a');
CHAR_VAL_WITH_ONE_CHARACTER : ('A' | 'a');
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CHAR_VAL_WITH_ONE_DIGIT : '1';
CHAR_VAL_WITH_ONE_DIGIT : '1';
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CHAR_VAL_WITH_TWO_CHARACTERS : (('A' | 'a') ('B' | 'b'));
CHAR_VAL_WITH_TWO_CHARACTERS : (('A' | 'a') ('B' | 'b'));
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CHAR_VAL_WITH_TWO_DIGITS : ('1' '2');
CHAR_VAL_WITH_TWO_DIGITS : ('1' '2');
Original file line number Diff line number Diff line change
@@ -1 +1 @@
concatenation_and_alternation_without_grouping : (concatenation1 concatenation2) | (concatenation3 concatenation4);
concatenation_and_alternation_without_grouping : (concatenation1 concatenation2) | (concatenation3 concatenation4);
Original file line number Diff line number Diff line change
@@ -1 +1 @@
concatenation_and_alternation_without_grouping : (concatenation1 concatenation2) | (concatenation3 concatenation4);
concatenation_and_alternation_without_grouping : (concatenation1 concatenation2) | (concatenation3 concatenation4);
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CONCATENATION_WITH_ONE_REPETITION : '1';
CONCATENATION_WITH_ONE_REPETITION : '1';
Original file line number Diff line number Diff line change
@@ -1 +1 @@
concatenation-with-two-repetitions = "1" "2"
concatenation-with-two-repetitions = "1" "2"
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CONCATENATION_WITH_TWO_REPETITIONS : '1' '2';
CONCATENATION_WITH_TWO_REPETITIONS : '1' '2';
Loading

0 comments on commit 9b4893a

Please sign in to comment.