-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Open
Description
I was reading a post in Reddit for parsing C and understanding declarations like void (*(*f[])())();. I tried to do trparse -i 'void (*(*f[])())();', but I noticed that I'm getting an empty tree. This is due to a bug in the code that reads command-line input strings. The fix is very simple, e.g., for CSharp:
diff --git a/c/CSharp/CLexerBase.cs b/c/CSharp/CLexerBase.cs
index b35100c57..3f20bbe97 100644
--- a/c/CSharp/CLexerBase.cs
+++ b/c/CSharp/CLexerBase.cs
@@ -50,7 +50,7 @@ public abstract class CLexerBase : Lexer
File.WriteAllText(output_name, x1);
return CharStreams.fromString(x1);
}
- File.WriteAllText(output_name, x1);
+ if (source_name == "stdin.c") File.WriteAllText(source_name, x1);
if (gcc)
{
Essentially, when a string input is used, the string should be output to "stdin.c", rather than "stdin.c.p", because the preprocessor needs to be applied to the string first. If stdin.c is empty, the parse is for an empty file. The fix should be applied across targets.
Metadata
Metadata
Assignees
Labels
No labels