Skip to content

Commit

Permalink
Updating conversion.
Browse files Browse the repository at this point in the history
  • Loading branch information
kaby76 committed Jul 27, 2023
1 parent d16ed2d commit eec2fc6
Show file tree
Hide file tree
Showing 5 changed files with 475 additions and 6 deletions.
11 changes: 8 additions & 3 deletions src/trconvert/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ public void Execute(Config config)
System.Console.WriteLine("Unhandled conversion to.");
break;
}
}
break;
}

case "ANTLRv3":
{
Expand All @@ -116,8 +116,13 @@ public void Execute(Config config)
Parser = parser
};
results.Add(tuple);
break;
}

case "Bison":
{
break;
}

case "rex":
{
Expand All @@ -131,14 +136,14 @@ public void Execute(Config config)
Parser = parser
};
results.Add(tuple);
}
break;
}

default:
{
System.Console.WriteLine("Unknown type for conversion.");
break;
}
break;
}
}

Expand Down
80 changes: 80 additions & 0 deletions src/trconvert/ConvertAntlr3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,87 @@ or text() = 'rewrite'
.Select(x => (x.NativeValue as ParseTreeEditing.UnvParseTreeDOM.UnvParseTreeElement)).ToList();
TreeEdits.Delete(optionsSpec);
}
using (var dynamicContext = ate.Try(trees, parser))
{
var nodes = engine.parseExpression(
@"//action",
new StaticContextBuilder()).evaluate(
dynamicContext, new object[] { dynamicContext.Document })
.Select(x => (x.NativeValue as ParseTreeEditing.UnvParseTreeDOM.UnvParseTreeElement)).ToList();
TreeEdits.Delete(nodes);
}

using (var dynamicContext = ate.Try(trees, parser))
{
var nodes = engine.parseExpression(
@"//ruleAction",
new StaticContextBuilder()).evaluate(
dynamicContext, new object[] { dynamicContext.Document })
.Select(x => (x.NativeValue as ParseTreeEditing.UnvParseTreeDOM.UnvParseTreeElement)).ToList();
TreeEdits.Delete(nodes);
}

using (var dynamicContext = ate.Try(trees, parser))
{
// Allow language, tokenVocab, TokenLabelType, superClass
var nodes = engine.parseExpression(
@"//actionBlock/(. | ./following-sibling::QM | ../SEMPREDOP)",
new StaticContextBuilder()).evaluate(
dynamicContext, new object[] { dynamicContext.Document })
.Select(x => (x.NativeValue as ParseTreeEditing.UnvParseTreeDOM.UnvParseTreeElement)).ToList();
TreeEdits.Delete(nodes);
}

using (var dynamicContext = ate.Try(trees, parser))
{
var nodes = engine.parseExpression(
@"//throwsSpec",
new StaticContextBuilder()).evaluate(
dynamicContext, new object[] { dynamicContext.Document })
.Select(x => (x.NativeValue as ParseTreeEditing.UnvParseTreeDOM.UnvParseTreeElement)).ToList();
TreeEdits.Delete(nodes);
}

using (var dynamicContext = ate.Try(trees, parser))
{
var nodes = engine.parseExpression(
@"//argActionBlock",
new StaticContextBuilder()).evaluate(
dynamicContext, new object[] { dynamicContext.Document })
.Select(x => (x.NativeValue as ParseTreeEditing.UnvParseTreeDOM.UnvParseTreeElement)).ToList();
TreeEdits.Delete(nodes);
}

using (var dynamicContext = ate.Try(trees, parser))
{
var nodes = engine.parseExpression(
@"//rule_/(PROTECTED | PUBLIC | PRIVATE)",
new StaticContextBuilder()).evaluate(
dynamicContext, new object[] { dynamicContext.Document })
.Select(x => (x.NativeValue as ParseTreeEditing.UnvParseTreeDOM.UnvParseTreeElement)).ToList();
TreeEdits.Delete(nodes);
}

using (var dynamicContext = ate.Try(trees, parser))
{
var nodes = engine.parseExpression(
@"//elementOption/(id_[following-sibling::EQUAL] | EQUAL[preceding-sibling::id_])",
new StaticContextBuilder()).evaluate(
dynamicContext, new object[] { dynamicContext.Document })
.Select(x => (x.NativeValue as ParseTreeEditing.UnvParseTreeDOM.UnvParseTreeElement)).ToList();
TreeEdits.Delete(nodes);
}

using (var dynamicContext = ate.Try(trees, parser))
{
var nodes = engine.parseExpression(
@"//elementNoOptionSpec/(id_[following-sibling::EQUAL] | EQUAL[preceding-sibling::id_])",
new StaticContextBuilder()).evaluate(
dynamicContext, new object[] { dynamicContext.Document })
.Select(x => (x.NativeValue as ParseTreeEditing.UnvParseTreeDOM.UnvParseTreeElement)).ToList();
TreeEdits.Delete(nodes);
}

// Fix options in the beginning of rules.
// See https://theantlrguy.atlassian.net/wiki/spaces/ANTLR3/pages/2687029/Rule+and+subrule+options
using (var dynamicContext = ate.Try(trees, parser))
Expand Down
4 changes: 2 additions & 2 deletions src/trconvert/ConvertAntlr4.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.Generic;


namespace Trash
{
using System.Collections.Generic;
using Antlr4.Runtime;
using org.eclipse.wst.xml.xpath2.processor.util;
using org.w3c.dom;
Expand Down
Loading

0 comments on commit eec2fc6

Please sign in to comment.