thesephist / tabloid

A minimal programming language inspired by clickbait headlines

Home Page:https://tabloid.vercel.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

More helpful error messages

Eiim opened this issue · comments

Alternate title: YOU WON'T BELIEVE THESE CRAZY ERROR MESSAGES FROM A REAL DEVELOPER!

When I'm doing my normal, everyday Tabloid coding (thanks for the input function btw!), I often run into issues that I simply can't seem to debug. Why? Well, because lots of my Tabloid code seems to have syntax errors of some kind, and the output given simply doesn't help. For example:

EXPERTS CLAIM D TO BE 1
DISCOVER HOW TO F WITH V
    WHAT IF D IS ACTUALLY 1
        SHOCKING DEVELOPMENT 0
    EXPERTS CLAIM D TO BE D MINUS 1
    SHOCKING DEVELOPMENT F OF 1
EXPERTS CLAIM O TO BE F OF 1
YOU WON'T WANT TO MISS O
PLEASE LIKE AND SUBSCRIBE

errors with TypeError: node.exprs is undefined. However, if D is set to be 2 at the start, the error changes to [object Object], which I am fairly certain is not the intended error message. Another one that doesn't make sense to me:

DISCOVER HOW TO func WITH param
    EXPERTS CLAIM var TO BE param
    WHAT IF var IS ACTUALLY 1
        SHOCKING DEVELOPMENT 1
    SHOCKING DEVELOPMENT 0

PLEASE LIKE AND SUBSCRIBE

gives Error: Runtime error: Undefined variable "var", despite var being declared in the function, and the function never being run.

I would recommend making the erroring system more robust and/or adding some kind of debugging function (perhaps WHAT'S GOING ON?) that provides more verbose error messages to help figure out what the issue is. Alternatively, adding line numbers to errors may be enough to figure out what's going on in most cases, although I'm not sure if that's feasible post-preprocessing.

Also, if you happen to know what any of the above problems happen to be, I'd love to know.

So... this is where I expected no sane person to actually try to write anything in Tabloid, so I didn't care to add in any error messages, haha.

My first response is that the error in both those examples are the same: Tabloid is not whitespace-sensitive, so you indicate multi-line (multi-expression) blocks by wrapping them in RUMOR HAS IT...END OF STORY (a block scope).

So for example, your example 1 works if we write instead

EXPERTS CLAIM D TO BE 1
DISCOVER HOW TO F WITH V
RUMOR HAS IT
    WHAT IF D IS ACTUALLY 1
        SHOCKING DEVELOPMENT 0
    EXPERTS CLAIM D TO BE D MINUS 1
    SHOCKING DEVELOPMENT F OF 1
END OF STORY

EXPERTS CLAIM O TO BE F OF 1
YOU WON'T WANT TO MISS O
PLEASE LIKE AND SUBSCRIBE

My second response is that I don't really intend on adding a bunch of debugging facilities to Tabloid as-is because... well it's not meant for writing real programs. That said, I think the language implementation is pretty simple and readable if you want to be adventurous and add some error-throwing logic with more helpful messages where errors are detected.

I wrote this language in a hurry so the parser doesn't keep track of span information (which we need to report line numbers with errors). To add it I think would be a nontrivial task, even for me.

I am curious what you're trying to make with this though 👀

Sounds good! I might fork it and look into writing some error-throwing logic myself. Thanks for your answer as well.

As for what I'm trying to make with it, those came up as I was working on a primality checking program, so that it would count as a valid language for PPCG. After that, it could potentially be used for some challenges, with its output constraints making it... very interesting to work with.

Gonna close this due to inactivity; if you or anyone else ends up working on it, do reopen:)