scalameta-parsers

4.9.3 • Public • Published

scalameta-parsers

A JS API for the parsers module of scalameta.

It exposes two functions:

  • parseSource(code: string): parses the given code as a full-fledged source file

  • parseStat(code: string): parses the given code a statement (useful for parsing single expressions without wrapping them into an object or class)

Example:

const { parseStat, parseSource } = require('scalameta-parsers');

const tree1 = parseStat('val answer = 42');
console.log(tree1);

// Output:

// { type: 'Defn.Val',
//   children:
//    [ { type: 'Pat.Var.Term', children: [Object], pos: [Object] },
//      { type: 'Lit.Int', children: [], pos: [Object], value: 42 } ],
//   pos: { start: 0, end: 15 } }

const tree2 = parseSource(`
object Main {
  def main(args: Array[String]): Unit =
    println("Hello, World!")
}`);
console.log(tree2);

// Output:

// { type: 'Source',
//   children: [ { type: 'Defn.Object', children: [Object], pos: [Object] } ],
//   pos: { start: 0, end: 85 } }

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 4.9.3
    8
    • latest

Version History

Package Sidebar

Install

npm i scalameta-parsers

Weekly Downloads

500

Version

4.9.3

License

BSD-3-Clause

Unpacked Size

8.54 MB

Total Files

4

Last publish

Collaborators

  • tanishiking
  • olafurpg
  • xeno-by
  • gabro
  • ckipp01