addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscontroller-playcrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobegmailgooglegroupshelp-with-circleimageimagesinstagramFill 1light-bulblinklocation-pinm-swarmSearchmailmessagesminusmoremuplabelShape 3 + Rectangle 1ShapeoutlookpersonJoin Group on CardStartprice-ribbonprintShapeShapeShapeShapeImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruserwarningyahoo

External DSLs

Last month, we got through (painfully) our investigation of internal DSLs with that sweet, sweet syntactic sugar. This time, let's finish up our overview of DSLs by taking a look at the rest of the story: external DSLs using parser combinators!

Join or login to comment.

  • Todd F.

    Dave was right that it's cleaner to use the parser to handle quoted strings, rather than creating a helper method to strip quotes. An example:

    class ConfigTokenParser extends JavaTokenParsers {
    def stringValue: Parser[String] = "\"" ~> ("""([^"\p{Cntrl}\\]|\\[\\'"bfnrt]|\\u[a-fA-F0-9]{4})*""").r <~ "\""
    def nvPair: Parser[(String, Any)] = ident ~ "=" ~ stringValue ^^ {case name ~ "=" ~ value => (name, value)}
    } val parser = new ConfigTokenParser describe("name value pair tests") {
    it("should parse a string value") {
    val result = parser.parseAll(parser.nvPair, """ name = "value" """)
    println(result)
    result.successful should be (true)
    result.get should be (("name", "value"))
    } }

    November 25, 2013

  • Richard Alexander G.

    I learned a thing or two.

    November 21, 2013

  • David B.

    Thanks for the presentation Todd, very informative and enjoyable!

    1 · November 20, 2013

  • Wen Cheng L.

    Thanks Todd. I am feeling sick, so I won't go tonight.
    Nathan thanks again for your effort on this, could we postpone this DSLs overview to next meeting when you are around?

    November 20, 2013

    • Todd F.

      I hope you rest up and feel better soon, Wayne. Let me know if you work through the exercise by yourself. I'm hoping that it's possible to follow, since you can always cheat and look at the solution for each step.

      November 20, 2013

  • Richard Alexander G.

    I'll be there.

    November 20, 2013

  • Nathan D.

    I've got to cover a class for someone else at work tonight. Do you guys think you'll be able to hold a meeting without me? The discussion material was to be from Programming Scala, 2nd half of Chapter 11, and I believe Todd had some material for an exercise.

    Can anyone step up and lead tonight for me? :)

    November 20, 2013

    • Todd F.

      Sure. We can pair and randori on test-driving a JSON parser. I'll post the github URL for the exercise shortly.

      November 20, 2013

    • Nathan D.

      You guys are awesome. Thanks!

      November 20, 2013

  • Todd F.

    If you want to get started early, here is the project we will walk through: https://github.com/tflander/scalaJsonDsl

    You need SBT installed. I'll be using eclipse. There are 12 steps to completing this exercise. I hope to rotate pairs to complete each step. The pair consists of a driver and a navigator. When the step is complete, the navigator becomes the new driver, and the old driver chooses a new navigator.

    Cheating is allowed. You can look at branches 0-12 from github to see how the exercise progresses. Lets do this and have fun.

    November 20, 2013

10 went

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy