js-ds-language-framework
v1.2.0
Published
<div> <h3> <em> Create your own truly amazing programming language from scratch. :heart: </em> </h3> </div> <div> <h4>First of all, DSLanguage.Framework has two main subsystems</h4> <ul> <li> <a href="#scanner-s
Downloads
2
Maintainers
Readme
DSLanguage.Framework
Scanner subsystem
This subsystem translates given text to an stream of tokens. It is necessary intermediate step for building AST (abstract syntax tree).
You can plug in this subsystem into your code as:
import * as Scanner from '<path-to-framework>/DSLF.Scanner'
This subsystem has such public components:
namespace Scanner.Token
namespace Scanner.Types
interface Scanner.Component
interface Scanner.Context
class Scanner.Base
:bulb:
Scanner.Token
Scanner.Token
is the namespaces that contains basic definition for Token- Token is an object that contains specific information about language symbol
- Members:
namespace Types
class Base
- basic definition for type of tokenclass Basic
- most frequently used types of token
namespace Information
interface Base<T>
- basic definition of additional information about tokennamespace Defaults
- most frequently used types of additional information about tokenclass Placement
- class that have information about token's placement
type Base
- basic definition of tokentype: Token.Types.Base
- type of tokenvalue: Token.Value
- value of tokenplacement: Token.Information.Defaults.Placement
- information about placement of symbol
Scanner.Types
Scanner.Types
is the namespace that contains basic type declarations that necessary for scanner- Members:
type Cursor
type Accumulator
Scanner.Component
Scanner.Component
is the basic definition for scanner component- Components are main functional parts of scanner (a.k.a "subscanners")
- Members:
Scan(context: Scanner.Context, cursor: Scanner.Commons.Cursor): Scanner.Token.Base | void
- scanning strategy
Scanner.Context
Scanner.Context
is the basic definition for context, where components of scanner can share some information
Scanner.Base
Scanner.Base
is the type of scanner itself- This class has two main methods to use:
Scan(input: string): Scanner.Token.Base[]
- scans input by customisable handlerAddHandler(handler: Scanner.Handler): void
- adds customisable handler
Parser subsystem
This subsystem translates given stream of token to AST (abstract syntax tree).
You can plug in this subsystem into your code as:
import * as Parser from '<path-to-framework>/DSLF.Parser'
This subsystem has such public components:
namespace Parser.Types
namespace Parser.Nodes
namespace Parser.Components
namespace Parser.Layers
class Parser.Base<T extends Parser.Nodes.Base>
:bulb:
Parser.Types
- Parser.Types is the namespace that contains basic type declarations that necessary for parser
Parser.Nodes
- Parser.Nodes is the namespace that contains basic definitions for nodes
- Node is an element of AST (abstract syntax tree).
- Members:
interface Base
- basic definition of nodeinterface Translatable
- definition for translatable nodeTranslatable.Translate(): string
- translation strategy
interface Executable<T> extends Base
- definition for executable nodeExecutable.Execute(context: Parser.Nodes.Additional.Context): T
- execution strategy
namespace Default
- namespace that contains default nodes realisationsnamespace Default.Block
namespace Default.Primitives
namespace Additional
interface Context
Parser.Components
Parser.Components
is the namespace that contains basic definitions for components- Components are the main functional parts of the parser (a.k.a "subparsers"). The main purpose of the components is generation AST (abstract syntax tree)
- Members:
interface Base<T extends Parser.Nodes.Base>
- definition for basic componentBase.Parse(environment: Environment<T>): T
- parsing strategy
Parser.Layers
Parser.Layers
is the namespace that contains basic layer definition- Members:
abstract class Base<T extends Parser.Nodes.Base>
- is a part of recursive descent parsingExecuteSuccessorParser(): T
- method that calls successor layer parser
abstract class WithReferenceToTop<T extends Parser.Nodes.Base>
- is the same asParser.Layer
but with reference to top layerExecuteSuccessorParser(): T
- method that calls successor layer parserExecuteTopParser(): T
- method that calls top layer parser
Parser.Base
Parser.Base
is the type of parser itself.- This class has two main methods you can use:
UseTerminal(parser: () => Parser.Component.Base<T>): void
- methods that adds terminal expression parsers to base parserUse(priority: number, parser: () => Parser.Component.Base<T>): void
- method that adds non-terminal expression parsers to base parser with given priority (biggerpriority
= less priority)Parse(): T[]
Examples of usage
Go to file Examples/Example.ts
and look at how this used for create your own programming language
How to download and configure this package
- Go to folder with your project
- Open terminal in this folder
- Type
npm install js-ds-language-framework --save-dev
- You're ready! Enjoy :heart:
This package created by Saitov Denis