First D project, problem with error messages

Daniel d at gmail.com
Thu Feb 9 19:37:44 UTC 2023


         So I finally decided to start my first project using the 
D language. So far it feels very clean, but I'm having problems 
with error messages that don't seem to point to the problematic 
place and syntax element. My setup is DMD 2.102 and VSCode with 
Code-d plugin. For example:
     ```d
     module lexer;

import std.stdio;
import token;

class Lexer() {

     	string sourceText;
     	char currentChar;
     	int charIndex;
     	int line;
     	int column;

         this(string sourceText) {
             this.sourceText = sourceText;
             this.currentChar = '';
             this.charIndex = 0;
             this.line = 1;
             this.column = 1;
         }
     ```
         Here, the word module is underlined in red and the 
message I get is "Primary expression expected (DScanner)". The 
solution is to write a character between the single quotes in the 
assignment to this.currentChar. (Saving and previewing this post 
shows an error at the place of the single quotes, but this is not 
the case in VSCode). I have already fixed a couple of similar 
errors with comparably puzzling messages.

         Now I am stuck with this:
     ```d
     module dpl0c;

import std.stdio;
import lexer;

enum VERSION = "0.0.1";

     void main(string[] args) {
         writefln("\nThe D PL0 Compiler %s", VERSION);

         string sourceText = "Hello, World!";
         Lexer lex = new Lexer(sourceText);
         lex.sayHello();
     }
     ```
     > dmd dpl0c.d lexer.d token.d
     dpl0c.d(12): Error: template class `lexer.Lexer()` is used as 
a type without instantiation; to instantiate it use 
`Lexer!(arguments)`

         Of course new Lexer!(sourceText); doesn't solve the 
problem. Googling the error messages has been of little to no use 
so far. So I'm having a hard time getting used to the language 
features.
         However puzzling, it feels better than C/C++ anyway.

Daniel


More information about the Digitalmars-d mailing list