@tracespace/parser
Version:
Gerber and NC drill file parser
36 lines (35 loc) • 886 B
TypeScript
import { Lexer } from './lexer';
import { Root } from './tree';
/**
* Gerber and NC drill file parser.
*
* @category Parser
*/
export interface Parser {
/** Parser's {@linkcode Lexer} instance */
lexer: Lexer;
/** Feed the parser with all or part of the source file */
feed(chunk: string): void;
/** Get the resulting AST when you are done feeding the parser */
results(): Root;
}
/**
* {@linkcode Parser} factory and the primary export of the library.
*
* @example
* ```ts
* import {createParser} from '@tracespace/parser'
*
* // create a parser to parse a single file
* const parser = createParser()
*
* // feed the parser the source file contents
* parser.feed('G04 gerber file contents*\nM02*\n')
*
* // get the resulting AST
* const tree = parser.results()
* ```
*
* @category Parser
*/
export declare function createParser(): Parser;