JavaScript implementation of the Links Notation parser using Bun and Peggy.js parser generator.
Install the package using your preferred package manager:
npm install links-notationbun add links-notationimport { Parser, Link } from 'npm:links-notation@^0.6.0';For contributors working on the source code:
cd js
bun installcd js
npm installCompile the Peggy.js grammar:
bun run build:grammarBuild the project:
bun run buildRun tests:
bun testWatch mode:
bun test --watchimport { Parser, Link } from 'links-notation';
// Create parser
const parser = new Parser();
// Parse Lino format string
const input = `papa (lovesMama: loves mama)
son lovesMama
daughter lovesMama
all (love mama)`;
const result = parser.parse(input);
console.log(result);
// Access parsed structure
result.forEach((link) => {
console.log(link.toString());
});import { Link } from 'links-notation';
// Create links programmatically
const link = new Link('parent', [new Link('child1'), new Link('child2')]);
console.log(link.toString()); // (parent: child1 child2)
// Access link properties
console.log('ID:', link.id);
console.log('Values:', link.values);// Handle nested structures
const input = `parent
child1
child2
grandchild1
grandchild2`;
const parsed = await parser.parse(input);
// Work with groups
import { LinksGroup } from 'links-notation';
const group = new LinksGroup(parsed);
console.log(group.format());papa (lovesMama: loves mama)
son lovesMama
daughter lovesMama
all (love mama)
papa has car
mama has house
(papa and mama) are happy
(linksNotation: links notation)
(This is a linksNotation as well)
(linksNotation supports (unlimited number (of references) in each link))
parent
child1
child2
grandchild1
grandchild2
Main parser class for converting strings to links.
initialize()- Initialize the parser (async)parse(input)- Parse a Lino string and return links
Represents a single link with ID and values.
constructor(id, values = [])- Create a new linktoString()- Convert link to string formatid- Link identifiervalues- Array of child values/links
Container for grouping related links.
constructor(links)- Create a new groupformat()- Format the group as a string
src/grammar.pegjs- Peggy.js grammar definitionsrc/Link.js- Link data structuresrc/LinksGroup.js- Links group containersrc/Parser.js- Parser wrappersrc/index.js- Main entry pointtests/- Test files
Run ESLint to check for code style issues:
bun run lintAuto-fix linting issues:
bun run lint:fixThis project uses pre-commit hooks that automatically run ESLint before commits. To set up pre-commit hooks locally:
# From repository root
pip install pre-commit
pre-commit install- Peggy.js (5.0.6) - Parser generator
- Bun runtime (development)
This project uses Prettier for code formatting.
npx prettier --write .npx prettier --check .These checks are also enforced in CI. Pull requests with formatting issues will fail the format check.
- Package:
links-notation - Version: 0.1.0
- License: MIT