fix: 删除语法中关于单引号的定义 (#34)

Reviewed-on: PostGuard/Canon#34
This commit is contained in:
jackfiled 2024-04-11 22:41:43 +08:00
parent e773e666ae
commit f1c569ee0e
3 changed files with 636 additions and 588 deletions

View File

@ -109,9 +109,7 @@ public static class PascalGrammar
Terminator.NumberTerminator,
],
[
new Terminator(DelimiterType.SingleQuotation),
Terminator.CharacterTerminator,
new Terminator(DelimiterType.SingleQuotation),
]
]
},

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,6 @@
using Canon.Core.Abstractions;
using Canon.Core.Enums;
using Canon.Core.GrammarParser;
using Canon.Core.LexicalParser;
using Canon.Core.SyntaxNodes;
using Canon.Tests.GeneratedParserTests;
@ -25,4 +27,54 @@ public class PascalGrammarTests
ProgramStruct root = _parser.Analyse(tokens).Convert<ProgramStruct>();
Assert.Equal("DoNothing", root.Head.ProgramName.LiteralValue);
}
[Fact]
public void AddTest()
{
const string program = """
program Add;
var a : Integer;
begin
a := 1 + 1
end.
""";
Lexer lexer = new(program);
List<SemanticToken> tokens = lexer.Tokenize();
tokens.Add(SemanticToken.End);
ProgramStruct root = _parser.Analyse(tokens).Convert<ProgramStruct>();
Assert.Equal("Add", root.Head.ProgramName.LiteralValue);
}
[Fact]
public void WriteLnTest()
{
const string program = """
program exFunction;
const str = 'result is : ';
var a, b : Integer;
begin
writeln( str, ret );
end.
""";
Lexer lexer = new(program);
List<SemanticToken> tokens = lexer.Tokenize();
tokens.Add(SemanticToken.End);
ProgramStruct root = _parser.Analyse(tokens).Convert<ProgramStruct>();
Assert.Equal("exFunction", root.Head.ProgramName.LiteralValue);
}
private static GrammarParserBase GenerateGrammarParser()
{
GrammarBuilder builder = new()
{
Generators = PascalGrammar.Grammar, Begin = new NonTerminator(NonTerminatorType.StartNonTerminator)
};
Grammar grammar = builder.Build();
return grammar.ToGrammarParser();
}
}