Coder Social home page Coder Social logo

clarsec's Introduction

clarsec

clarsec is an attempt to port haskell parsec to clojure

This library is inspired on http://kotka.de/projects/clojure/parser.html and uses the Meikel Brandmeyer's "monad" library (slightly adapted), as I didn't understand how the clojure contrib monad library works.

Usage

there is an example parser which I ported straight from a Haskell Parsec code.

Basically, you should be able to write the examples on http://kotka.de/projects/clojure/parser.html.

The library comes with a small number of basic combinators. I hope it will be useful.

Caveats

forward references are a mess. I tried to maintain the DSL as simple as possible. Imagine that "structureDef" and "comma" are two already existing parsers, and "brackets" and "sepBy" are two combinators. I want to be able to write it like this:

(def structure (brackets (sepBy structureDef comma)))

however, clojures 'def' binding is strict and all the referenced vars have to be already defined, otherwise you get:

Var example/structureDef is unbound.

I'm a clojure newbie, so I don't know exactly how to avoid this. I know only of two workarounds:

  1. use functions: (defn structure [] (brackets (sepBy (structureDef) (comma))))
  2. use delay: (def structure (delay (brackets (sepBy structureDef comma))))

I opted for delay, as it allowed me to avoid all those spurious parens, and retain the illusion of a parser DSL, and put the "delay" only where needed. (or everywhere with a "defblabla" macro).

Unfortunately this required a small patch to Brandmeyer's monad library.

Installation

lein jar

License

http://www.apache.org/licenses/LICENSE-2.0.html

clarsec's People

Contributors

devn avatar thachmai avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.