chamber-abc
v0.2.0
Published
ABC notation language toolkit - parser, analyzer, formatter, and tokenizer
Maintainers
Readme
chamber-abc
ABC notation language toolkit for the browser - parser, analyzer, formatter, and tokenizer.
Installation
npm install chamber-abcUsage
import init, { parse, analyze, format, format_default } from 'chamber-abc';
// Initialize WASM
await init();
const source = `X:1
T:Test Tune
M:4/4
L:1/8
K:C
CDEF GABc|`;
// Parse
const result = parse(source);
console.log(result.tune); // AST
console.log(result.diagnostics); // Parse errors/warnings
// Analyze (semantic checks)
const analysis = analyze(result.tune);
console.log(analysis.diagnostics); // Lint warnings
// Format
const formatted = format_default(source);API
parse(source: string): ParseResult
Parse ABC notation and return AST with diagnostics.
analyze(tune: Tune): AnalysisResult
Run semantic analysis (linting) on parsed tune.
format(source: string, config: FormatterConfig): string
Format ABC notation with custom configuration.
format_default(source: string): string
Format with default settings (normalize spacing, etc).
format_minimal(source: string): string
Format with minimal changes (cleanup only).
format_passthrough(source: string): string
Return source unchanged.
get_line_col(source: string, offset: number): LineCol
Convert byte offset to line/column position.
tokenize(source: string): Token[]
Tokenize source for syntax highlighting. Returns array of tokens:
const tokens = tokenize(source);
// [
// { kind: "FieldLabel", range: { start: 0, end: 1 } },
// { kind: "Colon", range: { start: 1, end: 2 } },
// { kind: "Note", range: { start: 20, end: 21 } },
// ...
// ]Token kinds: FieldLabel, Note, Rest, Sharp, Flat, Natural, Bar, DoubleBar, RepeatStart, RepeatEnd, Decoration, Comment, Tuplet, Tie, Number, Text, Whitespace, Newline, etc.
License
MIT
