BoundaryML / baml

BAML is a templating language to write typed LLM functions. Check out the promptfiddle.com playground
https://docs.boundaryml.com
Apache License 2.0
936 stars 23 forks source link

First line of an array cannot be a comment #777

Closed anish-palakurthi closed 2 weeks ago

anish-palakurthi commented 1 month ago

Surface better error or fix Pest grammar to allow this

greptile-apps[bot] commented 1 month ago

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](https://app.greptile.com/chat/github/boundaryml/baml/canary) ยท [Edit Issue Bot Settings](https://app.greptile.com/apps/github)