Git Product home page Git Product logo

parsermacros's Introduction

Parser Macros (WIP) Build Status

This repository holds a Scala compiler plugin that will bring parser macros to Scala. This plugin is still a work in progress.

Building and using the plugin

The plugin is not yet published anywhere. You will need to clone this repository and build the plugin yourself. Fortunately, it's pretty straightforward to do using sbt:

$ git clone [email protected]:Duhemm/parsermacro.git
$ cd parsermacro
$ sbt cmp test

You can place your macro implementations in sandbox-macros/ and your macro clients in sandbox-clients/.

Using the plugin in the Scala REPL

This plugin can also be used directly in the Scala REPL after you've built it. To build a self-contained JAR that includes this plugin among with its dependencies (scala.meta), the best is to use sbt:

$ sbt cmp

This will produce a fat JAR in plugin/target/scala-2.11/fat-plugin.jar. To start a Scala REPL with the plugin loaded, simply run:

$ scala -Xplugin:plugin/target/scala-2.11/fat-plugin.jar -cp plugin/target/scala-2.11/fat-plugin.jar

You can then start having fun with parser macros !

Welcome to Scala version 2.11.6 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_31).
Type in expressions to have them evaluated.
Type :help for more information.

scala> import scala.meta._
import scala.meta._

scala> def impl(t: Seq[Token]): Tree = internal.ast.Lit.Int(t.size)
impl: (t: Seq[meta.Token])scala.meta.Tree

scala> def count: Int = macro impl
defined term macro count: Int

scala> count#(Hello, world!)
res0: Int = 7

parsermacros's People

Contributors

duhemm avatar roman0yurin 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.