Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

4d-parser

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

4d-parser

4D to Javascript parser

  • 0.1.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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.

FAQs

Package last updated on 25 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc