I am using antlr to translate a custom language to C++ code.
In this language, user can embed C++ code snippets between $code...$endcode
directives, that gets inserted into the translated C++code as-is.
我有一个问题:当代码片断有错误时, 我希望编译者指出源文件, 而不是翻译的 C++ 代码 。
我尝试了使用线性指令如下, 但它不起作用:
"foo.custom_laguage"
1 $code
2 ...some c++ code...
3 $endcode
翻译到
"auto-generated.cpp"
42 #line 2 "foo.custom_language"
43 ...some c++ code...
44 #line __LINE__ __FILE__
这不起作用, 我想是因为 #line 指令会修改 LINE/code> 宏的写法。 我如何才能将行号设置回翻译的 C++ 代码中的 < em> actual em> 行号? Antlr 如何这样做?
以下是我要自动生成的代码 看起来像:
"auto-generated.cpp"
42 #line 2 "foo.custom_language"
43 ...some c++ code...
44 #line 44 "auto-generated.cpp" //actual line in this file
45 ..some more C++ code ...
edit: I just found out that there is a way to do this in C# language by using a #line default
directive:
http://msdn.microsoft.com/en-us/library/34dk387t.aspx
But couldn t find anything similar for C++