Skip to content

Generating strings with Instaparse #82

@zmaril

Description

@zmaril

I'm interested in generating strings with instaparse. By this, I mean I'd like to give instaparse a data structure to fill in and a grammar and have it return to me strings that could parse to something that would parse to the given data structure. We use instaparse a good deal in ECHELON and I'd like to use test.check to generate data for testing. I'm still learning how the QuickCheck style libraries work, but I think if we could generate strings via instaparse we could use test.check without too much trouble. I'm happy to develop this myself (and will continue to explore further), but I wanted to check in first to see if it is possible (or has already been quietly done).

For clarification, I'd like a function that does something akin to the following:

(def grammar
  (insta/parser
   "S = name ' ' business
    name = 'Steve' | 'Mary' | 'Bob'
    business = 'Bakery' | 'Shop'"))

(grammar "Steve Shop")
(def grammar
  (insta/parser
   "S = name ' ' business
    name = 'Steve' | 'Mary' | 'Bob'
    business = 'Bakery' | 'Shop'"))

(grammar "Steve Shop")

(insta/generate [:S [:name] [:business]])
;;;[:S [:name "Steve"] " " [:business "Shop"]]

(insta/generate [:S [:name] [:business]])
;;["Steve Bakery" "Steve Shop" "Mary Bakery" "Mary Shop" "Bob Bakery" "Bob Shop"]

I suppose I'd like to give instaparse a partial data structure corresponding to a "skeleton" of a parse tree and have it generate data to fill in the rest of the tree. I haven't thought through how this would play with transformations and the hiding of tags in instaparse yet. Does this seem possible? Is it a dumb thing to ask for?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions