envlang-csharp/MixFixGenerator.cs
2020-08-23 03:54:12 +00:00

48 lines
1.6 KiB
C#

using static Generator;
public static class ParserGenerator {
public static void Main() {
Generate(
"MixFixGenerated.cs",
"using System.Collections.Immutable;\n"
+ "using S = Lexer.S;\n"
+ "using PrecedenceGroupName = System.String;",
"public static partial class MixFix {",
"}",
"MixFix.",
Types(
Variant("Grammar",
Case("ImmutableList<Grammar>", "Or"),
Case("ImmutableList<Grammar>", "Sequence")),
Variant("Fixity",
Case("Closed"),
Case("InfixLeftAssociative"),
Case("InfixRightAssociative"),
Case("InfixNonAssociative"),
Case("Prefix"),
Case("Postfix")),
Variant("Associativity",
Case("NonAssociative"),
Case("LeftAssociative"),
Case("RightAssociative")),
Record("Operator",
Field("PrecedenceGroupName", "precedenceGroup"),
Field("Associativity", "associativity"),
Field("ImmutableList<Part>", "parts")),
Variant("Part",
Case("S", "Name"),
Case("ImmutableHashSet<PrecedenceGroupName>", "Hole")),
Record("DAGNode",
Field("ImmutableList<Operator>", "infixLeftAssociative"),
Field("ImmutableList<Operator>", "infixRightAssociative"),
Field("ImmutableList<Operator>", "infixNonAssociative"),
Field("ImmutableList<Operator>", "prefix"),
Field("ImmutableList<Operator>", "postfix"),
Field("ImmutableList<Operator>", "closed"))));
}
}