Skip to content

More default parsers? #21

@sjl

Description

@sjl

Hey, I've been using the Parsatron in another project lately and came up with a few pretty basic parsers that might be useful to other people. If you want them I can send a pull request that adds them, some tests, and some documentation for them:

(defparser optional [p]
  (either (attempt p)
          (always nil)))

(defparser separated1 [p separatorp]
  (let->> [fst p
           rst (many (>> separatorp p))]
    (always (concat [fst] rst))))

(defparser separated [p separatorp]
  (let->> [result (optional (separated1 p separatorp))]
    (always (if (nil? result)
              []
              result))))

It's possible there's an easier way to do these and I just missed it, in which case let me know!

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