Skip to content

Commit

Permalink
syntax tree graph viz improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
b3b00 committed May 29, 2024
1 parent b5b4f3c commit d504818
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 7 deletions.
21 changes: 21 additions & 0 deletions src/samples/ParserExample/ExprLexer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using sly.lexer;

namespace ParserExample;

public enum ExprLexer
{
[Double]
NUMBER,
[Sugar("+")]
PLUS,
[Sugar("-")]
MINUS,
[Sugar("*")]
TIMES,
[Sugar("/")]
DIVIDE,
[Sugar("(")]
LPAREN,
[Sugar(")")]
RPAREN,
}
58 changes: 58 additions & 0 deletions src/samples/ParserExample/ExprParser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using sly.lexer;
using sly.parser.generator;

namespace ParserExample;

[ParserRoot("root")]
public class ExprParser
{
[Production("root : ExprParser_expressions")]
public object root___WhileParser_expressions(object p0)
{
return default(object);
}

[Infix("PLUS", Associativity.Right, 10)]
public object PLUS(object left, Token<ExprLexer> oper, object right)
{
return left;
}

[Infix("MINUS", Associativity.Left, 10)]
public object MINUS(object left, Token<ExprLexer> oper, object right)
{
return left;
}

[Infix("TIMES", Associativity.Right, 50)]
public object TIMES(object left, Token<ExprLexer> oper, object right)
{
return left;
}

[Infix("DIVIDE", Associativity.Left, 50)]
public object DIVIDE(object left, Token<ExprLexer> oper, object right)
{
return left;
}

[Prefix("MINUS", Associativity.Left, 100)]
public object MINUS(Token<ExprLexer> oper, object value)
{
return value;
}

[Operand]
[Production("operand : NUMBER")]
public object operand___NUMBER(Token<ExprLexer> p0)
{
return default(object);
}

[Operand]
[Production("operand : LPAREN ExprParser_expressions RPAREN")]
public object operand___LPAREN_WhileParser_expressions_RPAREN(Token<ExprLexer> p0, object p1, Token<ExprLexer> p2)
{
return default(object);
}
}
Binary file added src/sly/nupkg/sly.3.1.5.nupkg
Binary file not shown.
Binary file added src/sly/nupkg/sly.3.1.5.snupkg
Binary file not shown.
Binary file added src/sly/nupkg/sly.3.1.6.nupkg
Binary file not shown.
Binary file added src/sly/nupkg/sly.3.1.6.snupkg
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ public DotNode VisitTree(ISyntaxNode<IN> root)
return dot;
}

private DotNode Node(string label)
private DotNode Node(string label, bool nodeIsByPassNode)
{
var shape = nodeIsByPassNode ? "ellipse" : "mrecord";
var style = nodeIsByPassNode ? "dotted" : "solid";
var node = new DotNode(NodeCounter.ToString())
{
// Set all available properties
Shape = "ellipse",
Shape = shape,
Style = style,
Label = label,
FontColor = "black",
Style = null,
Height = 0.5f
};
NodeCounter++;
Expand All @@ -57,7 +59,7 @@ public DotNode VisitNode(SyntaxNode<IN> node, IList<DotNode> children)
{
DotNode result = null;

result = Node(GetNodeLabel(node));
result = Node(GetNodeLabel(node),node.IsByPassNode);
//children.ForEach(c =>
foreach (var child in children)
{
Expand All @@ -79,7 +81,7 @@ public DotNode VisitManyNode(ManySyntaxNode<IN> node, IList<DotNode> children)
{
DotNode result = null;

result = Node(GetNodeLabel(node));
result = Node(GetNodeLabel(node),node.IsByPassNode);
Graph.Add(result);
//children.ForEach(c =>
foreach (var child in children)
Expand Down
4 changes: 2 additions & 2 deletions src/sly/sly.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
<Description>#LY is a parser generator halfway between parser combinators and parser generator like ANTLR</Description>
<Authors>b3b00</Authors>
<version>3.1.5</version>
<version>3.1.6</version>
<PackageProjectUrl>https://github.com/b3b00/sly</PackageProjectUrl>
<RepositoryUrl>https://github.com/b3b00/sly</RepositoryUrl>
<PackageVersion>3.1.5</PackageVersion>
<PackageVersion>3.1.6</PackageVersion>
<ApplicationIcon/>
<OutputType>Library</OutputType>
<StartupObject/>
Expand Down

0 comments on commit d504818

Please sign in to comment.