UNPKG

@syntaxs/compiler

Version:

Compiler used to compile Syntax Script projects.

169 lines 4.74 kB
import { OperatorStatement } from './types.js'; /** * Main class used to compile a folder containing syntax script declaration (.syx) and syntax script (.sys) files. * @version 1.0.1 * @since 0.0.1-alpha */ export declare class SyntaxScriptCompiler { private readonly rootDir; private readonly outDir; private readonly mainFileFormat; readonly exportData: Record<string, AnyExportable[]>; /** * Constructs a new compiler. * @param {string} rootDir Root dir to search for source files. * @param {string} outDir Out dir to write compiled files. * @param {string} format File format to compile. * @author efekos * @version 1.0.1 * @since 0.0.1-alpha */ constructor(rootDir: string, outDir: string, format: string); /** * Parses .syx files and compiles .sys files using them. * @author efekos * @since 0.0.1-alpha * @version 1.0.0 */ compile(): Promise<void>; /** * Compiles every .syx file found in the path. * @param {string} folderPath A folder path to search for .syx files. * @author efekos * @version 1.0.0 * @since 0.0.1-alpha */ compileSyxFiles(folderPath: string): void; /** * Compiles one .syx file from the path given. * @param {string} file Path to a file to compile. * @author efekos * @version 1.0.6 * @since 0.0.2-alpha */ compileSyx(file: string): void; /** * Compiles every .sys file found in the given folder. * @param {string} folderPath Folder path to search for .sys files. * @author efekos * @version 1.0.0 * @since 0.0.1-alpha */ compileSysFiles(folderPath: string): void; /** * Compiles a .sys file at the path given. * @param {string} file Path to the .sys file to compile. * @author efekos * @since 0.0.1-alpha * @version 1.0.3 */ compileSys(file: string): void; } /** * Type of something that can be exported. * @version 1.0.1 * @since 0.0.1-alpha * @author efekos */ export declare enum ExportType { /** * {@link ExportedOperator}. */ Operator = 0, /** * {@link ExportedFunction}. */ Function = 1, /** * {@link ExportedKeyword}. */ Keyword = 2, /** * {@link ExportedGlobal}. */ Global = 3 } /** * Base exportable interface. * @author efekos * @version 1.0.1 * @since 0.0.1-alpha */ export interface Exported { type: ExportType; } /** * Represents an exported operator. Uses type {@link ExportType.Operator}. * @author efekos * @version 1.0.1 * @since 0.0.1-alpha */ export interface ExportedOperator extends Exported { type: ExportType.Operator; regexMatcher: RegExp; outputGenerators: Record<string, OneParameterMethod<string, string>>; imports: Record<string, string>; } /** * Represents an exported function. Uses type {@link ExportType.Function}. * @author efekos * @version 1.0.1 * @since 0.0.1-alpha */ export interface ExportedFunction extends Exported { type: ExportType.Function; name: string; args: RegExp[]; formatNames: Record<string, string>; imports: Record<string, string>; } /** * Represents an exported keyword. Uses type {@link ExportType.Keyword}. * @author efekos * @version 1.0.1 * @since 0.0.1-alpha */ export interface ExportedKeyword extends Exported { type: ExportType.Keyword; word: string; } /** * A method that has one parameter with the type {@link V} and returns {@link R}. * @author efekos * @version 1.0.0 * @since 0.0.1-alpha */ export type OneParameterMethod<V, R> = (v: V) => R; /** * A method that takes no parameters and returns an {@link R}. * @author efekos * @version 1.0.0 * @since 0.0.1-alpha */ export type ReturnerMethod<R> = () => R; /** * Any interface that represents something exportable. */ export type AnyExportable = ExportedOperator | ExportedFunction | ExportedKeyword; export declare const regexes: Record<string, RegExp>; /** * Escapes every RegExp character at the source string. * @param src Source string. * @returns Same string with every RegExp character replaced with '\\$&'. * @author efekos * @version 1.0.0 * @since 0.0.1-alpha */ export declare function escapeRegex(src: string): string; export declare namespace CompilerFunctions { /** * Generates {@link RegExp} of the given operator statement. * @param statement An operator statement. * @returns A regular expression generated from regex of the operator statement. * @author efekos * @version 1.0.0 * @since 0.0.2-alpha */ function generateRegexMatcher(statement: OperatorStatement): RegExp; } //# sourceMappingURL=compiler.d.ts.map