Parser

Parser

yarn add --dev @elodin/parser

The parser turns a string of Elodin code into an AST (Abstract Syntax Tree).

parse

It exposes a

parse
method that just takes an single string of code.

Example

import { parse } from '@elodin/parser'
const input = `
style Button {
backgroundColor: red
paddingLeft: 10
paddingRight: 10
}
`
const ast = parse(input)

AST Nodes

The AST consists of the following AST nodes:

File

PropertyTypeDescription
body[Variant, Style]List of root nodes


Style

PropertyTypeDescription
nameStringThe name of the style
format
view
,
text
The format of the style
body[Declaration, Conditional]List of declarations
comments[String]List of comments found in front of the style


Variant

PropertyTypeDescription
nameStringThe name of the variant
body[Identifier]List of variant values
comments[String]List of comments found in front of the style


Conditional

PropertyTypeDescription
propertyStringThe property that is being compared (only available if boolean is
false
)
valueFloat, Integer, Identifier, StringThe value that is being compared with the actual property value (only available if boolean is
false
)
operator
=
,
>=
,
>
,
<=
,
<
The comparison operator used
booleanBooleanWhether the condition is boolean
body[Declaration, Conditional]List of declarations


Declaration

PropertyTypeDescription
propertyStringThe style property
value[FunctionExpression, Float, Integer, Identifier, String, Variable]The style value
dynamicBooleanWhether it's declaration has dynamic input (thus a variable as value)
rawBooleanWhether it has a raw property prefixed with
__


FunctionExpression

PropertyTypeDescription
callee
params


Float

PropertyTypeDescription
integer
fractional
negative


Integer

PropertyTypeDescription
value
negative


Identifier

PropertyTypeDescription
value


String

PropertyTypeDescription
value


Variable

PropertyTypeDescription
value