@ws-ui/parser
v0.1.2
Published
4D to Javascript parser
Downloads
3
Keywords
Readme
4D Parser
This package provides two main Classes:
- Parser:
- Parse 4D-language and transpile it to JavaScript
- ParserRunner:
- Parse 4d-language
- Execute 4d-langague Client-Side
- Using Web Worker to provide an isolated env to run your Code
Install
npm install @ws-ui/parser
Usage Exemple
- Parser
import { Parser } from '@ws-ui/parser'
const code4D = '$bar:="foo"'
const parser = new Parser()
parser.parse(code4D)
const generatedCode = parser.generateJS()
const jsCode = generatedCode.code
This code will generate this result:
let bar = "foo"
- ParserRunner
import { ParserRunner } from '@ws-ui/parser'
const parserRunner = new ParserRunner(5000, 1)
const code4D = '$result:= $a + $b'
const { response } = await parserRunner.parse([
code: code4D,
name: 'sum',
params: [{ name: "$a" }, { name: "$b" }],
returns: { name: "$result" },
])
const { result } = await parserRunner.run('sum', [4, 4])
const { result: readResult } = await parserRunner.read(['sum'])
//response: OK
//result: 8
//readResult: [ {code: '$result:= $a + $b', codeJS: 'let $result = $a + $b;'} ]
The result of the read operation:
let $result = $a + $b;
Supported Language Syntax
Variable Declaration
- With New Keyword
- With the Var keyword.
- Local variable, start with $
- Process Variables.
Function declaration with Function keyword.
Controll flow
- While...End while
- For...End for
- If...Else...End if
- Case of...Else...End case
Other Syntax are in WIP.
Important Note
- 4d Code provided to the Parser or ParserRunner must be with Tabs indentation.