D lexer, parser, and ImportC parser are now standalone
Andrej Mitrovic
andrej.mitrovich at gmail.com
Mon Apr 10 12:17:26 UTC 2023
On Monday, 10 April 2023 at 02:02:49 UTC, Walter Bright wrote:
> I've finally managed to sever its dependencies on the rest of
> the compiler. You can now build a standalone lexer, or a
> standalone D parser, or a standalone ImportC parser.
Appreciate the effort!
From my brief attempts I've ran into a few problems:
- `Parser` requires `ErrorSink` in its constructor, but
`dmd.errorsink` is not in DMD's `dub.sdl`. So using `Parser`
directly doesn't seem to work (errorsink module not found). Maybe
it's an easy fix to dub.sdl..?
- On Linux I'm getting linking errors. While on Windows I get a
segfault. Probably because I am missing some important
initialization somewhere.
-----
import std.stdio;
import dmd.dmodule;
import dmd.identifier;
import dmd.location;
void main()
{
auto mod = new Module(`C:\DMD\dmd2\src\phobos\std\file.d`,
new Identifier("file"), false, false);
auto loc = Loc("app.d", 0, 0);
if (!mod.read(loc))
assert(0, "can't read");
}
-----
Linux:
-----
Linking dparser
/usr/bin/ld:
/home/drey/.dub/cache/dmd/~master/+lexer/build/library-debug-linux.posix-x86_64-dmd_v2.102.0-9CFF4D64344FD218B941F4DE6FAF1B94F5E5640E5F33D1921150D7105AD91F2E/libdmd_lexer.a(errors_66_6da.o):(.data._D3dmd6errors17ErrorSinkCompiler7__ClassZ+0x50): undefined reference to `_D3dmd9errorsink9ErrorSink7__ClassZ'
/usr/bin/ld:
/home/drey/.dub/cache/dmd/~master/+lexer/build/library-debug-linux.posix-x86_64-dmd_v2.102.0-9CFF4D64344FD218B941F4DE6FAF1B94F5E5640E5F33D1921150D7105AD91F2E/libdmd_lexer.a(errors_88_732.o): in function `_D3dmd6errors18colorHighlightCodeFNbKSQBk6common9outbuffer9OutBufferZv':
/home/drey/.dub/packages/dmd-master/dmd/compiler/src/dmd/errors.d:832: undefined reference to `_D3dmd9errorsink13ErrorSinkNull7__ClassZ'
-----
On Windows it segfaults somewhere in `StringTable` on an invalid
pointer, so probably something needs to be initialized.
But the real problem here is the lack of documentation, or a lack
of examples of how to use these classes outside of the compiler
itself.
It would be nice to have a very minimal sample dub project that
uses these Module / Parser classes.
More information about the Digitalmars-d
mailing list