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
Property | Type | Description |
---|---|---|
body | [Variant, Style] | List of root nodes |
Style
Property | Type | Description |
---|---|---|
name | String | The name of the style |
format | ,
| The format of the style |
body | [Declaration, Conditional] | List of declarations |
comments | [String] | List of comments found in front of the style |
Variant
Property | Type | Description |
---|---|---|
name | String | The name of the variant |
body | [Identifier] | List of variant values |
comments | [String] | List of comments found in front of the style |
Conditional
Property | Type | Description |
---|---|---|
property | String | The property that is being compared (only available if boolean is ) |
value | Float, Integer, Identifier, String | The value that is being compared with the actual property value (only available if boolean is ) |
operator | , , , ,
| The comparison operator used |
boolean | Boolean | Whether the condition is boolean |
body | [Declaration, Conditional] | List of declarations |
Declaration
Property | Type | Description |
---|---|---|
property | String | The style property |
value | [FunctionExpression, Float, Integer, Identifier, String, Variable] | The style value |
dynamic | Boolean | Whether it's declaration has dynamic input (thus a variable as value) |
raw | Boolean | Whether it has a raw property prefixed with
|
FunctionExpression
Property | Type | Description |
---|---|---|
callee | ||
params |
Float
Property | Type | Description |
---|---|---|
integer | ||
fractional | ||
negative |
Integer
Property | Type | Description |
---|---|---|
value | ||
negative |
Identifier
Property | Type | Description |
---|---|---|
value |
String
Property | Type | Description |
---|---|---|
value |
Variable
Property | Type | Description |
---|---|---|
value |