Function parseLedgerToCST

  • Scans, lexes, and parses an HLedger journal file into a concrete syntax tree (CST). This method produces a tree of Chevrotain CST nodes containing the type, position and text image of each parsed node.

    A 'raw' journal object can be translated into a 'cooked' journal object using the cstToRawLedger method.

    Example (ESModule)

    import { parseLedgerToCST } from '@jones.tristand/hledger-parser'

    const parseResult = parseLedgerToCST(sourceCode)
    console.log(`Lexing errors: ${parseResult.lexErrors.length}`);
    console.log(`Parsing errors: ${parseResult.parseErrors.length}`);
    console.log('Result:', parseResult.cstJournal);

    // => Lexing errors: 0
    // => Parsing errors: 0
    // => Result: {
    // => name: 'journal',
    // => children: [Object: null prototype] { journalItem: [ [Object] ] }
    // => }

    Example (CommonJS)

    const { parseLedgerToCST } = require('@jones.tristand/hledger-parser');

    const parseResult = parseLedgerToCST(sourceCode)
    console.log(`Lexing errors: ${parseResult.lexErrors.length}`);
    console.log(`Parsing errors: ${parseResult.parseErrors.length}`);
    console.log('Result:', parseResult.cstJournal);

    // => Lexing errors: 0
    // => Parsing errors: 0
    // => Result: {
    // => name: 'journal',
    // => children: [Object: null prototype] { journalItem: [ [Object] ] }
    // => }

    Parameters

    • source: string

      the source code of the journal to parse

    Returns CSTParseReturn

Generated using TypeDoc