Is it possible to set/override the name of the source file when piping it into DMD via stdin?
H. S. Teoh
hsteoh at qfbox.info
Wed Dec 13 19:58:42 UTC 2023
On Wed, Dec 13, 2023 at 07:37:09PM +0000, Siarhei Siamashka via Digitalmars-d-learn wrote:
> Example:
>
> ```D
> import std;
> void main() {
> deliberate syntax error here
> }
> ```
>
> ```bash
> $ cat example.d | dmd -run -
> __stdin.d(3): Error: found `error` when expecting `;` or `=`, did you mean
> `deliberate syntax = here`?
> __stdin.d(3): Error: found `}` when expecting `;` or `=`, did you mean
> `error here = End of File`?
> ```
>
> Now I'm curious. Is it possible to somehow communicate the real source
> file name to `dmd`, so that it shows up in the error log instead of
> "__stdin.d"?
Add a module declaration to your source file. For example:
echo 'module abc; import std; void main(){writefln(__MODULE__);}' | dmd -run -
Output:
abc
`__stdin` is used as a placeholder when no module declaration is
present, and dmd doesn't know the filename (which is what it would
normally have used for the module name in this case).
T
--
Век живи - век учись. А дураком помрёшь.
More information about the Digitalmars-d-learn
mailing list