baml icon indicating copy to clipboard operation
baml copied to clipboard

First line of an array cannot be a comment

Open anish-palakurthi opened this issue 1 year ago • 1 comments

Surface better error or fix Pest grammar to allow this

anish-palakurthi avatar Jul 11 '24 20:07 anish-palakurthi

To address the issue where the first line of an array cannot be a comment, follow these steps:

  1. Update Pest Grammar: Modify the datamodel.pest file to allow comments at the start of arrays.
array = { "[" ~ (whitespaces? ~ comment_block ~ whitespaces? ~ value ~ ("," ~ value)*)? ~ "]" }
  1. Adjust JSON Parsing Logic: Update the json_parse_state.rs file to handle comments at the start of arrays.
// In json_parse_state.rs, modify the logic to handle comments at the start of arrays
if let Some(JsonCollection::Array) = self.collection_stack.last() {
    if let Some(JsonCollection::TrailingComment | JsonCollection::BlockComment) = self.collection_stack.get(self.collection_stack.len() - 2) {
        // Handle the comment appropriately
    }
}

These changes should allow comments to be the first line in an array and provide better error handling.

References

/engine/baml-lib/prompt-parser/src/parser/datamodel.pest /engine/baml-lib/jsonish/src/jsonish/parser/fixing_parser

About Greptile

This response provides a starting point for your research, not a precise solution.

Help us improve! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

Ask Greptile · Edit Issue Bot Settings

greptile-apps[bot] avatar Jul 11 '24 20:07 greptile-apps[bot]