Skip to content

Commit

Permalink
v 3.2.0 : syntax tree node names
Browse files Browse the repository at this point in the history
  • Loading branch information
b3b00 committed Jul 3, 2024
1 parent 0d238f8 commit 7dd0888
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/sly/parser/generator/EBNFParserBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,17 @@ protected virtual ParserConfiguration<IN, OUT> ExtractEbnfParserConfiguration(Ty
var attributes =
(ProductionAttribute[])m.GetCustomAttributes(typeof(ProductionAttribute), true);

var nodeNames = (NodeNameAttribute[])m.GetCustomAttributes(typeof(NodeNameAttribute), true);
string nodeName = nodeNames != null && nodeNames.Any() ? nodeNames[0].Name : null;

foreach (var attr in attributes)
{
var ruleString = attr.RuleString;
var parseResult = grammarParser.Parse(ruleString);
if (!parseResult.IsError)
{
var rule = (Rule<IN>)parseResult.Result;
rule.NodeName = nodeName;
rule.RuleString = ruleString;
rule.SetVisitor(m);
NonTerminal<IN> nonT = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public override SyntaxParseResult<IN> Parse(IList<Token<IN>> tokens, Rule<IN> ru
else
{
node = new SyntaxNode<IN>( nonTerminalName, children);
node.Name = rule.NodeName ?? nonTerminalName;
node.ExpressionAffix = rule.ExpressionAffix;
node = ManageExpressionRules(rule, node);
result.Root = node;
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.9</version>
<version>3.2.0</version>
<PackageProjectUrl>https://github.com/b3b00/sly</PackageProjectUrl>
<RepositoryUrl>https://github.com/b3b00/sly</RepositoryUrl>
<PackageVersion>3.1.9</PackageVersion>
<PackageVersion>3.2.0</PackageVersion>
<ApplicationIcon/>
<OutputType>Library</OutputType>
<StartupObject/>
Expand Down

0 comments on commit 7dd0888

Please sign in to comment.