https://github.com/dk14/typed-template
this macro generates parsers from specified grammars
https://github.com/dk14/typed-template
ast grammar macros parse scala
Last synced: 25 days ago
JSON representation
this macro generates parsers from specified grammars
- Host: GitHub
- URL: https://github.com/dk14/typed-template
- Owner: dk14
- Created: 2014-09-24T13:44:51.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2018-02-17T03:56:34.000Z (over 8 years ago)
- Last Synced: 2025-02-20T16:43:25.012Z (over 1 year ago)
- Topics: ast, grammar, macros, parse, scala
- Language: Scala
- Homepage:
- Size: 416 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
typed-template
==============
This macro generates parser from user-friendly external grammar.
AST returned from such parser will be typesafe (tree of case classes)
Example
Grammar:
instrument {name} is Option
exercise at {exerciseDate: String} {automatic: String}
{optionsCount: String} options with strike {strike: String}
with {count: String} underlyer
pay premium {premium: String} from {partyFrom: String} to {partyTo: String} at {premiumDate: String}
Input:
instrument Equity is Option
exercise at 10500/10/10 automatic
20 options with strike 100
with one underlyer
pay premium 100500 from DB to NEDB at 10500/10/10
Usage:
@generator(source = "option.template") object Env
Env.parse(instrument)
Output AST:
Env.Option(
Env.ExerciseDate(10500/10/10,automatic),
Env.OptionsCount(20,100),
Env.Count(one),
Env.Premium(100500,DB,NEDB,10500/10/10)
)
Try:
git clone https://github.com/dk14/typed-template.git
brew install sbt
sbt
;clean;test/runMain Test
Note: macroparadise must be added in client module to use this macro
autoCompilerPlugins := true,
resolvers in ThisBuild += Resolver.sonatypeRepo("releases"),
libraryDependencies += "org.scalamacros" % "paradise" % "2.0.1" cross CrossVersion.full,
addCompilerPlugin("org.scalamacros" % "paradise" % "2.0.1" cross CrossVersion.full)