More than one entry to the grammar gives unclear error message #38

Closed
opened 2 years ago by tbmreza · 1 comments
tbmreza commented 2 years ago (Migrated from github.com)

For example:

; x.rkt
#lang racket

(require brag/support)
(require "./parser.rkt")

(define tkns (list "?"))
(syntax->datum (parse tkns))

; parser.rkt
#lang brag

<order-matters>  : "?"
<literal>        : '"' <TEXT> '"' | "'" <TEXT> "'"

gives:

'(<order-matters> "?")

If I reorder the rule to last, it cries.

; parser.rkt
#lang brag

<literal>        : '"' <TEXT> '"' | "'" <TEXT> "'"
<order-matters>  : "?"
Encountered parsing error near "?" (token '?) while parsing 'unknown [line=#f, column=#f, offset=#f]
  location...:
   unknown
  context...:
   /path/to/Library/Racket/8.4/pkgs/brag-lib/brag/private/internal-support.rkt:16:3
   /path/to/Library/Racket/8.4/pkgs/brag-lib/brag/codegen/expander.rkt:82:23: rule-parser
   /path/to/x.rkt:7:0
   body of "/path/to/x.rkt"

Is this expected?

For example: ```rkt ; x.rkt #lang racket (require brag/support) (require "./parser.rkt") (define tkns (list "?")) (syntax->datum (parse tkns)) ; parser.rkt #lang brag <order-matters> : "?" <literal> : '"' <TEXT> '"' | "'" <TEXT> "'" ``` gives: ``` '(<order-matters> "?") ``` If I reorder the rule to last, it cries. ```rkt ; parser.rkt #lang brag <literal> : '"' <TEXT> '"' | "'" <TEXT> "'" <order-matters> : "?" ``` ``` Encountered parsing error near "?" (token '?) while parsing 'unknown [line=#f, column=#f, offset=#f] location...: unknown context...: /path/to/Library/Racket/8.4/pkgs/brag-lib/brag/private/internal-support.rkt:16:3 /path/to/Library/Racket/8.4/pkgs/brag-lib/brag/codegen/expander.rkt:82:23: rule-parser /path/to/x.rkt:7:0 body of "/path/to/x.rkt" ``` Is this expected?
mbutterick commented 2 years ago (Migrated from github.com)

Yes, this is the documented behavior of parse: "Parses a series of tokens according to the rules in the grammar, using the first rule of the grammar for the initial production".

Yes, this is the documented behavior of [`parse`](https://docs.racket-lang.org/brag/#%28def._%28%28lib._brag%2Fmain..rkt%29._parse%29%29): "Parses a series of [tokens](https://docs.racket-lang.org/brag/#%28tech._token%29) according to the rules in the grammar, **using the first rule of the grammar for the initial production**".
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: mbutterick/brag#38
Loading…
There is no content yet.