Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ Code insertion using antlr and the line directive
    text
    copied!<p>I am using antlr to translate a custom language to C++ code. In this language, user can embed C++ code snippets between <code>$code...$endcode</code> directives, that gets inserted into the translated C++code as-is.</p> <p>I have the following problem: When there is an error in the code snippet I would like the compiler to point to the source file rather than the translated C++ code.</p> <p>I tried using line directives as follows, but it didn't work:</p> <pre><code>"foo.custom_laguage" 1 $code 2 ...some c++ code... 3 $endcode </code></pre> <p>gets translated to </p> <pre><code>"auto-generated.cpp" 42 #line 2 "foo.custom_language" 43 ...some c++ code... 44 #line __LINE__ __FILE__ </code></pre> <p>This doesn't work, I think because #line directive modifies what gets written by the <code>__LINE__</code> macro later. How can I set line number back to the <em>actual</em> line number in the translated C++ code? How does antlr do this? </p> <p>Here is what I want the auto-generated code to look like:</p> <pre><code>"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 ... </code></pre> <p><strong>edit:</strong> I just found out that there is a way to do this in C# language by using a <code>#line default</code> directive: <a href="http://msdn.microsoft.com/en-us/library/34dk387t.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/34dk387t.aspx</a> But couldn't find anything similar for C++</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload