Once you have generated the parser, you can use it to parse text by combining it with the Parse function.

Example:

import { Parse } from 'grammar-well/parse';
import grammar from './my-grammar.js';
const output = Parse(
    new grammar(), 
    body,
    { 
        algorithm: 'earley',
        parserOptions: {}
    }, 
    'first'
);

Function signature:

export function Parse(
    language: InstanceType<RuntimeParserClass>,
    input: string,
    options: {
        algorithm: 'earley',
        parserOptions: {}
    },
    results: 'full' | 'first' = 'first'
)

Below are the arguments the Parse function accepts:

#NameTypeDescription
1languageInstance of generated parser classAn instance of the generated parser class (e.g., new grammar()).
2inputstringThe input string to be parsed.
3optionsobject (optional)Parser options:
- algorithm: Parsing algorithm to use ('earley' by default).
- parserOptions: Additional parser options.
4results'first' | 'full' (optional, default: 'first')Determines the type of result returned:
- 'first': Returns the first parse result.
- 'full': Returns all possible parse results.