scalameta-parsers

4.12.0 • 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 } }

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i scalameta-parsers

      Weekly Downloads

      515

      Version

      4.12.0

      License

      BSD-3-Clause

      Unpacked Size

      7.67 MB

      Total Files

      4

      Last publish

      Collaborators

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