0.1.17 • Published 23 days ago

@rekajs/parser v0.1.17

Weekly downloads
-
License
MIT
Repository
github
Last release
23 days ago

@rekajs/parser

Parser for Reka AST.

This package is mainly intended to provide an easy way to create Reka AST Nodes from code.

Syntax

The Parser expects code to be written in a custom Reka-syntax.

Apart from some syntactical differences in defining stateful variables and components, most of the syntax are identical to JSX (with some Vue/Svelte influence).

Program

The entire Program Node can be parsed based on the following syntax:

val globalVariable1 = "hi";

component ComponentName(prop1="default value") {
    val stateVariable1 = 0;
    val stateWithBinaryExpression = 1+1;
    val stateWithBooleanExpression = false;
} => (
    <div></div>
)

component AnotherComponentName() {

} => (
    <ComponentName1 prop1="overriden value" />
)

Templates

Component templates are similar to templates in JSX with some differences:

Text values

Text values must be written in a <text /> tag:

component ComponentName() {} => (
    <text value="Hello World!" />
)

Conditionals

To conditionally render an element, specify the @if directive:

component ComponentName(prop1) {
    val showCounter = false;
} => (
    <div @if={showCounter}>

    </div>
)

Foreach

To render an element for each item in a list, specify the @each directive:

val items = ["a", "b", "c"];

component ComponentName(prop1) {

} => (
    <div @each={item in items}>
        <text value={item} />
    </div>
)

Specifying index variable:

<div @each={(item, i) in items}>
    <text value={i + " " + item} />
</div>

Children

A component can accept children elements by rendering the <slot /> element:

component Button() {} => (
    <button>
        <slot />
    </button>
)

component App() {} => (
    <div>
        <Button>
            <text value="Click me!" />
        </Button>
    </div>
)
0.1.17

23 days ago

0.1.16

3 months ago

0.1.15

5 months ago

0.1.14

5 months ago

0.1.10

7 months ago

0.1.11

7 months ago

0.1.12

6 months ago

0.1.13

6 months ago

0.1.8

9 months ago

0.1.7

9 months ago

0.1.9

8 months ago

0.1.6

10 months ago

0.1.4

12 months ago

0.1.5

11 months ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.3

1 year ago

0.1.0

1 year ago

0.1.0-alpha.0

1 year ago