Utodev / DRC

A new compiler for DAAD adventure writer. For ZX Spectrum, Commodore 64, Amstrad CPC and PCW, MSX, MSX2, MSDOS, Amiga, Atari ST and HTML.
GNU General Public License v3.0
23 stars 8 forks source link

Compiler error line numbers in #include files #27

Closed anoriangit closed 3 years ago

anoriangit commented 3 years ago

Currently the compiler prints global line numbers for errors in #included files (i.e the number that the line has in the overall file after including it). That makes it virtually impossible to navigate to the error line inside the included file itself. It would be great if the "local" line number in the included file could be printed too if possible.

Utodev commented 3 years ago

In version 0.20 there is detailed reponse for errors in include file, unless is a lexer error, which means something totally unexpected is found.

For instance:

/PRO 6 ; Initialise the DAAD system

#include include.txt

and content of include.txt is:

; this is a test 

>TAKE ALL
 MEASGE "asdasd"
 DONE

(notice MESSAGE is misspelled)

When compiling you see:

Reading BLANK_EN.DSF
Checking Syntax...
4:7:include.txt: Unknown condact: "MEASGE".

Sadly, if the problem is a unknown token is found by the parser, for instance if include file is

Content of include.txt
; this is a test 

>TAKE ALL
 MEASGE "asdasd"
 DONE

In this case that "Content of include.txt" is missing the semicolon at the beginning to show it's a comment, and so, the parser tries to recognize it as tokens, getting two tokens recognized as identifiers "Content" and "of", and then something it's not a token (there parser doesn't know what an unquoted string with a dot in the middle is). In that case, it's a lexer error, and the lexer doesn't know about include files, so the error is reported in the global file number.

I can try to check if that can be fixed (there is a chance it can be fixed), but in general, you should be receiving already proper messages if you are using latest version.

Is that the case?

If you are using v 0.20 but you still have problems with error messages, may you please provide more detailed information?

Thanks

anoriangit commented 3 years ago

Hi Uto Many thanks for the quick reply! Using 0.20 from your latest "DAAD Ready" release.

It does report the proper "local" line number (the line number in the included file itself) for things like missing nouns for example:

DAAD Reborn Compiler Frontend 0.20 (C) Uto 2018-2021 Reading tg.dsf Checking Syntax... 5:14:tg_pro5.dsf: Noun not found in vocabulary: "BEDO". <<<<<<<<<< This is the correct "local" line number

but not for some things (like typos, or when I copy&paste your tutorial code from medium.com, where some of the quotation marks come out weird when copied&pasted). In those cases it reports the global line number (the line number the error line has after being inserted in the overall temp file)

DAAD Reborn Compiler Frontend 0.20 (C) Uto 2018-2021 Reading tg.dsf 573:26: Unexpected character. <<<<<<<< this should be "9:17:tg_pro5.dsf

I realize that these errors seem to be detected at some later stage (after you've already merged all the include into one file) and hence probably don't have the original (local) line number anymore, so it might be hard to fix.

Its not a big problem really (for now I just went back to using bookmarks in VS Code for quickly navigating to sections instead of breaking them out into separate files)

Utodev commented 3 years ago

Yes, that "unexpected character" was the only message that was not providing the proper line number. Please notice I say "was" because I already fixed it, and pushed the changes to repository. If you know how to compile it just get the source code for drf.exe from this repository. If not, stay tuned, because it won't be today but I will publish new releases of Maluva and DRC prety soon.

anoriangit commented 3 years ago

Hi Uto

UPDATE: can confirm it works with latest github source.

Gerhard

Utodev commented 3 years ago

Closing this issue. Thanks for the input.