baml
baml copied to clipboard
First line of an array cannot be a comment
Surface better error or fix Pest grammar to allow this
To address the issue where the first line of an array cannot be a comment, follow these steps:
- Update Pest Grammar: Modify the
datamodel.pestfile to allow comments at the start of arrays.
array = { "[" ~ (whitespaces? ~ comment_block ~ whitespaces? ~ value ~ ("," ~ value)*)? ~ "]" }
- Adjust JSON Parsing Logic: Update the
json_parse_state.rsfile 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.