1

I have the beginnings of a new programming language I'm working on, which uses "trees" of lowercased terms (separated by dashes for multi-word terms). The punctuation and everything can be seen from these two examples:

enter image description here enter image description here

That is:

  • Strings are with angle brackets <I am a string>.
  • Strings can have interpolation like <I am {variable}>.
  • Interpolation can be nested even <I am {bold(<Some {variable} text>)}>
  • There are numbers
  • There are terms
  • Terms can be interpolated some-{interpolated}-term

Otherwise, things form into a simple tree.

There are many kinds of structures you can define, like classes, functions, and other things. For this question I will keep it narrow and focus on just one of them, the function definition (called "task" in the lingo).

Here is an example task/function:

task find-fibonacci-via-loop
  # "take" is an input
  take i, form natural-number
  # "free" is the return type
  free natural-number

  # declares/saves a variable
  save g, size 0
    flex true

  save o, size 1
    flex true

  save d
    flex true

  # loops
  walk test
    # loop condition
    hook test
      test is-gt
        loan i
        text 0
    # loop step
    hook tick
      save d, move o
      save o
        # function call
        call add
          # function inputs
          loan g
          loan d
      save g, move d
      save i
        call decrement
          loan i

  # return result
  back g

I am working on implementing error handling for this code, which is still fuzzy to me how it should work. Basically it should be kind of like Rust language and highlight the part of code that has the error.

enter image description here

But I'm just not sure what to highlight exactly. There are a lot of cases and things you might want to highlight, so I will try and keep it narrow and focus on a basic case or two. First case demos kind of what I'm talking about / wondering.

The simple case is if the call add (a function call to "add" function) is not imported, that is, it is an invalid/unknown reference. What should I highlight there? Should I center on the call add line, plus 2 or 3 lines above and below, and that's it? Actually I don't think you can show the context lines above/below, because you need that space to show the error. Something like this:

Error: Unknown task `add` referenced.

save d, move o          [in gray]
save o                  [in gray]
  # function call       [in gray]
  call add              [in black, to bring more focus]
  ~~~~~~~~              [in red]

Line: 123:8
File: ./path/to/fibonacci.code

How does that look/seem?

Now say the call add only had one parameter passed, like:

call add
  loan g
  # missing loan d

What should it do there? Not worried about what the error text says, just what it should show in terms of code.

Error: The call to `add` is missing second input.

save d, move o          [in gray]
save o                  [in gray]
  # function call       [in gray]
call add                [in black]
  loan g                [in black]
  ~ missing input ~     [in red]

Line: 123:8
File: ./path/to/fibonacci.code

Am I on the right track? Or how how would you handle this in a better UX way. Basically printing textual errors like in the Terminal app.

1 Answer 1

0

Have you looked in detail how other languages report errors? What type of error are you trying to detect (run time, syntax, compile time)? What main stream languages are your target users most familiar with and can you adopt error reporting style from that? I would do more research as this is a very broad question currently.

At the basic level, any programming environment should provide users:

  1. Line Number were the error occurred
  2. Meaningful error message
  3. Full Stack trace (for run time errors, crashes)

If you can highlight the part of the code in the terminal window that would be ideal as it will help users quickly detect the bug. Generally terminal provides limited GUI controls so for DSL's syntax highliting is tricky, case in point YAML formatting error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.