schemelispracketdr.racket

show errors, creating a programming language in racket


I am creating a programming language in Racket, I am currently using ragg, I was reading the guide of Danny Yoo Guide Danny Yoo Ragg, I define a grammar, for example

#lang ragg
nested-word-list: WORD
            | LEFT-PAREN nested-word-list* RIGHT-PAREN

I use the funcion parse by passing tokens,

#lang racket


(require ragg/support)
(require "nested-word-list.rkt")

(define a-parsed-value
    (parse (list (token 'LEFT-PAREN "(")
             (token 'WORD "some")
             (token 'LEFT-PAREN "[")
             (token 'WORD "pig")
             (token 'RIGHT-PAREN "]")
             (token 'RIGHT-PAREN ")"))))

a-parsed-value

I know that function generated a Syntax Object that I don't know what is that.

If I pass some tokens invalids like these

#lang racket


(require ragg/support)
(require "nested-word-list.rkt")

(define a-parsed-value
     (parse (list (token 'WORD "some")
             (token 'LEFT-PAREN "[")
             (token 'WORD "pig")
             (token 'RIGHT-PAREN "]")
             (token 'RIGHT-PAREN ")"))))

a-parsed-value

It generates an error like this

   Encountered parsing error near token 'LEFT-PAREN ("[") while parsing #f    [line=#f, column=#f, offset=#f]

I want to know how it could generate errors, for example, for the previous case that the output shows "ERROR: MISSING BRACKET" and this for every error that may occur.

Note: For example, I use a simple grammar, but really, my original grammar is a language like Java


Solution

  • It sounds like you're asking how to improve or modify the error messages generated by ragg. I believe that once you add a real lexer (in the following sections of the documentation) you'll get good source location information for the errors.

    Beyond this, I think I would urge you to ... worry about other things? I don't know exactly what degree of customization ragg allows for error message generation, but that seems outside of the scope of a tool like ragg.