Hello,
First, I am not very experimented with the combination of static lang (alloc &
typing) and OO (class-based). I'm implementing a library for lexical analysis
(lexing), with 2 minor issues:
-1- How to enforce that subclasses implement given methods without using
"abstract", which seems to make the whole class abstract? (no info found in doc,
actually, the page on classes [1] does not seem to even mention abstract classes)
-2- How to have "constant" (predefined) class instances at the module-level? The
compiler requires a "static this ()". What does this actually mean (for a
constructor)? What are the consequences, for either my code or client code? (The
doc on the topic [2] is rather obscure for me, and I could not find better
elsewhere.)
I'm also bluffed by "Static constructors have empty parameter lists." Does this
mean I should manually fill the fields? (not a big deal, but why???) This may give:
// Predefined pseudo-pattern "End-of-Text":
auto EoT = new Pattern() ; // ???
EoT.name = "EoT" ;
// Unique lexeme "end-of-text":
auto eot = new Lexeme() ; // ???
eot.patname = "EoT" ;
eot.slice = null ;
eot.index = uint.max ;
Then, why have a constructor at all? This would also prevent me from making
classes immutable, while conceptually all are immutable... (no reason for a
pattern or a lexeme to change)
Thank you,
diniz
[1] https://dlang.org/spec/class.html
[2] https://dlang.org/spec/class.html#static-constructor