Initial WIP commit

This commit is contained in:
Smaug123
2024-01-22 00:21:14 +00:00
commit fdd8fb31b1
10 changed files with 395 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
<IsPublishable>false</IsPublishable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<Compile Include="TestLexer.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FsUnit" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
<PackageReference Include="NUnit" Version="4.0.1"/>
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0"/>
<PackageReference Include="coverlet.collector" Version="6.0.0"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PrattParser\PrattParser.fsproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,66 @@
namespace PrattParser.Test
open PrattParser
open NUnit.Framework
open FsUnitTyped
[<TestFixture>]
module TestLexer =
[<Test>]
let ``Lexer looks plausible`` () =
let input = "g x y + a * func (b + 100)"
let expected =
[
{
Type = TokenType.Var
Trivia = (0, 1)
}
{
Type = TokenType.Var
Trivia = (2, 1)
}
{
Type = TokenType.Var
Trivia = (4, 1)
}
{
Type = TokenType.Plus
Trivia = (6, 1)
}
{
Type = TokenType.Var
Trivia = (8, 1)
}
{
Type = TokenType.Times
Trivia = (10, 1)
}
{
Type = TokenType.Var
Trivia = (12, 4)
}
{
Type = TokenType.LeftBracket
Trivia = (17, 1)
}
{
Type = TokenType.Var
Trivia = (18, 1)
}
{
Type = TokenType.Plus
Trivia = (20, 1)
}
{
Type = TokenType.ConstInt
Trivia = (22, 3)
}
{
Type = TokenType.RightBracket
Trivia = (25, 1)
}
]
Lexer.lex input |> shouldEqual expected