diff --git a/_scripts/publish.sh b/_scripts/publish.sh
index 6eee3727e..35e1cab14 100644
--- a/_scripts/publish.sh
+++ b/_scripts/publish.sh
@@ -1,5 +1,5 @@
#!/usr/bin/bash
-version=0.23.4
+version=0.23.5
cd src
exes=`find . -name 'tr*.exe' | grep -v publish`
for i in $exes
diff --git a/_scripts/set-version.sh b/_scripts/set-version.sh
index de6959909..f9bc898ec 100644
--- a/_scripts/set-version.sh
+++ b/_scripts/set-version.sh
@@ -1,5 +1,5 @@
#!/usr/bin/bash
-version="0.23.4"
+version="0.23.5"
cd src
directories=`find . -maxdepth 1 -type d -name "tr*"`
cwd=`pwd`
@@ -41,7 +41,7 @@ do
mv asdfasdf *.csproj
rm -f asdfasdf2
touch readme.md
- cat readme.md | sed -e 's%^0[.][0-9]*[.][0-9]*.*$'"%$version"' Add scripts for syntactic highlighting as default for trgenvsc.%' > asdfasdf2
+ cat readme.md | sed -e 's%^0[.][0-9]*[.][0-9]*.*$'"%$version"' Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.%' > asdfasdf2
mv asdfasdf2 readme.md
cd ..
done
@@ -78,7 +78,7 @@ do
mv asdfasdf *.csproj
rm -f asdfasdf2
touch readme.md
- cat readme.md | sed -e 's%^0[.][0-9]*[.][0-9]*.*$'"%$version"' Add scripts for syntactic highlighting as default for trgenvsc.%' > asdfasdf2
+ cat readme.md | sed -e 's%^0[.][0-9]*[.][0-9]*.*$'"%$version"' Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.%' > asdfasdf2
mv asdfasdf2 readme.md
cd ..
done
diff --git a/_tests/basic-trees/Gold/trparse.tree b/_tests/basic-trees/Gold/trparse.tree
index ad9048eaf..c9f6b9414 100644
--- a/_tests/basic-trees/Gold/trparse.tree
+++ b/_tests/basic-trees/Gold/trparse.tree
@@ -1,4 +1,3 @@
-
( s
( e
( e
@@ -8,7 +7,7 @@
) ) )
( Attribute Skip Value ' '
)
- (
+ ( T__3
( text:'+' tt:0 chnl:DEFAULT_TOKEN_CHANNEL
) )
( e
@@ -19,7 +18,7 @@
) ) ) )
( Attribute Skip Value ' '
)
- (
+ ( T__3
( text:'+' tt:0 chnl:DEFAULT_TOKEN_CHANNEL
) )
( e
@@ -35,3 +34,4 @@
) ) )
+
diff --git a/_tests/basic-trees/trparse.tree b/_tests/basic-trees/trparse.tree
index ad9048eaf..c9f6b9414 100644
--- a/_tests/basic-trees/trparse.tree
+++ b/_tests/basic-trees/trparse.tree
@@ -1,4 +1,3 @@
-
( s
( e
( e
@@ -8,7 +7,7 @@
) ) )
( Attribute Skip Value ' '
)
- (
+ ( T__3
( text:'+' tt:0 chnl:DEFAULT_TOKEN_CHANNEL
) )
( e
@@ -19,7 +18,7 @@
) ) ) )
( Attribute Skip Value ' '
)
- (
+ ( T__3
( text:'+' tt:0 chnl:DEFAULT_TOKEN_CHANNEL
) )
( e
@@ -35,3 +34,4 @@
) ) )
+
diff --git a/_tests/delete/Gold/delete.tree b/_tests/delete/Gold/delete.tree
index 6d2442660..5d6ecf580 100644
--- a/_tests/delete/Gold/delete.tree
+++ b/_tests/delete/Gold/delete.tree
@@ -1,4 +1,3 @@
-
( grammarSpec
( grammarDecl
( grammarType
@@ -512,3 +511,4 @@
) ) )
+
diff --git a/_tests/xgrep/Gold/output b/_tests/xgrep/Gold/output
index 8b1378917..48521d990 100644
--- a/_tests/xgrep/Gold/output
+++ b/_tests/xgrep/Gold/output
@@ -1 +1,14 @@
+( INT
+ ( text:'1' tt:0 chnl:DEFAULT_TOKEN_CHANNEL
+) )
+
+( INT
+ ( text:'2' tt:0 chnl:DEFAULT_TOKEN_CHANNEL
+) )
+
+( INT
+ ( text:'3' tt:0 chnl:DEFAULT_TOKEN_CHANNEL
+) )
+
+
diff --git a/_tests/xgrep/output b/_tests/xgrep/output
index 8b1378917..48521d990 100644
--- a/_tests/xgrep/output
+++ b/_tests/xgrep/output
@@ -1 +1,14 @@
+( INT
+ ( text:'1' tt:0 chnl:DEFAULT_TOKEN_CHANNEL
+) )
+
+( INT
+ ( text:'2' tt:0 chnl:DEFAULT_TOKEN_CHANNEL
+) )
+
+( INT
+ ( text:'3' tt:0 chnl:DEFAULT_TOKEN_CHANNEL
+) )
+
+
diff --git a/_tests/xgrep/test.sh b/_tests/xgrep/test.sh
index 3c68e9ca0..1547d1565 100644
--- a/_tests/xgrep/test.sh
+++ b/_tests/xgrep/test.sh
@@ -13,9 +13,9 @@ rm -rf Generated-CSharp
trgen -t CSharp
cd Generated-CSharp
make
-echo "1 + 2 + 3" | trparse | trquery grep ' //SCIENTIFIC_NUMBER' | trtree > ../output
+echo "1 + 2 + 3" | trparse | trquery grep ' //INT' | trtree > ../output
cd ..
-rm -rf Generated-CSharp
+#rm -rf Generated-CSharp
# Diff result.
for i in output Gold/output
diff --git a/src/ParseTreeEditing/UnvParseTreeDOM/ConvertToDOM.cs b/src/ParseTreeEditing/UnvParseTreeDOM/ConvertToDOM.cs
index 50bf27113..e2580b86a 100644
--- a/src/ParseTreeEditing/UnvParseTreeDOM/ConvertToDOM.cs
+++ b/src/ParseTreeEditing/UnvParseTreeDOM/ConvertToDOM.cs
@@ -56,6 +56,18 @@ public UnvParseTreeElement BottomUpConvert(IParseTree tree, UnvParseTreeElement
Interval interval = t.SourceInterval;
new_node.NodeType = NodeConstants.ELEMENT_NODE;
var fixed_name = parser.Vocabulary.GetSymbolicName(t.Symbol.Type);
+ if (fixed_name == null)
+ {
+ try
+ {
+ var xxxxx = lexer.RuleNames[t.Symbol.Type];
+ fixed_name = xxxxx;
+ }
+ catch (System.Exception)
+ {
+ fixed_name = "Unknown";
+ }
+ }
new_node.LocalName = fixed_name;
var nl = new UnvParseTreeNodeList();
new_node.ChildNodes = nl;
diff --git a/src/ParseTreeEditing/UnvParseTreeDOM/TreeOutput.cs b/src/ParseTreeEditing/UnvParseTreeDOM/TreeOutput.cs
index b9d648ec8..f8f8a87c2 100644
--- a/src/ParseTreeEditing/UnvParseTreeDOM/TreeOutput.cs
+++ b/src/ParseTreeEditing/UnvParseTreeDOM/TreeOutput.cs
@@ -3,120 +3,227 @@
using System.IO;
using System.Text;
-namespace ParseTreeEditing.UnvParseTreeDOM
+namespace ParseTreeEditing.UnvParseTreeDOM;
+
+public class TreeOutput
{
- public class TreeOutput
+ private int changed = 0;
+ private bool first_time = true;
+ private StringBuilder sb;
+ private Lexer lexer;
+ private Parser parser;
+ private string prefix;
+
+ public TreeOutput(Lexer lexer, Parser parser, string prefix = "")
{
- private static int changed = 0;
- private static bool first_time = true;
+ changed = 0;
+ first_time = true;
+ sb = new StringBuilder();
+ this.lexer = lexer;
+ this.parser = parser;
+ this.prefix = prefix;
+ }
- public static StringBuilder OutputTree(UnvParseTreeNode tree, Lexer lexer, Parser parser)
+ public StringBuilder OutputTree(UnvParseTreeNode tree)
+ {
+ ParenthesizedAST(tree);
+ return sb;
+ }
+
+ private void ParenthesizedAST(UnvParseTreeNode tree, int level = 0)
+ {
+ // Antlr always names a non-terminal with first letter lowercase,
+ // but renames it when creating the type in C#. So, remove the prefix,
+ // lowercase the first letter, and remove the trailing "Context" part of
+ // the name. Saves big time on output!
+ if (tree is UnvParseTreeText t)
{
- changed = 0;
- first_time = true;
- var sb = new StringBuilder();
- ParenthesizedAST(tree, sb, lexer, parser);
- return sb;
+ StartLine(level);
+ sb.Append(
+ "( "
+ + " text:'" + PerformEscapes(t.Data) + "'"
+ + " tt:" + t.TokenType
+ + " chnl:" + lexer.ChannelNames[t.Channel]
+ //+ " l:" + t.Line
+ //+ " c:" + t.Column
+ //+ " si:" + t.StartIndex
+ //+ " ei:" + t.StopIndex
+ //+ " ti:" + t.TokenIndex
+ );
+ sb.AppendLine();
}
-
- private static void ParenthesizedAST(UnvParseTreeNode tree, StringBuilder sb, Lexer lexer, Parser parser, int level = 0)
+ else if (tree is UnvParseTreeAttr a)
{
- // Antlr always names a non-terminal with first letter lowercase,
- // but renames it when creating the type in C#. So, remove the prefix,
- // lowercase the first letter, and remove the trailing "Context" part of
- // the name. Saves big time on output!
- if (tree is UnvParseTreeText t)
- {
- StartLine(sb, level);
- sb.Append(
- "( "
- + " text:'" + PerformEscapes(t.Data) + "'"
- + " tt:" + t.TokenType
- + " chnl:" + lexer.ChannelNames[t.Channel]
- //+ " l:" + t.Line
- //+ " c:" + t.Column
- //+ " si:" + t.StartIndex
- //+ " ei:" + t.StopIndex
- //+ " ti:" + t.TokenIndex
- );
- sb.AppendLine();
- }
- else if (tree is UnvParseTreeAttr a)
- {
- StartLine(sb, level);
- sb.Append("( Attribute " + a.Name as string);
- sb.Append(" Value '");
- sb.Append(PerformEscapes(a.StringValue));
- sb.Append("'");
- if (a.Channel >= 0 && a.Channel < lexer.ChannelNames.Length)
- {
- sb.Append(" chnl:");
- sb.Append(lexer.ChannelNames[a.Channel].ToString());
- }
- sb.AppendLine();
- }
- else if (tree is UnvParseTreeElement e)
- {
- var x = e;
- var name = e.LocalName;
- StartLine(sb, level);
- sb.Append(
- "( " + name
- );
- sb.AppendLine();
- }
- for (int i = 0; tree.ChildNodes != null && i < tree.ChildNodes.Length; ++i)
+ StartLine(level);
+ sb.Append("( Attribute " + a.Name as string);
+ sb.Append(" Value '");
+ sb.Append(PerformEscapes(a.StringValue));
+ sb.Append("'");
+ if (a.Channel >= 0 && a.Channel < lexer.ChannelNames.Length)
{
- var c = tree.ChildNodes.item(i);
- ParenthesizedAST(c as UnvParseTreeNode, sb, lexer, parser, level + 1);
+ sb.Append(" chnl:");
+ sb.Append(lexer.ChannelNames[a.Channel].ToString());
}
- if (level == 0)
+ sb.AppendLine();
+ }
+ else if (tree is UnvParseTreeElement e)
+ {
+ var x = e;
+ var name = e.LocalName;
+ StartLine(level);
+ sb.Append(
+ "( " + name
+ );
+ sb.AppendLine();
+ }
+ for (int i = 0; tree.ChildNodes != null && i < tree.ChildNodes.Length; ++i)
+ {
+ var c = tree.ChildNodes.item(i);
+ ParenthesizedAST(c as UnvParseTreeNode, level + 1);
+ }
+ if (level == 0)
+ {
+ for (int k = 0; k < 1 + changed - level; ++k) sb.Append(") ");
+ sb.AppendLine();
+ changed = 0;
+ }
+ }
+
+ private void StartLine(int level = 0)
+ {
+ if (changed - level >= 0)
+ {
+ if (!first_time)
{
+ sb.Append(prefix);
+ for (int j = 0; j < level; ++j) sb.Append(" ");
for (int k = 0; k < 1 + changed - level; ++k) sb.Append(") ");
sb.AppendLine();
- changed = 0;
}
+ changed = 0;
+ first_time = false;
}
+ changed = level;
+ sb.Append(prefix);
+ for (int j = 0; j < level; ++j) sb.Append(" ");
+ }
- private static void StartLine(StringBuilder sb, int level = 0)
+ private static string ToLiteral(string input)
+ {
+ using (var writer = new StringWriter())
{
- if (changed - level >= 0)
- {
- if (!first_time)
- {
- for (int j = 0; j < level; ++j) sb.Append(" ");
- for (int k = 0; k < 1 + changed - level; ++k) sb.Append(") ");
- sb.AppendLine();
- }
- changed = 0;
- first_time = false;
- }
- changed = level;
- for (int j = 0; j < level; ++j) sb.Append(" ");
+ var literal = input;
+ literal = literal.Replace("\\", "\\\\");
+ literal = literal.Replace("\b", "\\b");
+ literal = literal.Replace("\n", "\\n");
+ literal = literal.Replace("\t", "\\t");
+ literal = literal.Replace("\r", "\\r");
+ literal = literal.Replace("\f", "\\f");
+ literal = literal.Replace("\"", "\\\"");
+ literal = literal.Replace(string.Format("\" +{0}\t\"", Environment.NewLine), "");
+ return literal;
}
+ }
- private static string ToLiteral(string input)
+ public static string PerformEscapes(string s)
+ {
+ StringBuilder new_s = new StringBuilder();
+ new_s.Append(ToLiteral(s));
+ return new_s.ToString();
+ }
+
+ public StringBuilder OutputTreeAntlrStyle(UnvParseTreeNode tree)
+ {
+ sb.Append(prefix);
+ AntlrParenthesizedAST(tree);
+ return sb;
+ }
+
+ private void AntlrParenthesizedAST(UnvParseTreeNode tree, int level = 0)
+ {
+ if (tree is UnvParseTreeText t)
+ {
+ sb.Append((!first_time ? " " : "") + "\"" + PerformEscapes(t.Data) + "\"");
+ first_time = false;
+ return;
+ }
+ else if (tree is UnvParseTreeAttr a)
+ {
+ return;
+ }
+ else if (tree is UnvParseTreeElement e)
+ {
+ var x = e;
+ var name = e.LocalName;
+ sb.Append((!first_time ? " " : "") + "(" + name);
+ first_time = false;
+ }
+ for (int i = 0; tree.ChildNodes != null && i < tree.ChildNodes.Length; ++i)
{
- using (var writer = new StringWriter())
+ var c = tree.ChildNodes.item(i);
+ AntlrParenthesizedAST(c as UnvParseTreeNode, level + 1);
+ }
+ sb.Append(")");
+ }
+
+ public StringBuilder OutputTreeIndentStyle(UnvParseTreeNode tree)
+ {
+ IndentAST(tree);
+ return sb;
+ }
+
+ public void IndentAST(UnvParseTreeNode tree, int level = 0)
+ {
+ if (tree is UnvParseTreeText t)
+ {
+ IndentStartLine(level);
+ sb.Append("\"" + PerformEscapes(t.Data) + "\"");
+ sb.AppendLine();
+ }
+ else if (tree is UnvParseTreeAttr a)
+ {
+ IndentStartLine(level);
+ sb.Append("Attribute " + a.Name as string);
+ sb.Append(" Value '");
+ sb.Append(PerformEscapes(a.StringValue));
+ sb.Append("'");
+ if (a.Channel >= 0 && a.Channel < lexer.ChannelNames.Length)
{
- var literal = input;
- literal = literal.Replace("\\", "\\\\");
- literal = literal.Replace("\b", "\\b");
- literal = literal.Replace("\n", "\\n");
- literal = literal.Replace("\t", "\\t");
- literal = literal.Replace("\r", "\\r");
- literal = literal.Replace("\f", "\\f");
- literal = literal.Replace("\"", "\\\"");
- literal = literal.Replace(string.Format("\" +{0}\t\"", Environment.NewLine), "");
- return literal;
+ sb.Append(" chnl:");
+ sb.Append(lexer.ChannelNames[a.Channel].ToString());
}
+ sb.AppendLine();
+ }
+ else if (tree is UnvParseTreeElement e)
+ {
+ var x = e;
+ var name = e.LocalName;
+ IndentStartLine(level);
+ sb.Append(name);
+ sb.AppendLine();
}
+ for (int i = 0; tree.ChildNodes != null && i < tree.ChildNodes.Length; ++i)
+ {
+ var c = tree.ChildNodes.item(i);
+ IndentAST(c as UnvParseTreeNode, level + 1);
+ }
+ if (level == 0)
+ {
+// sb.AppendLine();
+ changed = 0;
+ }
+ }
- public static string PerformEscapes(string s)
+ private void IndentStartLine(int level = 0)
+ {
+ if (changed - level >= 0)
{
- StringBuilder new_s = new StringBuilder();
- new_s.Append(ToLiteral(s));
- return new_s.ToString();
+ changed = 0;
+ first_time = false;
}
+ changed = level;
+ sb.Append(prefix);
+ for (int j = 0; j < level; ++j) sb.Append(" ");
}
+
}
diff --git a/src/tragl/readme.md b/src/tragl/readme.md
index 809fd3a46..d0dc46272 100644
--- a/src/tragl/readme.md
+++ b/src/tragl/readme.md
@@ -19,7 +19,7 @@ This tool is part of Trash, Transformations for Antlr Shell.
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/tragl/tragl.csproj b/src/tragl/tragl.csproj
index 5f699638c..1ecacdc4a 100644
--- a/src/tragl/tragl.csproj
+++ b/src/tragl/tragl.csproj
@@ -19,7 +19,7 @@ This program is part of the Trash toolkit.]]>
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/tragl
git
diff --git a/src/tranalyze/Command.cs b/src/tranalyze/Command.cs
index eee116ce2..615cac5a4 100644
--- a/src/tranalyze/Command.cs
+++ b/src/tranalyze/Command.cs
@@ -65,7 +65,7 @@ public void Execute(Config config)
if (config.Verbose)
{
foreach (var n in trees)
- System.Console.WriteLine(TreeOutput.OutputTree(n, lexer, parser).ToString());
+ System.Console.WriteLine(new TreeOutput(lexer, parser).OutputTree(n).ToString());
}
AnalyzeDoc(trees);
}
diff --git a/src/tranalyze/readme.md b/src/tranalyze/readme.md
index c2b0394bc..caf6e7318 100644
--- a/src/tranalyze/readme.md
+++ b/src/tranalyze/readme.md
@@ -65,7 +65,7 @@ _Output_
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/tranalyze/tranalyze.csproj b/src/tranalyze/tranalyze.csproj
index b7d90ecf0..7231a6a54 100644
--- a/src/tranalyze/tranalyze.csproj
+++ b/src/tranalyze/tranalyze.csproj
@@ -17,7 +17,7 @@ This program is part of the Trash toolkit.]]>
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/tranalyze
git
diff --git a/src/trcaret/readme.md b/src/trcaret/readme.md
index fc60269f6..94b3e2aa3 100644
--- a/src/trcaret/readme.md
+++ b/src/trcaret/readme.md
@@ -18,7 +18,7 @@ Reads a tree from stdin and prints lines and caret marks.
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trcaret/trcaret.csproj b/src/trcaret/trcaret.csproj
index 80b82f034..f8131119a 100644
--- a/src/trcaret/trcaret.csproj
+++ b/src/trcaret/trcaret.csproj
@@ -19,7 +19,7 @@ This program is part of the Trash toolkit.
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trcaret
git
diff --git a/src/trclonereplace/Command.cs b/src/trclonereplace/Command.cs
index 6cbf3f3e9..ed6c76cc6 100644
--- a/src/trclonereplace/Command.cs
+++ b/src/trclonereplace/Command.cs
@@ -72,7 +72,7 @@ public void Execute(Config config)
if (config.Verbose)
{
foreach (var n in trees)
- System.Console.WriteLine(TreeOutput.OutputTree(n, lexer, parser).ToString());
+ System.Console.WriteLine(new TreeOutput(lexer, parser).OutputTree(n).ToString());
}
/* Step 1: Find all parser symbols on the right hand side that match,
diff --git a/src/trclonereplace/readme.md b/src/trclonereplace/readme.md
index b24fa3eba..bb9983429 100644
--- a/src/trclonereplace/readme.md
+++ b/src/trclonereplace/readme.md
@@ -19,7 +19,7 @@ Clone, rename, and replace symbols in a grammar to optimize full stack fallbacks
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trclonereplace/trclonereplace.csproj b/src/trclonereplace/trclonereplace.csproj
index 0a4aecf8e..dbde957bd 100644
--- a/src/trclonereplace/trclonereplace.csproj
+++ b/src/trclonereplace/trclonereplace.csproj
@@ -17,7 +17,7 @@ This program is part of the Trash toolkit.]]>
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trclonereplace
git
diff --git a/src/trcombine/readme.md b/src/trcombine/readme.md
index b8f5a3ce4..8f2a2478f 100644
--- a/src/trcombine/readme.md
+++ b/src/trcombine/readme.md
@@ -103,7 +103,7 @@ The original grammars are left unchanged.
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trcombine/trcombine.csproj b/src/trcombine/trcombine.csproj
index 98c3ee05c..7850535c3 100644
--- a/src/trcombine/trcombine.csproj
+++ b/src/trcombine/trcombine.csproj
@@ -17,7 +17,7 @@ This program is part of the Trash toolkit.]]>
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trcombine
git
diff --git a/src/trconvert/Command.cs b/src/trconvert/Command.cs
index 607fc349c..1665b4452 100644
--- a/src/trconvert/Command.cs
+++ b/src/trconvert/Command.cs
@@ -57,7 +57,7 @@ public void Execute(Config config)
if (config.Verbose)
{
foreach (var n in trees)
- System.Console.WriteLine(TreeOutput.OutputTree(n, lexer, parser).ToString());
+ System.Console.WriteLine(new TreeOutput(lexer, parser).OutputTree(n).ToString());
}
var ty = new Regex("Parser$").Replace(Path.GetFileNameWithoutExtension(parser.GrammarFileName), "");
switch (ty)
diff --git a/src/trconvert/readme.md b/src/trconvert/readme.md
index 11ad87550..ca455fc8e 100644
--- a/src/trconvert/readme.md
+++ b/src/trconvert/readme.md
@@ -93,7 +93,7 @@ _Output_
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trconvert/trconvert.csproj b/src/trconvert/trconvert.csproj
index 77359e0b5..35f7db659 100644
--- a/src/trconvert/trconvert.csproj
+++ b/src/trconvert/trconvert.csproj
@@ -18,7 +18,7 @@ syntax. This program is part of the Trash toolkit.]]>
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trconvert
git
diff --git a/src/trcover/readme.md b/src/trcover/readme.md
index f38e42ba3..7215234a3 100644
--- a/src/trcover/readme.md
+++ b/src/trcover/readme.md
@@ -24,7 +24,7 @@ a grammar.
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trcover/trcover.csproj b/src/trcover/trcover.csproj
index 8efe6e5eb..3d065de14 100644
--- a/src/trcover/trcover.csproj
+++ b/src/trcover/trcover.csproj
@@ -18,7 +18,7 @@ for the entire grammar. This program is part of the Trash toolkit.]]>
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trcover
git
diff --git a/src/trdot/readme.md b/src/trdot/readme.md
index 5bb2d679b..d72bae479 100644
--- a/src/trdot/readme.md
+++ b/src/trdot/readme.md
@@ -63,7 +63,7 @@ The output will be:
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trdot/trdot.csproj b/src/trdot/trdot.csproj
index 62495686c..b7cea4189 100644
--- a/src/trdot/trdot.csproj
+++ b/src/trdot/trdot.csproj
@@ -18,7 +18,7 @@ This program is part of the Trash toolkit.
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trdot
git
diff --git a/src/trenum/readme.md b/src/trenum/readme.md
index b932eeb39..6a722b2fb 100644
--- a/src/trenum/readme.md
+++ b/src/trenum/readme.md
@@ -8,7 +8,7 @@
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trenum/trenum.csproj b/src/trenum/trenum.csproj
index 9478c2533..ba14bb9ee 100644
--- a/src/trenum/trenum.csproj
+++ b/src/trenum/trenum.csproj
@@ -18,7 +18,7 @@ This program is part of the Trash toolkit.
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trull
git
diff --git a/src/trfirst/readme.md b/src/trfirst/readme.md
index 3d8e88d9a..fb760c404 100644
--- a/src/trfirst/readme.md
+++ b/src/trfirst/readme.md
@@ -24,7 +24,7 @@ XPaths, type _export MSYS2_ARG_CONV_EXCL="*"_, then execute your command.
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trfirst/trfirst.csproj b/src/trfirst/trfirst.csproj
index 0029c916f..cea5a02b6 100644
--- a/src/trfirst/trfirst.csproj
+++ b/src/trfirst/trfirst.csproj
@@ -17,7 +17,7 @@ This program is part of the Trash toolkit.]]>
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trfirst
git
diff --git a/src/trfold/readme.md b/src/trfold/readme.md
index 11a265b94..0aa4dc26b 100644
--- a/src/trfold/readme.md
+++ b/src/trfold/readme.md
@@ -26,7 +26,7 @@ XPaths, type _export MSYS2_ARG_CONV_EXCL="*"_, then execute your command.
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trfold/trfold.csproj b/src/trfold/trfold.csproj
index 3db2efd70..d4e7bf827 100644
--- a/src/trfold/trfold.csproj
+++ b/src/trfold/trfold.csproj
@@ -17,7 +17,7 @@ This program is part of the Trash toolkit.]]>
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trfold
git
diff --git a/src/trfoldlit/readme.md b/src/trfoldlit/readme.md
index 4512105b8..20e41fa42 100644
--- a/src/trfoldlit/readme.md
+++ b/src/trfoldlit/readme.md
@@ -65,7 +65,7 @@ XPaths, type _export MSYS2_ARG_CONV_EXCL="*"_, then execute your command.
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trfoldlit/trfoldlit.csproj b/src/trfoldlit/trfoldlit.csproj
index 6a489bcfb..56de5fc51 100644
--- a/src/trfoldlit/trfoldlit.csproj
+++ b/src/trfoldlit/trfoldlit.csproj
@@ -17,7 +17,7 @@ This program is part of the Trash toolkit.]]>
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trfoldlit
git
diff --git a/src/trformat/readme.md b/src/trformat/readme.md
index d603822eb..9c6b69f03 100644
--- a/src/trformat/readme.md
+++ b/src/trformat/readme.md
@@ -18,7 +18,7 @@ Format of grammar using machine learning.
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trformat/trformat.csproj b/src/trformat/trformat.csproj
index 21d57a16e..e75840adb 100644
--- a/src/trformat/trformat.csproj
+++ b/src/trformat/trformat.csproj
@@ -17,7 +17,7 @@ This program is part of the Trash toolkit.]]>
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trformat
git
diff --git a/src/trgen/Command.cs b/src/trgen/Command.cs
index 322d64acd..b4100dfd0 100644
--- a/src/trgen/Command.cs
+++ b/src/trgen/Command.cs
@@ -541,7 +541,7 @@ private void ModifyWithGrammarParse(Config config)
}
}
- public static string version = "0.23.4";
+ public static string version = "0.23.5";
// For maven-generated code.
public List failed_modules = new List();
diff --git a/src/trgen/readme.md b/src/trgen/readme.md
index b3a0a7ebd..98b8c70fe 100644
--- a/src/trgen/readme.md
+++ b/src/trgen/readme.md
@@ -49,7 +49,7 @@ simplify and eliminate bugs created when adding new grammars.
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trgen/templates/CSharp/MyParserInterpreter.cs b/src/trgen/templates/CSharp/MyParserInterpreter.cs
new file mode 100644
index 000000000..79ed6fa41
--- /dev/null
+++ b/src/trgen/templates/CSharp/MyParserInterpreter.cs
@@ -0,0 +1,449 @@
+/* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
+ */
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Antlr4.Runtime;
+using Antlr4.Runtime.Atn;
+using Antlr4.Runtime.Dfa;
+using Antlr4.Runtime.Misc;
+using Antlr4.Runtime.Sharpen;
+
+///
+/// A parser simulator that mimics what ANTLR's generated
+/// parser code does.
+///
+///
+/// A parser simulator that mimics what ANTLR's generated
+/// parser code does. A ParserATNSimulator is used to make
+/// predictions via adaptivePredict but this class moves a pointer through the
+/// ATN to simulate parsing. ParserATNSimulator just
+/// makes us efficient rather than having to backtrack, for example.
+/// This properly creates parse trees even for left recursive rules.
+/// We rely on the left recursive rule invocation and special predicate
+/// transitions to make left recursive rules work.
+/// See TestParserInterpreter for examples.
+///
+public class MyParserInterpreter : Parser
+{
+ private readonly string _grammarFileName;
+
+ private readonly ATN _atn;
+
+ private readonly DFA[] _decisionToDFA;
+
+ protected internal readonly BitSet pushRecursionContextStates;
+
+ private readonly string[] _ruleNames;
+
+ [NotNull]
+ private readonly IVocabulary vocabulary;
+
+ private Stack> _parentContextStack = new Stack>();
+
+ /** We need a map from (decision,inputIndex)->forced alt for computing ambiguous
+ * parse trees. For now, we allow exactly one override.
+ */
+ protected int overrideDecision = -1;
+ protected int overrideDecisionInputIndex = -1;
+ protected int overrideDecisionAlt = -1;
+ protected bool overrideDecisionReached = false; // latch and only override once; error might trigger infinite loop
+
+ /** What is the current context when we override a decisions? This tells
+ * us what the root of the parse tree is when using override
+ * for an ambiguity/lookahead check.
+ */
+ protected InterpreterRuleContext overrideDecisionRoot = null;
+ protected InterpreterRuleContext rootContext;
+
+ public MyParserInterpreter(IVocabulary vocabulary, IEnumerable ruleNames, ATN atn, ITokenStream input)
+ : base(input)
+ {
+ this._atn = atn;
+ this._ruleNames = ruleNames.ToArray();
+ this.vocabulary = vocabulary;
+ // identify the ATN states where pushNewRecursionContext must be called
+ this.pushRecursionContextStates = new BitSet(atn.states.Count);
+ foreach (ATNState state in atn.states)
+ {
+ if (!(state is StarLoopEntryState))
+ {
+ continue;
+ }
+ if (((StarLoopEntryState)state).isPrecedenceDecision)
+ {
+ this.pushRecursionContextStates.Set(state.stateNumber);
+ }
+ }
+
+ //init decision DFA
+ int numberofDecisions = atn.NumberOfDecisions;
+ this._decisionToDFA = new DFA[numberofDecisions];
+ for (int i = 0; i < numberofDecisions; i++)
+ {
+ DecisionState decisionState = atn.GetDecisionState(i);
+ _decisionToDFA[i] = new DFA(decisionState, i);
+ }
+ // get atn simulator that knows how to do predictions
+ Interpreter = new ParserATNSimulator(this, atn, _decisionToDFA, null);
+ }
+
+ public override void Reset() {
+ base.Reset();
+ overrideDecisionReached = false;
+ overrideDecisionRoot = null;
+ overrideDecision = -1;
+ overrideDecisionInputIndex = -1;
+ overrideDecisionAlt = -1;
+ _parentContextStack = new Stack>();
+ overrideDecisionRoot = null;
+ rootContext = null;
+ }
+
+ public override ATN Atn
+ {
+ get
+ {
+ return _atn;
+ }
+ }
+
+ public override IVocabulary Vocabulary
+ {
+ get
+ {
+ return vocabulary;
+ }
+ }
+
+ public override string[] RuleNames
+ {
+ get
+ {
+ return _ruleNames;
+ }
+ }
+
+ /// Begin parsing at startRuleIndex
+ public virtual ParserRuleContext Parse(int startRuleIndex)
+ {
+ RuleStartState startRuleStartState = _atn.ruleToStartState[startRuleIndex];
+ InterpreterRuleContext rootContext = new InterpreterRuleContext(null, ATNState.InvalidStateNumber, startRuleIndex);
+ if (startRuleStartState.isPrecedenceRule)
+ {
+ EnterRecursionRule(rootContext, startRuleStartState.stateNumber, startRuleIndex, 0);
+ }
+ else
+ {
+ EnterRule(rootContext, startRuleStartState.stateNumber, startRuleIndex);
+ }
+ while (true)
+ {
+ ATNState p = AtnState;
+ switch (p.StateType)
+ {
+ case StateType.RuleStop:
+ {
+ // pop; return from rule
+ if (RuleContext.IsEmpty)
+ {
+ if (startRuleStartState.isPrecedenceRule)
+ {
+ ParserRuleContext result = RuleContext;
+ Tuple parentContext = _parentContextStack.Pop();
+ UnrollRecursionContexts(parentContext.Item1);
+ return result;
+ }
+ else
+ {
+ ExitRule();
+ return rootContext;
+ }
+ }
+ VisitRuleStopState(p);
+ break;
+ }
+
+ default:
+ {
+ try
+ {
+ VisitState(p);
+ }
+ catch (RecognitionException e)
+ {
+ State = _atn.ruleToStopState[p.ruleIndex].stateNumber;
+ Context.exception = e;
+ ErrorHandler.ReportError(this, e);
+ ErrorHandler.Recover(this, e);
+ }
+ break;
+ }
+ }
+ }
+ }
+
+ public override void EnterRecursionRule(ParserRuleContext localctx, int state, int ruleIndex, int precedence)
+ {
+ _parentContextStack.Push(Tuple.Create(RuleContext, localctx.invokingState));
+ base.EnterRecursionRule(localctx, state, ruleIndex, precedence);
+ }
+
+ protected internal virtual ATNState AtnState
+ {
+ get
+ {
+ return _atn.states[State];
+ }
+ }
+
+ public override string GrammarFileName => throw new NotImplementedException();
+
+ protected internal virtual void VisitState(ATNState p)
+ {
+ int predictedAlt = 1;
+ if ( p is DecisionState ) {
+ predictedAlt = visitDecisionState((DecisionState) p);
+ }
+
+ Transition transition = p.Transition(predictedAlt - 1);
+ switch (transition.TransitionType)
+ {
+ case TransitionType.EPSILON:
+ {
+ if (pushRecursionContextStates.Get(p.stateNumber) && !(transition.target is LoopEndState))
+ {
+ InterpreterRuleContext ctx = new InterpreterRuleContext(_parentContextStack.Peek().Item1, _parentContextStack.Peek().Item2, RuleContext.RuleIndex);
+ PushNewRecursionContext(ctx, _atn.ruleToStartState[p.ruleIndex].stateNumber, RuleContext.RuleIndex);
+ }
+ break;
+ }
+
+ case TransitionType.ATOM:
+ {
+ Match(((AtomTransition)transition).token);
+ break;
+ }
+
+ case TransitionType.RANGE:
+ case TransitionType.SET:
+ case TransitionType.NOT_SET:
+ {
+ if (!transition.Matches(TokenStream.LA(1), TokenConstants.MinUserTokenType, 65535))
+ {
+ ErrorHandler.RecoverInline(this);
+ }
+ MatchWildcard();
+ break;
+ }
+
+ case TransitionType.WILDCARD:
+ {
+ MatchWildcard();
+ break;
+ }
+
+ case TransitionType.RULE:
+ {
+ RuleStartState ruleStartState = (RuleStartState)transition.target;
+ int ruleIndex = ruleStartState.ruleIndex;
+ InterpreterRuleContext ctx_1 = new InterpreterRuleContext(RuleContext, p.stateNumber, ruleIndex);
+ if (ruleStartState.isPrecedenceRule)
+ {
+ EnterRecursionRule(ctx_1, ruleStartState.stateNumber, ruleIndex, ((RuleTransition)transition).precedence);
+ }
+ else
+ {
+ EnterRule(ctx_1, transition.target.stateNumber, ruleIndex);
+ }
+ break;
+ }
+
+ case TransitionType.PREDICATE:
+ {
+ PredicateTransition predicateTransition = (PredicateTransition)transition;
+ if (!Sempred(RuleContext, predicateTransition.ruleIndex, predicateTransition.predIndex))
+ {
+ throw new FailedPredicateException(this);
+ }
+ break;
+ }
+
+ case TransitionType.ACTION:
+ {
+ ActionTransition actionTransition = (ActionTransition)transition;
+ Action(RuleContext, actionTransition.ruleIndex, actionTransition.actionIndex);
+ break;
+ }
+
+ case TransitionType.PRECEDENCE:
+ {
+ if (!Precpred(RuleContext, ((PrecedencePredicateTransition)transition).precedence))
+ {
+ throw new FailedPredicateException(this, string.Format("precpred(Context, {0})", ((PrecedencePredicateTransition)transition).precedence));
+ }
+ break;
+ }
+
+ default:
+ {
+ throw new NotSupportedException("Unrecognized ATN transition type.");
+ }
+ }
+ State = transition.target.stateNumber;
+ }
+
+ /** Method visitDecisionState() is called when the interpreter reaches
+ * a decision state (instance of DecisionState). It gives an opportunity
+ * for subclasses to track interesting things.
+ */
+ protected int visitDecisionState(DecisionState p) {
+ int predictedAlt = 1;
+ if ( p.NumberOfTransitions > 1 ) {
+ ErrorHandler.Sync(this);
+ int decision = p.decision;
+ if ( decision == overrideDecision && InputStream.Index == overrideDecisionInputIndex &&
+ !overrideDecisionReached )
+ {
+ predictedAlt = overrideDecisionAlt;
+ overrideDecisionReached = true;
+ }
+ else {
+ predictedAlt = Interpreter.AdaptivePredict((ITokenStream)InputStream, decision, Context);
+ }
+ }
+ return predictedAlt;
+ }
+
+ /** Provide simple "factory" for InterpreterRuleContext's.
+ * @since 4.5.1
+ */
+ protected InterpreterRuleContext createInterpreterRuleContext(
+ ParserRuleContext parent,
+ int invokingStateNumber,
+ int ruleIndex)
+ {
+ return new InterpreterRuleContext(parent, invokingStateNumber, ruleIndex);
+ }
+
+ protected internal virtual void VisitRuleStopState(ATNState p)
+ {
+ RuleStartState ruleStartState = _atn.ruleToStartState[p.ruleIndex];
+ if (ruleStartState.isPrecedenceRule)
+ {
+ Tuple parentContext = _parentContextStack.Pop();
+ UnrollRecursionContexts(parentContext.Item1);
+ State = parentContext.Item2;
+ }
+ else
+ {
+ ExitRule();
+ }
+ RuleTransition ruleTransition = (RuleTransition)_atn.states[State].Transition(0);
+ State = ruleTransition.followState.stateNumber;
+ }
+
+
+ /** Override this parser interpreters normal decision-making process
+ * at a particular decision and input token index. Instead of
+ * allowing the adaptive prediction mechanism to choose the
+ * first alternative within a block that leads to a successful parse,
+ * force it to take the alternative, 1..n for n alternatives.
+ *
+ * As an implementation limitation right now, you can only specify one
+ * override. This is sufficient to allow construction of different
+ * parse trees for ambiguous input. It means re-parsing the entire input
+ * in general because you're never sure where an ambiguous sequence would
+ * live in the various parse trees. For example, in one interpretation,
+ * an ambiguous input sequence would be matched completely in expression
+ * but in another it could match all the way back to the root.
+ *
+ * s : e '!'? ;
+ * e : ID
+ * | ID '!'
+ * ;
+ *
+ * Here, x! can be matched as (s (e ID) !) or (s (e ID !)). In the first
+ * case, the ambiguous sequence is fully contained only by the root.
+ * In the second case, the ambiguous sequences fully contained within just
+ * e, as in: (e ID !).
+ *
+ * Rather than trying to optimize this and make
+ * some intelligent decisions for optimization purposes, I settled on
+ * just re-parsing the whole input and then using
+ * {link Trees#getRootOfSubtreeEnclosingRegion} to find the minimal
+ * subtree that contains the ambiguous sequence. I originally tried to
+ * record the call stack at the point the parser detected and ambiguity but
+ * left recursive rules create a parse tree stack that does not reflect
+ * the actual call stack. That impedance mismatch was enough to make
+ * it it challenging to restart the parser at a deeply nested rule
+ * invocation.
+ *
+ * Only parser interpreters can override decisions so as to avoid inserting
+ * override checking code in the critical ALL(*) prediction execution path.
+ *
+ * @since 4.5.1
+ */
+ public void AddDecisionOverride(int decision, int tokenIndex, int forcedAlt) {
+ overrideDecision = decision;
+ overrideDecisionInputIndex = tokenIndex;
+ overrideDecisionAlt = forcedAlt;
+ }
+
+ public InterpreterRuleContext GetOverrideDecisionRoot() {
+ return overrideDecisionRoot;
+ }
+
+ /** Rely on the error handler for this parser but, if no tokens are consumed
+ * to recover, add an error node. Otherwise, nothing is seen in the parse
+ * tree.
+ */
+ protected void Recover(RecognitionException e) {
+ int i = InputStream.Index;
+ ErrorHandler.Recover(this, e);
+ if ( InputStream.Index==i ) {
+ // no input consumed, better add an error node
+ if ( e is InputMismatchException ) {
+ InputMismatchException ime = (InputMismatchException)e;
+ IToken tok = e.OffendingToken;
+ int expectedTokenType = TokenConstants.InvalidType;
+ if ( !ime.GetExpectedTokens().IsNil ) {
+ expectedTokenType = ime.GetExpectedTokens().MinElement; // get any element
+ }
+ IToken errToken = TokenFactory.Create(new Tuple(tok.TokenSource, tok.TokenSource.InputStream),
+ expectedTokenType, tok.Text,
+ TokenConstants.DefaultChannel,
+ -1, -1, // invalid start/stop
+ tok.Line, tok.Column);
+ Context.AddErrorNode(errToken);
+ }
+ else { // NoViableAlt
+ IToken tok = e.OffendingToken;
+ IToken errToken = TokenFactory.Create(new Tuple(tok.TokenSource, tok.TokenSource.InputStream),
+ TokenConstants.InvalidType, tok.Text,
+ TokenConstants.DefaultChannel,
+ -1, -1, // invalid start/stop
+ tok.Line, tok.Column);
+ Context.AddErrorNode(errToken);
+ }
+ }
+ }
+
+ protected IToken RecoverInline() {
+ return ErrorHandler.RecoverInline(this);
+ }
+
+ /** Return the root of the parse, which can be useful if the parser
+ * bails out. You still can access the top node. Note that,
+ * because of the way left recursive rules add children, it's possible
+ * that the root will not have any children if the start rule immediately
+ * called and left recursive rule that fails.
+ *
+ * @since 4.5.1
+ */
+ public InterpreterRuleContext GetRootContext() {
+ return rootContext;
+ }
+}
diff --git a/src/trgen/templates/CSharp/st.MyParser.cs b/src/trgen/templates/CSharp/st.MyParser.cs
new file mode 100644
index 000000000..5fb36aae2
--- /dev/null
+++ b/src/trgen/templates/CSharp/st.MyParser.cs
@@ -0,0 +1,71 @@
+using System.Collections.Generic;
+using Antlr4.Runtime;
+using System.IO;
+using Antlr4.Runtime.Atn;
+using Antlr4.Runtime.Sharpen;
+using Antlr4.Runtime.Tree;
+
+public class MyParser : {
+ private readonly ITokenStream _tokens;
+ public MyParserInterpreter _ParserInterpreter;
+
+ public MyParser(ITokenStream input)
+ : base(input)
+ {
+ _tokens = input;
+ _ParserInterpreter = new MyParserInterpreter(
+ this.Vocabulary,
+ this.RuleNames,
+ this.Atn,
+ input);
+ }
+
+ public List\ getAllPossibleParseTrees(
+ int decision,
+ BitSet alts,
+ int startIndex,
+ int stopIndex,
+ int startRuleIndex)
+ {
+ _ParserInterpreter.Interpreter.PredictionMode = PredictionMode.LL_EXACT_AMBIG_DETECTION;
+ var trees = new List\();
+
+ if ( stopIndex>=(_tokens.Size - 1) ) { // if we are pointing at EOF token
+ // EOF is not in tree, so must be 1 less than last non-EOF token
+ stopIndex = _tokens.Size - 2;
+ }
+
+ // get ambig trees
+ int alt = alts.NextSetBit(0);
+ while ( alt >= 0 )
+ {
+ // re-parse entire input for all ambiguous alternatives
+ // (don't have to do first as it's been parsed, but do again for simplicity
+ // using this temp parser.)
+ _ParserInterpreter.Reset();
+ _ParserInterpreter.AddDecisionOverride(decision, startIndex, alt);
+ ParserRuleContext t = _ParserInterpreter.Parse(startRuleIndex);
+ trees.Add(t);
+ alt = alts.NextSetBit(alt+1);
+ }
+ return trees;
+ }
+
+ public override void RemoveErrorListener(IAntlrErrorListener\ listener)
+ {
+ base.RemoveErrorListener(listener);
+ _ParserInterpreter.RemoveErrorListener(listener);
+ }
+
+ public override void RemoveErrorListeners()
+ {
+ base.RemoveErrorListeners();
+ _ParserInterpreter.RemoveErrorListeners();
+ }
+
+ public override void AddErrorListener(IAntlrErrorListener\ listener)
+ {
+ base.AddErrorListener(listener);
+ _ParserInterpreter.AddErrorListener(listener);
+ }
+}
diff --git a/src/trgen/templates/CSharp/st.Test.cs b/src/trgen/templates/CSharp/st.Test.cs
index 76cf06fff..9a0bb66b2 100644
--- a/src/trgen/templates/CSharp/st.Test.cs
+++ b/src/trgen/templates/CSharp/st.Test.cs
@@ -4,12 +4,10 @@
using Antlr4.Runtime.Atn;
using Antlr4.Runtime.Tree;
using System;
+using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
-using System.Runtime.CompilerServices;
-using System.Collections.Generic;
-using System.Net.Sockets;
namespace
{
@@ -22,6 +20,7 @@ public class Program
public static ITokenStream TokenStream { get; set; }
public static ICharStream CharStream { get; set; }
public static IParseTree Tree { get; set; }
+ public static List\ Trees { get; set; }
public static string StartSymbol { get; set; } = "";
public static string Input { get; set; }
public static bool HeatMap { get; set; } = false;
@@ -31,15 +30,15 @@ public static void SetupParse2(string input, bool quiet = false)
CharStream = str;
var lexer = new (str);
Lexer = lexer;
- CommonTokenStream tokens = null;
- if (HeatMap) {
- tokens = new ProfilingCommonTokenStream(lexer);
- }
- else {
- tokens = new CommonTokenStream(lexer);
- }
+ CommonTokenStream tokens = null;
+ if (HeatMap) {
+ tokens = new ProfilingCommonTokenStream(lexer);
+ }
+ else {
+ tokens = new CommonTokenStream(lexer);
+ }
TokenStream = tokens;
- var parser = new (tokens);
+ var parser = new MyParser(tokens);
Parser = parser;
var listener_lexer = new ErrorListener\(false, false, System.Console.Error);
var listener_parser = new ErrorListener\(false, false, System.Console.Error);
@@ -60,6 +59,41 @@ public static IParseTree Parse2()
return tree;
}
+ public static List\>> Parse3()
+ {
+ Parser.Profile = true;
+ var tree = Parser.();
+ var decisions = Parser.ParseInfo.getDecisionInfo().Where(d => d.ambiguities.Any()).ToList();
+ var result = new List\>>();
+ foreach (var decision in decisions)
+ {
+ var am = decision.ambiguities;
+ var trees = new List\();
+ foreach (AmbiguityInfo ai in am)
+ {
+ var parser_decision = ai.decision;
+ var parser_alts = ai.ambigAlts;
+ var parser_startIndex = ai.startIndex;
+ var parser_stopIndex = ai.stopIndex;
+ var p = Parser.RuleNames.Select((value, index) => new { value, index })
+ .Where(pair => (pair.value == ""))
+ .Select(pair => pair.index).First();
+ var parser_startRuleIndex = p;
+ var parser_trees = ((MyParser)Parser).getAllPossibleParseTrees(
+ parser_decision,
+ parser_alts,
+ parser_startIndex,
+ parser_stopIndex,
+ parser_startRuleIndex);
+ trees.AddRange(parser_trees);
+ }
+ result.Add(new Tuple\>(decision.decision, trees));
+ }
+ Input = Lexer.InputStream.ToString();
+ TokenStream = Parser.TokenStream;
+ return result;
+ }
+
public static bool AnyErrors()
{
return ParserErrorListener.had_error || LexerErrorListener.had_error;
@@ -71,13 +105,13 @@ public static IParseTree Parse(string input)
CharStream = str;
var lexer = new (str);
Lexer = lexer;
- CommonTokenStream tokens = null;
- if (show_hit) {
- tokens = new ProfilingCommonTokenStream(lexer);
- }
- else {
- tokens = new CommonTokenStream(lexer);
- }
+ CommonTokenStream tokens = null;
+ if (show_hit) {
+ tokens = new ProfilingCommonTokenStream(lexer);
+ }
+ else {
+ tokens = new CommonTokenStream(lexer);
+ }
TokenStream = tokens;
var parser = new (tokens);
Parser = parser;
@@ -97,6 +131,7 @@ public static IParseTree Parse(string input)
static bool tee = false;
static bool show_diagnostic = false;
static bool show_hit = false;
+ static bool show_ambig = false;
static bool show_profile = false;
static bool show_tokens = false;
static bool show_trace = false;
@@ -119,6 +154,10 @@ static void Main(string[] args)
{
show_diagnostic = true;
}
+ else if (args[i] == "-ambig")
+ {
+ show_ambig = true;
+ }
else if (args[i] == "-profile")
{
show_profile = true;
@@ -259,14 +298,14 @@ static void DoParse(ICharStream str, string input_name, int row_number)
System.Console.Error.WriteLine(new_s.ToString());
lexer.Reset();
}
- CommonTokenStream tokens = null;
- if (show_hit) {
- tokens = new ProfilingCommonTokenStream(lexer);
- }
- else {
- tokens = new CommonTokenStream(lexer);
- }
- var parser = new (tokens);
+ CommonTokenStream tokens = null;
+ if (show_hit) {
+ tokens = new ProfilingCommonTokenStream(lexer);
+ }
+ else {
+ tokens = new CommonTokenStream(lexer);
+ }
+ var parser = new MyParser(tokens);
var output = tee ? new StreamWriter(input_name + ".errors") : System.Console.Error;
var listener_lexer = new ErrorListener\(quiet, tee, output);
var listener_parser = new ErrorListener\(quiet, tee, output);
@@ -278,7 +317,7 @@ static void DoParse(ICharStream str, string input_name, int row_number)
{
parser.AddErrorListener(new MyDiagnosticErrorListener());
}
- if (show_profile)
+ if (show_profile || show_ambig)
{
parser.Profile = true;
}
@@ -305,8 +344,7 @@ static void DoParse(ICharStream str, string input_name, int row_number)
if (tee)
{
System.IO.File.WriteAllText(input_name + ".tree", tree.ToStringTree(parser));
- } else
- {
+ } else {
System.Console.Error.WriteLine(tree.ToStringTree(parser));
}
}
@@ -314,6 +352,41 @@ static void DoParse(ICharStream str, string input_name, int row_number)
{
System.Console.Error.WriteLine(String.Join(",\n\r", parser.ParseInfo.getDecisionInfo().Select(d => d.ToString())));
}
+ if (show_ambig)
+ {
+ var decs = parser.ParseInfo.getDecisionInfo().Where(d =>
+ d.ambiguities.Any()).Select(d => d.ambiguities).ToList();
+ foreach (var decision in decs)
+ {
+ foreach (var ai in decision)
+ {
+ var parser_decision = ai.decision;
+ var parser_alts = ai.ambigAlts;
+ var parser_startIndex = ai.startIndex;
+ var parser_stopIndex = ai.stopIndex;
+ var nfa_state = parser.Atn.states.Where(s =>
+ {
+ if (s is BasicBlockStartState s2) return s2.decision == parser_decision;
+ else return false;
+ }).ToList();
+ var p = parser.RuleNames.Select((value, index) => new { value, index })
+ .Where(pair => (pair.value == ""))
+ .Select(pair => pair.index).First();
+ var parser_startRuleIndex = p;
+ var parser_trees = parser.getAllPossibleParseTrees(
+ parser_decision,
+ parser_alts,
+ parser_startIndex,
+ parser_stopIndex,
+ parser_startRuleIndex);
+ foreach (var parser_tree in parser_trees)
+ {
+ System.Console.WriteLine(parser_tree.ToStringTree(parser));
+ System.Console.WriteLine();
+ }
+ }
+ }
+ }
if (!quiet)
{
System.Console.Error.WriteLine(prefix + "CSharp " + row_number + " " + input_name + " " + result + " " + (after - before).TotalSeconds);
@@ -323,79 +396,79 @@ static void DoParse(ICharStream str, string input_name, int row_number)
public static string ToStringTree(ITree tree, Parser recog)
{
- StringBuilder sb = new StringBuilder();
- string[] ruleNames = recog != null ? recog.RuleNames : null;
- IList\ ruleNamesList = ruleNames != null ? ruleNames.ToList() : null;
- ToStringTree(sb, tree, 0, ruleNamesList);
- return sb.ToString();
+ StringBuilder sb = new StringBuilder();
+ string[] ruleNames = recog != null ? recog.RuleNames : null;
+ IList\ ruleNamesList = ruleNames != null ? ruleNames.ToList() : null;
+ ToStringTree(sb, tree, 0, ruleNamesList);
+ return sb.ToString();
}
public static void ToStringTree(StringBuilder sb, ITree t, int indent, IList\ ruleNames)
{
- string s = Antlr4.Runtime.Misc.Utils.EscapeWhitespace(GetNodeText(t, ruleNames), false);
- if (t.ChildCount == 0)
- {
- for (int i = 0; i \< indent; ++i) sb.Append(" ");
- sb.AppendLine(s);
- return;
- }
- s = Antlr4.Runtime.Misc.Utils.EscapeWhitespace(GetNodeText(t, ruleNames), false);
- for (int i = 0; i \< indent; ++i) sb.Append(' ');
- sb.AppendLine(s);
- for (int i = 0; i \< t.ChildCount; i++)
- {
- ToStringTree(sb, t.GetChild(i), indent+1, ruleNames);
- }
+ string s = Antlr4.Runtime.Misc.Utils.EscapeWhitespace(GetNodeText(t, ruleNames), false);
+ if (t.ChildCount == 0)
+ {
+ for (int i = 0; i \< indent; ++i) sb.Append(" ");
+ sb.AppendLine(s);
+ return;
+ }
+ s = Antlr4.Runtime.Misc.Utils.EscapeWhitespace(GetNodeText(t, ruleNames), false);
+ for (int i = 0; i \< indent; ++i) sb.Append(' ');
+ sb.AppendLine(s);
+ for (int i = 0; i \< t.ChildCount; i++)
+ {
+ ToStringTree(sb, t.GetChild(i), indent+1, ruleNames);
+ }
}
public static string GetNodeText(ITree t, Parser recog)
{
- string[] ruleNames = recog != null ? recog.RuleNames : null;
- IList\ ruleNamesList = ruleNames != null ? ruleNames.ToList() : null;
- return GetNodeText(t, ruleNamesList);
+ string[] ruleNames = recog != null ? recog.RuleNames : null;
+ IList\ ruleNamesList = ruleNames != null ? ruleNames.ToList() : null;
+ return GetNodeText(t, ruleNamesList);
}
public static string GetNodeText(ITree t, IList\ ruleNames)
{
- if (ruleNames != null)
- {
- if (t is RuleContext)
- {
- int ruleIndex = ((RuleContext)t).RuleIndex;
- string ruleName = ruleNames[ruleIndex];
- int altNumber = ((RuleContext)t).getAltNumber();
- if ( altNumber!= Antlr4.Runtime.Atn.ATN.INVALID_ALT_NUMBER ) {
- return ruleName+":"+altNumber;
- }
- return ruleName;
- }
- else
- {
- if (t is IErrorNode)
- {
- return t.ToString();
- }
- else
- {
- if (t is ITerminalNode)
- {
- IToken symbol = ((ITerminalNode)t).Symbol;
- if (symbol != null)
- {
- string s = symbol.Text;
- return s;
- }
- }
- }
- }
- }
- // no recog for rule names
- object payload = t.Payload;
- if (payload is IToken)
- {
- return ((IToken)payload).Text;
- }
- return t.Payload.ToString();
+ if (ruleNames != null)
+ {
+ if (t is RuleContext)
+ {
+ int ruleIndex = ((RuleContext)t).RuleIndex;
+ string ruleName = ruleNames[ruleIndex];
+ int altNumber = ((RuleContext)t).getAltNumber();
+ if ( altNumber!= Antlr4.Runtime.Atn.ATN.INVALID_ALT_NUMBER ) {
+ return ruleName+":"+altNumber;
+ }
+ return ruleName;
+ }
+ else
+ {
+ if (t is IErrorNode)
+ {
+ return t.ToString();
+ }
+ else
+ {
+ if (t is ITerminalNode)
+ {
+ IToken symbol = ((ITerminalNode)t).Symbol;
+ if (symbol != null)
+ {
+ string s = symbol.Text;
+ return s;
+ }
+ }
+ }
+ }
+ }
+ // no recog for rule names
+ object payload = t.Payload;
+ if (payload is IToken)
+ {
+ return ((IToken)payload).Text;
+ }
+ return t.Payload.ToString();
}
}
diff --git a/src/trgen/trgen.csproj b/src/trgen/trgen.csproj
index 30430320a..7d13c722f 100644
--- a/src/trgen/trgen.csproj
+++ b/src/trgen/trgen.csproj
@@ -18,7 +18,7 @@ This program is part of the Trash toolkit.]]>
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trgen
git
diff --git a/src/trgenvsc/readme.md b/src/trgenvsc/readme.md
index e22833e0a..9505dd41f 100644
--- a/src/trgenvsc/readme.md
+++ b/src/trgenvsc/readme.md
@@ -30,7 +30,7 @@ the XPath patterns to match certain parse trees.
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trgenvsc/templates/clean.sh b/src/trgenvsc/templates/clean.sh
index a8b6a10d6..736053a1b 100644
--- a/src/trgenvsc/templates/clean.sh
+++ b/src/trgenvsc/templates/clean.sh
@@ -1,16 +1,3 @@
#!/bin/sh
-pushd server
-rm -rf Logger ParseTreeEditing Workspaces
-popd
-
-pushd src
-rm -rf node_modules
-rm -f package-lock.json
-rm -rf out
-# rm -rf 'c:/Users/kenne/AppData/Roaming/Code'
-rm -rf server/net8.0
-rm -rf Trash
-rm -rf *.vsix
-# npm install
-popd
+rm -rf node_modules package-lock.json out server/*/bin/ server/*/obj/ *.vsix
diff --git a/src/trgenvsc/templates/install.sh b/src/trgenvsc/templates/install.sh
index a9338e73b..9eb5d911c 100644
--- a/src/trgenvsc/templates/install.sh
+++ b/src/trgenvsc/templates/install.sh
@@ -14,11 +14,17 @@ popd
if [[ "$OSTYPE" == "darwin"* ]]; then
brew install vsce
fi
-npm i vscode-jsonrpc@6.0.0-next.5
-npm i vscode-languageclient@7.0.0-next.9
-npm i vscode-languageserver@7.0.0-next.7
-npm i vscode-languageserver-protocol@3.16.0-next.7
-npm i vscode-languageserver-types@3.16.0-next.3
+npm i vscode-jsonrpc
+npm i vscode-languageclient
+npm i vscode-languageserver
+npm i vscode-languageserver-protocol
+npm i vscode-languageserver-types
+npm i jsonc-parser
+npm i @types/vscode
+npm i @types/mocha
+npm i @types/node
+npm i @vscode/vsce
+
npm install
npm run compile
./node_modules/.bin/vsce package
diff --git a/src/trgenvsc/templates/package.json b/src/trgenvsc/templates/package.json
index 7d1ca2407..937a8a678 100644
--- a/src/trgenvsc/templates/package.json
+++ b/src/trgenvsc/templates/package.json
@@ -19,7 +19,7 @@
},
"version": "1.0.0",
"engines": {
- "vscode": "^1.48.0"
+ "vscode": "^1.93.0"
},
"activationEvents": [
"onLanguage:any"
@@ -63,25 +63,24 @@
"compile": "tsc -p ./"
},
"dependencies": {
- "abort-controller": "3.0.0",
- "jsonc-parser": "2.3.0",
- "vscode-jsonrpc": "^6.0.0-next.5",
- "vscode-languageclient": "^7.0.0-next.9",
- "vscode-languageserver": "^7.0.0-next.7",
- "vscode-languageserver-protocol": "^3.16.0-next.7",
- "vscode-languageserver-types": "^3.16.0-next.3"
+ "@vscode/vsce": "^3.1.0",
+ "jsonc-parser": "^2.3.1",
+ "vscode-jsonrpc": "^8.2.1",
+ "vscode-languageclient": "^9.0.1",
+ "vscode-languageserver": "^9.0.1",
+ "vscode-languageserver-protocol": "^3.17.5",
+ "vscode-languageserver-types": "^3.17.5"
},
"devDependencies": {
- "@types/glob": "^7.1.3",
- "@types/mocha": "^8.0.3",
- "@types/node": "^14.6.2",
- "@types/vscode": "1.48.0",
- "@vscode/vsce": "^2.23.0",
- "glob": "^7.1.4",
- "mocha": "^10.2.0",
- "tslint": "^5.16.0",
- "typescript": "^3.8.3",
- "vscode-test": "^1.3.0"
+ "@types/mocha": "^10.0.7",
+ "@types/node": "^20.16.5",
+ "@types/vscode": "^1.93.0",
+ "@typescript-eslint/eslint-plugin": "^8.3.0",
+ "@typescript-eslint/parser": "^8.3.0",
+ "@vscode/test-cli": "^0.0.10",
+ "@vscode/test-electron": "^2.4.1",
+ "eslint": "^9.9.1",
+ "typescript": "^5.5.4"
},
"configuration": {
"type": "object",
diff --git a/src/trgenvsc/templates/src/extension.ts b/src/trgenvsc/templates/src/extension.ts
index 94516f077..64ebc41db 100644
--- a/src/trgenvsc/templates/src/extension.ts
+++ b/src/trgenvsc/templates/src/extension.ts
@@ -14,11 +14,13 @@ function getConfig(option: string, defaultValue?: any): T
return config.get(option, defaultValue);
}
+/*
namespace SwitchSourceHeaderRequest
{
export const type = new vscodelc.RequestType('textDocument/switchSourceHeader');
}
+*/
class FileStatus
{
diff --git a/src/trgenvsc/trgenvsc.csproj b/src/trgenvsc/trgenvsc.csproj
index c0b2a31af..86c262697 100644
--- a/src/trgenvsc/trgenvsc.csproj
+++ b/src/trgenvsc/trgenvsc.csproj
@@ -18,7 +18,7 @@ This program is part of the Trash toolkit.]]>
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trgenvsc
git
diff --git a/src/trglob/readme.md b/src/trglob/readme.md
index 07de30413..c70c805dd 100644
--- a/src/trglob/readme.md
+++ b/src/trglob/readme.md
@@ -17,7 +17,7 @@ Expand a glob string into file names.
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trglob/trglob.csproj b/src/trglob/trglob.csproj
index 33d3f3905..716c11fd0 100644
--- a/src/trglob/trglob.csproj
+++ b/src/trglob/trglob.csproj
@@ -18,7 +18,7 @@ This program is part of the Trash toolkit.]]>
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trglob
git
diff --git a/src/trgroup/readme.md b/src/trgroup/readme.md
index 903e3d0a9..6f9b1cdd2 100644
--- a/src/trgroup/readme.md
+++ b/src/trgroup/readme.md
@@ -56,7 +56,7 @@ XPaths, type _export MSYS2_ARG_CONV_EXCL="*"_, then execute your command.
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trgroup/trgroup.csproj b/src/trgroup/trgroup.csproj
index c58790a97..7aff38d92 100644
--- a/src/trgroup/trgroup.csproj
+++ b/src/trgroup/trgroup.csproj
@@ -17,7 +17,7 @@ This program is part of the Trash toolkit.]]>
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trgroup
git
diff --git a/src/triconv/readme.md b/src/triconv/readme.md
index d9ee28f84..14de4ca0d 100644
--- a/src/triconv/readme.md
+++ b/src/triconv/readme.md
@@ -20,7 +20,7 @@ unicode.
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/triconv/triconv.csproj b/src/triconv/triconv.csproj
index 5838203bc..387f5c570 100644
--- a/src/triconv/triconv.csproj
+++ b/src/triconv/triconv.csproj
@@ -17,7 +17,7 @@ This program is part of the Trash toolkit.]]>
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trxml2
git
diff --git a/src/tritext/readme.md b/src/tritext/readme.md
index b0aa4f3f9..3cb668af1 100644
--- a/src/tritext/readme.md
+++ b/src/tritext/readme.md
@@ -18,7 +18,7 @@ Get strings from a PDF file using IText.
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/tritext/tritext.csproj b/src/tritext/tritext.csproj
index 2c1648e9d..fcd5bf805 100644
--- a/src/tritext/tritext.csproj
+++ b/src/tritext/tritext.csproj
@@ -18,7 +18,7 @@ This program is part of the Trash toolkit.
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/tritext
git
diff --git a/src/trjson/readme.md b/src/trjson/readme.md
index d8e02e44d..4c3b8d14a 100644
--- a/src/trjson/readme.md
+++ b/src/trjson/readme.md
@@ -18,7 +18,7 @@ Read a parse tree from stdin and write a JSON represenation of it.
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trjson/trjson.csproj b/src/trjson/trjson.csproj
index afaa39ae3..8fa1fad6b 100644
--- a/src/trjson/trjson.csproj
+++ b/src/trjson/trjson.csproj
@@ -18,7 +18,7 @@ This program is part of the Trash toolkit.
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trjson
git
diff --git a/src/trkleene/readme.md b/src/trkleene/readme.md
index e2ab40550..1f3a6b723 100644
--- a/src/trkleene/readme.md
+++ b/src/trkleene/readme.md
@@ -38,7 +38,7 @@ XPaths, type _export MSYS2_ARG_CONV_EXCL="*"_, then execute your command.
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trkleene/trkleene.csproj b/src/trkleene/trkleene.csproj
index 4cbe2fb04..82478fdd4 100644
--- a/src/trkleene/trkleene.csproj
+++ b/src/trkleene/trkleene.csproj
@@ -19,7 +19,7 @@ This program is part of the Trash toolkit.
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trkleene
git
diff --git a/src/trparse/Config.cs b/src/trparse/Config.cs
index 00361f591..a531ee7b7 100644
--- a/src/trparse/Config.cs
+++ b/src/trparse/Config.cs
@@ -7,6 +7,9 @@ public class Config
{
[Value(0)] public IEnumerable Files { get; set; }
+ [Option('a', "ambig", Required = false, HelpText = "Output ambiguous parse trees.")]
+ public bool Ambig { get; set; }
+
[Option('d', "dll", Required = false, HelpText = "Search for parser in dll with this specified name.")]
public string Dll { get; set; } = "Test";
diff --git a/src/trparse/Grun.cs b/src/trparse/Grun.cs
index 60cb442c1..638521844 100644
--- a/src/trparse/Grun.cs
+++ b/src/trparse/Grun.cs
@@ -161,7 +161,7 @@ public int Run(string parser_type = null)
foreach (var t in d.Nodes)
{
if (config.Verbose)
- LoggerNs.TimedStderrOutput.WriteLine(TreeOutput.OutputTree(t, d.Lexer, d.Parser)
+ LoggerNs.TimedStderrOutput.WriteLine(new TreeOutput(d.Lexer, d.Parser).OutputTree(t)
.ToString());
}
}
@@ -192,8 +192,9 @@ public int Run(string parser_type = null)
}
catch (Exception e)
{
- System.Console.WriteLine(e.ToString());
+ System.Console.Error.WriteLine(e.ToString());
result = 1;
+ System.Console.Out.WriteLine();
}
return result;
@@ -255,23 +256,50 @@ int DoParse(string parser_type, string txt, string prefix, string input_name, in
object[] parm1 = new object[] { txt, config.Quiet };
var res = methodInfo.Invoke(null, parm1);
- MethodInfo methodInfo2 = type.GetMethod("Parse2");
- object[] parm2 = new object[] { };
+ var result = "";
+ object res2 = null;
+ object res3 = null;
DateTime before = DateTime.Now;
- var res2 = methodInfo2.Invoke(null, parm2);
DateTime after = DateTime.Now;
-
- MethodInfo methodInfo3 = type.GetMethod("AnyErrors");
- object[] parm3 = new object[] { };
- var res3 = methodInfo3.Invoke(null, parm3);
- var result = "";
- if ((bool)res3)
+ if (!config.Ambig)
{
- result = "fail";
+ MethodInfo methodInfo2 = type.GetMethod("Parse2");
+ object[] parm2 = new object[] { };
+ before = DateTime.Now;
+ res2 = methodInfo2.Invoke(null, parm2);
+ after = DateTime.Now;
+
+ MethodInfo methodInfo3 = type.GetMethod("AnyErrors");
+ object[] parm3 = new object[] { };
+ res3 = methodInfo3.Invoke(null, parm3);
+ if ((bool)res3)
+ {
+ result = "fail";
+ }
+ else
+ {
+ result = "success";
+ }
}
else
{
- result = "success";
+ MethodInfo methodInfo2 = type.GetMethod("Parse3");
+ object[] parm2 = new object[] { };
+ before = DateTime.Now;
+ res2 = methodInfo2.Invoke(null, parm2);
+ after = DateTime.Now;
+
+ MethodInfo methodInfo3 = type.GetMethod("AnyErrors");
+ object[] parm3 = new object[] { };
+ res3 = methodInfo3.Invoke(null, parm3);
+ if ((bool)res3)
+ {
+ result = "fail";
+ }
+ else
+ {
+ result = "success";
+ }
}
System.Console.Error.WriteLine(prefix + "CSharp " + row_number + " " + input_name + " " + result + " " +
@@ -282,19 +310,45 @@ int DoParse(string parser_type, string txt, string prefix, string input_name, in
var charstream = type.GetProperty("CharStream").GetValue(null, new object[0]) as ICharStream;
var commontokstream = tokstream as CommonTokenStream;
var r5 = type.GetProperty("Input").GetValue(null, new object[0]);
- var tree = res2 as IParseTree;
- var t2 = tree as ParserRuleContext;
- //if (!config.Quiet) System.Console.Error.WriteLine("Time to parse: " + (after - before));
- //if (!config.Quiet) System.Console.Error.WriteLine("# tokens per sec = " + tokstream.Size / (after - before).TotalSeconds);
- //if (!config.Quiet && config.Verbose) System.Console.Error.WriteLine(LanguageServer.TreeOutput.OutputTree(tree, lexer, parser, commontokstream));
- var converted_tree =
- new ConvertToDOM(config.LineNumbers).BottomUpConvert(t2, null, parser, lexer, commontokstream, charstream);
- var tuple = new AntlrJson.ParsingResultSet()
+ if (!config.Ambig)
{
- FileName = input_name, Nodes = new UnvParseTreeNode[] { converted_tree },
- Parser = parser, Lexer = lexer
- };
- data.Add(tuple);
+ var tree = res2 as IParseTree;
+ var t2 = tree as ParserRuleContext;
+ var converted_tree = new ConvertToDOM(config.LineNumbers).BottomUpConvert(t2, null, parser, lexer, commontokstream, charstream);
+ var tuple = new AntlrJson.ParsingResultSet()
+ {
+ FileName = input_name,
+ Nodes = new UnvParseTreeNode[] { converted_tree },
+ Parser = parser,
+ Lexer = lexer
+ };
+ data.Add(tuple);
+ }
+ else
+ {
+ var tuples = res2 as List>>;
+ foreach (var tt in tuples)
+ {
+ var list_of_trees = new List();
+ foreach (var tree in tt.Item2)
+ {
+ var t2 = tree as ParserRuleContext;
+ var converted_tree =
+ new ConvertToDOM(config.LineNumbers).BottomUpConvert(t2, null, parser, lexer, commontokstream,
+ charstream);
+ list_of_trees.Add(converted_tree);
+ }
+
+ var tuple = new AntlrJson.ParsingResultSet()
+ {
+ FileName = input_name + "." + tt.Item1,
+ Nodes = list_of_trees.ToArray(),
+ Parser = parser,
+ Lexer = lexer
+ };
+ data.Add(tuple);
+ }
+ }
return (bool)res3 ? 1 : 0;
}
}
diff --git a/src/trparse/Properties/launchSettings.json b/src/trparse/Properties/launchSettings.json
index 486a9f3a1..7f4a848ad 100644
--- a/src/trparse/Properties/launchSettings.json
+++ b/src/trparse/Properties/launchSettings.json
@@ -2,8 +2,8 @@
"profiles": {
"trparse": {
"commandName": "Project",
- "commandLineArgs": "../wsn.ebnf",
- "workingDirectory": "C:\\msys64\\home\\Kenne\\fix\\grammars-v4\\ebnf\\Generated-CSharp"
+ "commandLineArgs": "--ambig ../examples/array.php",
+ "workingDirectory": "C:\\msys64\\home\\Kenne\\issues\\g4-current\\php\\Generated-CSharp"
}
}
}
\ No newline at end of file
diff --git a/src/trparse/readme.md b/src/trparse/readme.md
index 18364427b..59ad10749 100644
--- a/src/trparse/readme.md
+++ b/src/trparse/readme.md
@@ -50,7 +50,7 @@ the `--type` command-line option:
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trparse/trparse.csproj b/src/trparse/trparse.csproj
index 7df29df49..ea8074ff8 100644
--- a/src/trparse/trparse.csproj
+++ b/src/trparse/trparse.csproj
@@ -18,7 +18,7 @@ This program is part of the Trash toolkit.]]>
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trparse
git
diff --git a/src/trperf/readme.md b/src/trperf/readme.md
index 06db4f14d..1473c4347 100644
--- a/src/trperf/readme.md
+++ b/src/trperf/readme.md
@@ -41,7 +41,7 @@ be in a trgen-generated parser directory, or use the -p option.
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trperf/trperf.csproj b/src/trperf/trperf.csproj
index 35a734700..a4469e74f 100644
--- a/src/trperf/trperf.csproj
+++ b/src/trperf/trperf.csproj
@@ -19,7 +19,7 @@ This program is part of the Trash toolkit.]]>
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trperf
git
diff --git a/src/trpiggy/readme.md b/src/trpiggy/readme.md
index b45216148..454774c78 100644
--- a/src/trpiggy/readme.md
+++ b/src/trpiggy/readme.md
@@ -63,7 +63,7 @@ Output:
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trpiggy/trpiggy.csproj b/src/trpiggy/trpiggy.csproj
index ffd831a9b..1daac93fd 100644
--- a/src/trpiggy/trpiggy.csproj
+++ b/src/trpiggy/trpiggy.csproj
@@ -18,7 +18,7 @@ This program is part of the Trash toolkit.]]>
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trpiggy
git
diff --git a/src/trquery/Command.cs b/src/trquery/Command.cs
index eeb069be0..318c678ab 100644
--- a/src/trquery/Command.cs
+++ b/src/trquery/Command.cs
@@ -91,7 +91,7 @@ public void Execute(Config config)
if (config.Verbose)
{
foreach (UnvParseTreeNode n in trees)
- LoggerNs.TimedStderrOutput.WriteLine(TreeOutput.OutputTree(n, lexer, parser).ToString());
+ LoggerNs.TimedStderrOutput.WriteLine(new TreeOutput(lexer, parser).OutputTree(n).ToString());
}
foreach (var scommand in stree.command())
@@ -125,7 +125,7 @@ public void Execute(Config config)
{
LoggerNs.TimedStderrOutput.WriteLine("Operating on this:");
foreach (UnvParseTreeNode n in trees)
- LoggerNs.TimedStderrOutput.WriteLine(TreeOutput.OutputTree(n, lexer, parser)
+ LoggerNs.TimedStderrOutput.WriteLine(new TreeOutput(lexer, parser).OutputTree(n)
.ToString());
}
if (scommand.MATCH_REQUIRED() != null)
@@ -137,8 +137,7 @@ public void Execute(Config config)
{
LoggerNs.TimedStderrOutput.WriteLine("Resulted in this:");
foreach (UnvParseTreeNode n in trees)
- LoggerNs.TimedStderrOutput.WriteLine(TreeOutput.OutputTree(n, lexer, parser)
- .ToString());
+ LoggerNs.TimedStderrOutput.WriteLine(new TreeOutput(lexer, parser).OutputTree(n).ToString());
}
}
}
@@ -180,8 +179,7 @@ public void Execute(Config config)
{
LoggerNs.TimedStderrOutput.WriteLine("Operating on this:");
foreach (UnvParseTreeNode n in trees)
- LoggerNs.TimedStderrOutput.WriteLine(TreeOutput.OutputTree(n, lexer, parser)
- .ToString());
+ LoggerNs.TimedStderrOutput.WriteLine(new TreeOutput(lexer, parser).OutputTree(n).ToString());
}
if (config.Verbose)
LoggerNs.TimedStderrOutput.WriteLine("Found " + nodes.Count + " nodes.");
@@ -225,8 +223,7 @@ public void Execute(Config config)
{
LoggerNs.TimedStderrOutput.WriteLine("Operating on this:");
foreach (UnvParseTreeNode n in trees)
- LoggerNs.TimedStderrOutput.WriteLine(TreeOutput.OutputTree(n, lexer, parser)
- .ToString());
+ LoggerNs.TimedStderrOutput.WriteLine(new TreeOutput(lexer, parser).OutputTree(n).ToString());
}
if (config.Verbose)
LoggerNs.TimedStderrOutput.WriteLine("Found " + nodes.Count + " nodes.");
@@ -266,8 +263,7 @@ public void Execute(Config config)
{
LoggerNs.TimedStderrOutput.WriteLine("Operating on this:");
foreach (UnvParseTreeNode n in trees)
- LoggerNs.TimedStderrOutput.WriteLine(TreeOutput.OutputTree(n, lexer, parser)
- .ToString());
+ LoggerNs.TimedStderrOutput.WriteLine(new TreeOutput(lexer, parser).OutputTree(n).ToString());
}
if (scommand.MATCH_REQUIRED() != null)
{
@@ -278,8 +274,7 @@ public void Execute(Config config)
{
LoggerNs.TimedStderrOutput.WriteLine("Resulted in this:");
foreach (UnvParseTreeNode n in trees)
- LoggerNs.TimedStderrOutput.WriteLine(TreeOutput.OutputTree(n, lexer, parser)
- .ToString());
+ LoggerNs.TimedStderrOutput.WriteLine(new TreeOutput(lexer, parser).OutputTree(n).ToString());
}
}
}
@@ -309,8 +304,7 @@ public void Execute(Config config)
{
LoggerNs.TimedStderrOutput.WriteLine("Operating on this:");
foreach (UnvParseTreeNode n in trees)
- LoggerNs.TimedStderrOutput.WriteLine(TreeOutput.OutputTree(n, lexer, parser)
- .ToString());
+ LoggerNs.TimedStderrOutput.WriteLine(new TreeOutput(lexer, parser).OutputTree(n).ToString());
}
if (scommand.MATCH_REQUIRED() != null)
{
@@ -321,8 +315,7 @@ public void Execute(Config config)
{
LoggerNs.TimedStderrOutput.WriteLine("Resulted in this:");
foreach (UnvParseTreeNode n in trees)
- LoggerNs.TimedStderrOutput.WriteLine(TreeOutput.OutputTree(n, lexer, parser)
- .ToString());
+ LoggerNs.TimedStderrOutput.WriteLine(new TreeOutput(lexer, parser).OutputTree(n).ToString());
}
}
}
@@ -365,8 +358,7 @@ public void Execute(Config config)
{
LoggerNs.TimedStderrOutput.WriteLine("Operating on this:");
foreach (UnvParseTreeNode n in nodes)
- LoggerNs.TimedStderrOutput.WriteLine(TreeOutput.OutputTree(n, lexer, parser)
- .ToString());
+ LoggerNs.TimedStderrOutput.WriteLine(new TreeOutput(lexer, parser).OutputTree(n).ToString());
}
foreach (UnvParseTreeNode n in nodes)
@@ -390,8 +382,7 @@ public void Execute(Config config)
{
LoggerNs.TimedStderrOutput.WriteLine("Resulted in this:");
foreach (UnvParseTreeNode n in trees)
- LoggerNs.TimedStderrOutput.WriteLine(TreeOutput.OutputTree(n, lexer, parser)
- .ToString());
+ LoggerNs.TimedStderrOutput.WriteLine(new TreeOutput(lexer, parser).OutputTree(n).ToString());
}
}
}
@@ -409,7 +400,7 @@ public void Execute(Config config)
if (config.Verbose)
{
foreach (UnvParseTreeNode node in trees)
- System.Console.Error.WriteLine(TreeOutput.OutputTree(node, lexer, parser).ToString());
+ System.Console.Error.WriteLine(new TreeOutput(lexer, parser).OutputTree(node).ToString());
}
}
diff --git a/src/trquery/readme.md b/src/trquery/readme.md
index dedc1845e..15a4216a7 100644
--- a/src/trquery/readme.md
+++ b/src/trquery/readme.md
@@ -47,7 +47,7 @@ XPaths, type _export MSYS2_ARG_CONV_EXCL="*"_, then execute your command.
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trquery/trquery.csproj b/src/trquery/trquery.csproj
index 44e93c3ec..1ecddc18d 100644
--- a/src/trquery/trquery.csproj
+++ b/src/trquery/trquery.csproj
@@ -17,7 +17,7 @@ This program is part of the Trash toolkit.]]>
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trquery
git
diff --git a/src/trrename/Command.cs b/src/trrename/Command.cs
index e0527b9fb..cfacbf9c4 100644
--- a/src/trrename/Command.cs
+++ b/src/trrename/Command.cs
@@ -98,7 +98,7 @@ public void Execute(Config config)
if (config.Verbose)
{
foreach (var n in trees)
- System.Console.WriteLine(TreeOutput.OutputTree(n, lexer, parser).ToString());
+ System.Console.WriteLine(new TreeOutput(lexer, parser).OutputTree(n).ToString());
}
org.eclipse.wst.xml.xpath2.processor.Engine engine = new org.eclipse.wst.xml.xpath2.processor.Engine();
diff --git a/src/trrename/readme.md b/src/trrename/readme.md
index 1ade927e9..788a8a9be 100644
--- a/src/trrename/readme.md
+++ b/src/trrename/readme.md
@@ -27,7 +27,7 @@ make sure to enclose the argument as it contains semi-colons.
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trrename/trrename.csproj b/src/trrename/trrename.csproj
index 13f86d754..9cd7c9e5d 100644
--- a/src/trrename/trrename.csproj
+++ b/src/trrename/trrename.csproj
@@ -17,7 +17,7 @@ This program is part of the Trash toolkit.]]>
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trrename
git
diff --git a/src/trrr/readme.md b/src/trrr/readme.md
index 505c5f88e..8f68b7cb4 100644
--- a/src/trrr/readme.md
+++ b/src/trrr/readme.md
@@ -14,7 +14,7 @@
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trrr/trrr.csproj b/src/trrr/trrr.csproj
index bfd34f9a5..099c755c0 100644
--- a/src/trrr/trrr.csproj
+++ b/src/trrr/trrr.csproj
@@ -17,7 +17,7 @@ This program is part of the Trash toolkit.]]>
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trrr
git
diff --git a/src/trrup/readme.md b/src/trrup/readme.md
index 4f5c38722..6d71dc656 100644
--- a/src/trrup/readme.md
+++ b/src/trrup/readme.md
@@ -42,7 +42,7 @@ XPaths, type _export MSYS2_ARG_CONV_EXCL="*"_, then execute your command.
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trrup/trrup.csproj b/src/trrup/trrup.csproj
index 51838f348..b165dd487 100644
--- a/src/trrup/trrup.csproj
+++ b/src/trrup/trrup.csproj
@@ -17,7 +17,7 @@ This program is part of the Trash toolkit.]]>
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trrup
git
diff --git a/src/trsem/readme.md b/src/trsem/readme.md
index a661998ca..4fe0d3431 100644
--- a/src/trsem/readme.md
+++ b/src/trsem/readme.md
@@ -18,7 +18,7 @@ Read a static semantics spec file and generate code.
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trsem/trsem.csproj b/src/trsem/trsem.csproj
index ed5d76159..6e7179668 100644
--- a/src/trsem/trsem.csproj
+++ b/src/trsem/trsem.csproj
@@ -18,7 +18,7 @@ This program is part of the Trash toolkit.]]>
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trsem
git
diff --git a/src/trsort/Command.cs b/src/trsort/Command.cs
index 2b9b55f27..377f0bc3b 100644
--- a/src/trsort/Command.cs
+++ b/src/trsort/Command.cs
@@ -70,7 +70,7 @@ public void Execute(Config config)
if (config.Verbose)
{
foreach (var n in trees)
- System.Console.WriteLine(TreeOutput.OutputTree(n, lexer, parser).ToString());
+ System.Console.WriteLine(new TreeOutput(lexer, parser).OutputTree(n).ToString());
}
org.eclipse.wst.xml.xpath2.processor.Engine engine = new org.eclipse.wst.xml.xpath2.processor.Engine();
diff --git a/src/trsort/readme.md b/src/trsort/readme.md
index 0e980a05e..0d272954b 100644
--- a/src/trsort/readme.md
+++ b/src/trsort/readme.md
@@ -37,7 +37,7 @@ XPaths, type _export MSYS2_ARG_CONV_EXCL="*"_, then execute your command.
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trsort/trsort.csproj b/src/trsort/trsort.csproj
index 605132c74..57b504b9d 100644
--- a/src/trsort/trsort.csproj
+++ b/src/trsort/trsort.csproj
@@ -17,7 +17,7 @@ This program is part of the Trash toolkit.]]>
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trsort
git
diff --git a/src/trsplit/readme.md b/src/trsplit/readme.md
index fac9f08b0..4529675f0 100644
--- a/src/trsplit/readme.md
+++ b/src/trsplit/readme.md
@@ -45,7 +45,7 @@ modified.
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trsplit/trsplit.csproj b/src/trsplit/trsplit.csproj
index e924c0294..4f1725bdb 100644
--- a/src/trsplit/trsplit.csproj
+++ b/src/trsplit/trsplit.csproj
@@ -17,7 +17,7 @@ This program is part of the Trash toolkit.]]>
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trsplit
git
diff --git a/src/trsponge/readme.md b/src/trsponge/readme.md
index a22ff7723..73c3eb25f 100644
--- a/src/trsponge/readme.md
+++ b/src/trsponge/readme.md
@@ -19,7 +19,7 @@ results to file(s).
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trsponge/trsponge.csproj b/src/trsponge/trsponge.csproj
index 9baeec683..7f5f9bf03 100644
--- a/src/trsponge/trsponge.csproj
+++ b/src/trsponge/trsponge.csproj
@@ -17,7 +17,7 @@ This program is part of the Trash toolkit.]]>
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trsponge
git
diff --git a/src/trst/readme.md b/src/trst/readme.md
index b5cfe8e72..fdee15750 100644
--- a/src/trst/readme.md
+++ b/src/trst/readme.md
@@ -18,7 +18,7 @@ Output tree using the Antlr runtime ToStringTree().
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trst/trst.csproj b/src/trst/trst.csproj
index 21206c02c..b298fbee8 100644
--- a/src/trst/trst.csproj
+++ b/src/trst/trst.csproj
@@ -18,7 +18,7 @@ This program is part of the Trash toolkit.
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trst
git
diff --git a/src/trtext/readme.md b/src/trtext/readme.md
index bbe3e13b9..f062aaae2 100644
--- a/src/trtext/readme.md
+++ b/src/trtext/readme.md
@@ -19,7 +19,7 @@ specified, the line number range for the tree is printed.
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trtext/trtext.csproj b/src/trtext/trtext.csproj
index aa2b5dfb0..fe1da7cdf 100644
--- a/src/trtext/trtext.csproj
+++ b/src/trtext/trtext.csproj
@@ -19,7 +19,7 @@ This program is part of the Trash toolkit.
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trtext
git
diff --git a/src/trthompson/readme.md b/src/trthompson/readme.md
index 43bc38c08..1c6ce54c6 100644
--- a/src/trthompson/readme.md
+++ b/src/trthompson/readme.md
@@ -12,7 +12,7 @@
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trthompson/trthompson.csproj b/src/trthompson/trthompson.csproj
index b324c5cb6..c2a93276a 100644
--- a/src/trthompson/trthompson.csproj
+++ b/src/trthompson/trthompson.csproj
@@ -18,7 +18,7 @@ This program is part of the Trash toolkit.
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trthompson
git
diff --git a/src/trtokens/readme.md b/src/trtokens/readme.md
index f9686d737..55de112dd 100644
--- a/src/trtokens/readme.md
+++ b/src/trtokens/readme.md
@@ -52,7 +52,7 @@ Output:
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trtokens/trtokens.csproj b/src/trtokens/trtokens.csproj
index db79abb7e..1e2b2aba7 100644
--- a/src/trtokens/trtokens.csproj
+++ b/src/trtokens/trtokens.csproj
@@ -17,7 +17,7 @@ This program is part of the Trash toolkit.]]>
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trtokens
git
diff --git a/src/trtree/Command.cs b/src/trtree/Command.cs
index 4b7cddb4e..0f9fd8828 100644
--- a/src/trtree/Command.cs
+++ b/src/trtree/Command.cs
@@ -1,5 +1,6 @@
using ParseTreeEditing.UnvParseTreeDOM;
using System.IO;
+using System.Linq;
using System.Text;
using System.Text.Json;
@@ -54,23 +55,33 @@ public void Execute(Config config)
if (config.Verbose) LoggerNs.TimedStderrOutput.WriteLine("starting deserialization");
var data = JsonSerializer.Deserialize(lines, serializeOptions);
if (config.Verbose) LoggerNs.TimedStderrOutput.WriteLine("deserialized");
+ bool more_than_one_fn = data.Count() > 1;
foreach (var in_tuple in data)
{
var nodes = in_tuple.Nodes;
var lexer = in_tuple.Lexer;
var parser = in_tuple.Parser;
+ var fn = in_tuple.FileName;
+ var prefix = more_than_one_fn ? fn + ": " : "";
StringBuilder sb = new StringBuilder();
foreach (var node in nodes)
{
- sb.AppendLine();
- sb.AppendLine(
- TreeOutput.OutputTree(
- node,
- lexer,
- parser).ToString());
+ if (config.AntlrStyle)
+ {
+ sb.AppendLine(new TreeOutput(lexer, parser, prefix).OutputTreeAntlrStyle(node).ToString());
+ }
+ if (config.ParenIndentStyle)
+ {
+ sb.AppendLine(new TreeOutput(lexer, parser, prefix).OutputTree(node).ToString());
+ }
+ if (config.IndentStyle)
+ {
+ sb.AppendLine(new TreeOutput(lexer, parser, prefix).OutputTreeIndentStyle(node).ToString());
+ }
}
System.Console.WriteLine(sb.ToString());
+ System.Console.WriteLine();
}
}
}
diff --git a/src/trtree/Config.cs b/src/trtree/Config.cs
index c019e57a6..b39ccf878 100644
--- a/src/trtree/Config.cs
+++ b/src/trtree/Config.cs
@@ -12,4 +12,10 @@ public class Config
[Option('a', "antlr-style", Required = false, HelpText = "Output tree as Antlr ToStringTree() style.")]
public bool AntlrStyle { get; set; }
+
+ [Option('i', "indent-style", Required = false, HelpText = "Output tree as plain indented style.")]
+ public bool IndentStyle { get; set; }
+
+ [Option("paren-indent-style", Required = false, HelpText = "Output tree as parenthesized indented style.")]
+ public bool ParenIndentStyle { get; set; }
}
diff --git a/src/trtree/Program.cs b/src/trtree/Program.cs
index 191f7a995..c7f4241e8 100644
--- a/src/trtree/Program.cs
+++ b/src/trtree/Program.cs
@@ -67,6 +67,7 @@ public void MainInternal(string[] args)
}
}
});
+ if (!(config.ParenIndentStyle || config.IndentStyle || config.AntlrStyle)) config.ParenIndentStyle = true;
new Command().Execute(config);
}
}
diff --git a/src/trtree/Properties/launchSettings.json b/src/trtree/Properties/launchSettings.json
index 3444d1613..88b6ba4da 100644
--- a/src/trtree/Properties/launchSettings.json
+++ b/src/trtree/Properties/launchSettings.json
@@ -2,8 +2,8 @@
"profiles": {
"trtree": {
"commandName": "Project",
- "commandLineArgs": "-f oo.pt",
- "workingDirectory": "c:\\msys64\\home\\Kenne\\useless-paren-check\\abb"
+ "commandLineArgs": "-f o.pt -a",
+ "workingDirectory": "C:\\msys64\\home\\Kenne\\issues\\g4-current\\java\\java20\\Generated-CSharp"
}
}
}
\ No newline at end of file
diff --git a/src/trtree/readme.md b/src/trtree/readme.md
index 916171174..47df779a2 100644
--- a/src/trtree/readme.md
+++ b/src/trtree/readme.md
@@ -18,7 +18,7 @@ Reads a tree from stdin and prints the tree as an indented node list.
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trtree/trtree.csproj b/src/trtree/trtree.csproj
index fa862718f..6d25fed41 100644
--- a/src/trtree/trtree.csproj
+++ b/src/trtree/trtree.csproj
@@ -18,7 +18,7 @@ This program is part of the Trash toolkit.
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trtree
git
diff --git a/src/trull/readme.md b/src/trull/readme.md
index 973bcfff9..aa20d3f7f 100644
--- a/src/trull/readme.md
+++ b/src/trull/readme.md
@@ -63,7 +63,7 @@ XPaths, type _export MSYS2_ARG_CONV_EXCL="*"_, then execute your command.
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trull/trull.csproj b/src/trull/trull.csproj
index 81e34b239..b1f82f636 100644
--- a/src/trull/trull.csproj
+++ b/src/trull/trull.csproj
@@ -18,7 +18,7 @@ This program is part of the Trash toolkit.
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trull
git
diff --git a/src/trunfold/Command.cs b/src/trunfold/Command.cs
index 6d391d0dc..e03eb0d58 100644
--- a/src/trunfold/Command.cs
+++ b/src/trunfold/Command.cs
@@ -70,7 +70,7 @@ public void Execute(Config config)
if (config.Verbose)
{
foreach (var n in trees)
- System.Console.WriteLine(TreeOutput.OutputTree(n, lexer, parser).ToString());
+ System.Console.WriteLine(new TreeOutput(lexer, parser).OutputTree(n).ToString());
}
org.eclipse.wst.xml.xpath2.processor.Engine engine = new org.eclipse.wst.xml.xpath2.processor.Engine();
@@ -105,7 +105,7 @@ public void Execute(Config config)
{
System.Console.Error.WriteLine("Final trees:");
foreach (var n in trees)
- System.Console.WriteLine(TreeOutput.OutputTree(n, lexer, parser).ToString());
+ System.Console.WriteLine(new TreeOutput(lexer, parser).OutputTree(n).ToString());
}
var tuple = new ParsingResultSet()
diff --git a/src/trunfold/readme.md b/src/trunfold/readme.md
index 1a6ced5c6..5fae343b9 100644
--- a/src/trunfold/readme.md
+++ b/src/trunfold/readme.md
@@ -51,7 +51,7 @@ XPaths, type _export MSYS2_ARG_CONV_EXCL="*"_, then execute your command.
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trunfold/trunfold.csproj b/src/trunfold/trunfold.csproj
index 1b11c3204..de175935c 100644
--- a/src/trunfold/trunfold.csproj
+++ b/src/trunfold/trunfold.csproj
@@ -18,7 +18,7 @@ in the parse tree. This program is part of the Trash toolkit.
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trunfold
git
diff --git a/src/trungroup/Command.cs b/src/trungroup/Command.cs
index 5726b2fbe..1e368e496 100644
--- a/src/trungroup/Command.cs
+++ b/src/trungroup/Command.cs
@@ -65,7 +65,7 @@ public void Execute(Config config)
if (config.Verbose)
{
foreach (var n in trees)
- System.Console.WriteLine(TreeOutput.OutputTree(n, lexer, parser).ToString());
+ System.Console.WriteLine(new TreeOutput(lexer, parser).OutputTree(n).ToString());
}
org.eclipse.wst.xml.xpath2.processor.Engine engine = new org.eclipse.wst.xml.xpath2.processor.Engine();
@@ -84,7 +84,7 @@ public void Execute(Config config)
{
System.Console.Error.WriteLine("Final trees:");
foreach (var n in trees)
- System.Console.WriteLine(TreeOutput.OutputTree(n, lexer, parser).ToString());
+ System.Console.WriteLine(new TreeOutput(lexer, parser).OutputTree(n).ToString());
}
var tuple = new ParsingResultSet()
diff --git a/src/trungroup/readme.md b/src/trungroup/readme.md
index 076af89a9..815fc0ad1 100644
--- a/src/trungroup/readme.md
+++ b/src/trungroup/readme.md
@@ -24,7 +24,7 @@ XPaths, type _export MSYS2_ARG_CONV_EXCL="*"_, then execute your command.
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trungroup/trungroup.csproj b/src/trungroup/trungroup.csproj
index f117d22f0..662884fbd 100644
--- a/src/trungroup/trungroup.csproj
+++ b/src/trungroup/trungroup.csproj
@@ -17,7 +17,7 @@ This program is part of the Trash toolkit.]]>
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trungroup
git
diff --git a/src/trwdog/readme.md b/src/trwdog/readme.md
index de67561b7..409be5b6b 100644
--- a/src/trwdog/readme.md
+++ b/src/trwdog/readme.md
@@ -18,7 +18,7 @@ Execute a command with a watchdog timer.
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trwdog/trwdog.csproj b/src/trwdog/trwdog.csproj
index 2195b11d7..056b93d41 100644
--- a/src/trwdog/trwdog.csproj
+++ b/src/trwdog/trwdog.csproj
@@ -19,7 +19,7 @@ This program is part of the Trash toolkit.
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trwdog
git
diff --git a/src/trxgrep/readme.md b/src/trxgrep/readme.md
index e9ad0de01..d7fe0859c 100644
--- a/src/trxgrep/readme.md
+++ b/src/trxgrep/readme.md
@@ -24,7 +24,7 @@ XPaths, type _export MSYS2_ARG_CONV_EXCL="*"_, then execute your command.
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trxgrep/trxgrep.csproj b/src/trxgrep/trxgrep.csproj
index 102b17f85..674659e1b 100644
--- a/src/trxgrep/trxgrep.csproj
+++ b/src/trxgrep/trxgrep.csproj
@@ -18,7 +18,7 @@ This program is part of the Trash toolkit.
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trxgrep
git
diff --git a/src/trxml/readme.md b/src/trxml/readme.md
index 6aa276ab3..b2e562ea2 100644
--- a/src/trxml/readme.md
+++ b/src/trxml/readme.md
@@ -18,7 +18,7 @@ Read a tree from stdin and write an XML represenation of it.
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trxml/trxml.csproj b/src/trxml/trxml.csproj
index 9ae0dbe75..3eaa9e6f5 100644
--- a/src/trxml/trxml.csproj
+++ b/src/trxml/trxml.csproj
@@ -17,7 +17,7 @@ This program is part of the Trash toolkit.]]>
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trxml
git
diff --git a/src/trxml2/readme.md b/src/trxml2/readme.md
index 0676b9f76..78838a8ad 100644
--- a/src/trxml2/readme.md
+++ b/src/trxml2/readme.md
@@ -18,7 +18,7 @@ Read an xml file and enumerate all paths to elements in xpath syntax.
## Current version
-0.23.4 Add scripts for syntactic highlighting as default for trgenvsc.
+0.23.5 Add --ambig option to trparse. Add file names to trtree. Add new output styles for trtree. Update packages for trgenvsc templates.
## License
diff --git a/src/trxml2/trxml2.csproj b/src/trxml2/trxml2.csproj
index bf7b50bba..3cb8c2985 100644
--- a/src/trxml2/trxml2.csproj
+++ b/src/trxml2/trxml2.csproj
@@ -17,7 +17,7 @@ This program is part of the Trash toolkit.]]>
true
portable
true
- 0.23.4
+ 0.23.5
https://github.com/kaby76/Trash/tree/main/src/trxml2
git