Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MemlCore

The main class for handling compiling MEML files and general configuration. Statics in this file are responsible for compiler configuration and an instance of this class can be created to compile files.

Example usage

const path = require('path')
const fs = require('fs')

const { MemlCore } = require('meml')

MemlCore.sourcePath = path.join(__dirname, 'src')
MemlCore.distPath = path.join(__dirname, 'build')

async function app() {
  const compiler = new MemlCore()

  fs.writeFileSync('./dist/index.html', await compiler.fileToWeb('./src/index.meml'))
}

app()

Build process

The following steps are taken by the build process, with appropriate functions available if you wish to break down the steps

Tokenizing -> Parsing -> Targeting

Note that whilst tokenizing and parsing generally remain constant, you can create a custom target for your use case. There is no current documentation for this, however it follows the structure layed out in crafting interpreters and you may use the source code in the web target as a starting point as long as your project is GPLv3 compatible.

Project management

todo

Should config be moved somewhere else?

todo

Should builds be moved into separate functions?

Hierarchy

  • MemlCore

Index

Constructors

constructor

Properties

Static distPath

distPath: string = ...

The path where files generated by loaded should be placed. Will be ignored if MemlCore.shouldLink is set to false.

Static errors

errors: string = ''

A string containing the errors outputted to the console. Can be reset between files using MemlCore.hadError()

Static globalLoaders

globalLoaders: ILoader[] = ...

Instantiated loader objects for imported values

Static hadError

hadError: boolean = false

Keeps track of if an error has occurred. Can be reset between files using MemlCore.hadError()

Static isProduction

isProduction: boolean = false

Passed into each language loader (see MemlCore.globalLoaders and ILoader) to determine if the output should be minified

Static shouldLink

shouldLink: boolean = false

If this is set, MEML will reference the files it imports rather than inlining them. The following arguments MUST be set correctly for this to work:

  • MemlCore.sourcePath
  • MemlCore.distPath

Example

false (default)

(import './something.css')

Out:

<!-- ... -->
<style>\* File contents here *\</style>
<!-- ... -->

true

(import './something.css')

Out:

<!-- ... -->
<link ... href="./something.css">
<!-- ... -->

Static sourcePath

sourcePath: string = ...

The path where all source files are stored. Used when importing files, ignored if MemlCore.shouldLink is set to false.

Methods

fileToWeb

  • fileToWeb(path: string): Promise<string>
  • Converts the contents of a file into a string of html.

    May write files to disk depending on your settings for shouldLink

    Parameters

    • path: string

    Returns Promise<string>

parse

  • parse(tokens: Token[], file?: string): PageStmt
  • Converts the input tokens to an AST tree with a PageStmt as its root

    Parameters

    • tokens: Token[]
    • file: string = ''

    Returns PageStmt

sourceToWeb

  • sourceToWeb(source: string, path?: string): Promise<string>
  • Converts a source MEML string to a string of html.

    May write files to disk depending on your settings for shouldLink

    Parameters

    • source: string
    • path: string = 'memory.meml'

    Returns Promise<string>

targetWeb

  • targetWeb(page: PageStmt, path?: string): Promise<string>
  • Converts an AST tree to a html string

    May write files to disk depending on your settings for shouldLink

    Parameters

    • page: PageStmt
    • path: string = 'memory.meml'

    Returns Promise<string>

tokenize

  • tokenize(source: string, file?: string): Token[]
  • Converts the contents of the source string into an array of tokens ready for parsing

    Parameters

    • source: string
    • file: string = ''

    Returns Token[]

tokenizeAndParse

  • tokenizeAndParse(source: string, file?: string): PageStmt

Static registerLoader

  • registerLoader(Loader: ILoader): void
  • Register a new loader for linking and rendering

    Parameters

    Returns void

Static reset

  • reset(): void
  • Resets all errors generated by the compiler and linker cache. Do not use between files, only between compilations. Use MemlCore.resetErrors() between files.

    Returns void

Generated using TypeDoc