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
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"
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'])
The result of the read operation:
let $result = $a + $b;
Supported Language Syntax
Important Note
- 4d Code provided to the Parser or ParserRunner must be with Tabs indentation.