add support for env variables to the DSL
This commit is contained in:
86
lang/lang.go
86
lang/lang.go
@ -4,12 +4,12 @@ import (
|
||||
"github.com/alecthomas/participle/v2"
|
||||
)
|
||||
|
||||
// Root AST node containing all definitions
|
||||
// AST Root AST node containing all definitions
|
||||
type AST struct {
|
||||
Definitions []Definition `parser:"@@*"`
|
||||
}
|
||||
|
||||
// Union type for top-level definitions
|
||||
// Definition Union type for top-level definitions
|
||||
type Definition struct {
|
||||
Server *Server `parser:"@@"`
|
||||
Entity *Entity `parser:"| @@"`
|
||||
@ -17,25 +17,48 @@ type Definition struct {
|
||||
Page *Page `parser:"| @@"`
|
||||
}
|
||||
|
||||
// Clean server syntax
|
||||
// ConfigValue Flexible value that can be literal or environment variable
|
||||
type ConfigValue struct {
|
||||
Literal *string `parser:"@String"`
|
||||
EnvVar *EnvVar `parser:"| @@"`
|
||||
}
|
||||
|
||||
// EnvVar Environment variable configuration
|
||||
type EnvVar struct {
|
||||
Name string `parser:"'env' @String"`
|
||||
Default *string `parser:"('default' @String)?"`
|
||||
Required bool `parser:"@'required'?"`
|
||||
}
|
||||
|
||||
// Server Clean server syntax
|
||||
type Server struct {
|
||||
Name string `parser:"'server' @Ident"`
|
||||
Settings []ServerSetting `parser:"('{' @@* '}')?"` // Block-delimited settings for consistency
|
||||
}
|
||||
|
||||
type ServerSetting struct {
|
||||
Host *string `parser:"('host' @String)"`
|
||||
Port *int `parser:"| ('port' @Int)"`
|
||||
Host *ConfigValue `parser:"('host' @@)"`
|
||||
Port *IntValue `parser:"| ('port' @@)"`
|
||||
DatabaseURL *ConfigValue `parser:"| ('database_url' @@)"`
|
||||
APIKey *ConfigValue `parser:"| ('api_key' @@)"`
|
||||
SSLCert *ConfigValue `parser:"| ('ssl_cert' @@)"`
|
||||
SSLKey *ConfigValue `parser:"| ('ssl_key' @@)"`
|
||||
}
|
||||
|
||||
// Clean entity syntax with better readability
|
||||
// IntValue Similar to ConfigValue but for integers
|
||||
type IntValue struct {
|
||||
Literal *int `parser:"@Int"`
|
||||
EnvVar *EnvVar `parser:"| @@"`
|
||||
}
|
||||
|
||||
// Entity Clean entity syntax with better readability
|
||||
type Entity struct {
|
||||
Name string `parser:"'entity' @Ident"`
|
||||
Description *string `parser:"('desc' @String)?"`
|
||||
Fields []Field `parser:"('{' @@* '}')?"` // Block-delimited fields for consistency
|
||||
}
|
||||
|
||||
// Much cleaner field syntax
|
||||
// Field Detailed field syntax
|
||||
type Field struct {
|
||||
Name string `parser:"@Ident ':'"`
|
||||
Type string `parser:"@Ident"`
|
||||
@ -45,15 +68,24 @@ type Field struct {
|
||||
Default *string `parser:"('default' @String)?"`
|
||||
Validations []Validation `parser:"@@*"`
|
||||
Relationship *Relationship `parser:"@@?"`
|
||||
Endpoints []string `parser:"('endpoints' '[' @Ident (',' @Ident)* ']')?"` // with transforms this might not be needed
|
||||
Transform []Transform `parser:"@@*"`
|
||||
}
|
||||
|
||||
// Simple validation syntax
|
||||
// Transform Field transformation specification
|
||||
type Transform struct {
|
||||
Type string `parser:"'transform' @Ident"`
|
||||
Column *string `parser:"('to' @Ident)?"`
|
||||
Direction *string `parser:"('on' @('input' | 'output' | 'both'))?"`
|
||||
}
|
||||
|
||||
// Validation Simple validation syntax
|
||||
type Validation struct {
|
||||
Type string `parser:"'validate' @Ident"`
|
||||
Value *string `parser:"@String?"`
|
||||
}
|
||||
|
||||
// Clear relationship syntax
|
||||
// Relationship Clear relationship syntax
|
||||
type Relationship struct {
|
||||
Type string `parser:"'relates' 'to' @Ident"`
|
||||
Cardinality string `parser:"'as' @('one' | 'many')"`
|
||||
@ -73,7 +105,7 @@ type Endpoint struct {
|
||||
CustomLogic *string `parser:"('custom' @String)? '}')?"` // Close block after all content
|
||||
}
|
||||
|
||||
// Clean parameter syntax
|
||||
// EndpointParam Clean parameter syntax
|
||||
type EndpointParam struct {
|
||||
Name string `parser:"'param' @Ident ':'"`
|
||||
Type string `parser:"@Ident"`
|
||||
@ -81,14 +113,14 @@ type EndpointParam struct {
|
||||
Source string `parser:"'from' @('path' | 'query' | 'body')"`
|
||||
}
|
||||
|
||||
// Response specification
|
||||
// ResponseSpec Response specification
|
||||
type ResponseSpec struct {
|
||||
Type string `parser:"'returns' @Ident"`
|
||||
Format *string `parser:"('as' @String)?"`
|
||||
Fields []string `parser:"('fields' '[' @Ident (',' @Ident)* ']')?"`
|
||||
}
|
||||
|
||||
// Enhanced Page definitions with unified section model
|
||||
// Page Enhanced Page definitions with unified section model
|
||||
type Page struct {
|
||||
Name string `parser:"'page' @Ident"`
|
||||
Path string `parser:"'at' @String"`
|
||||
@ -101,13 +133,13 @@ type Page struct {
|
||||
Components []Component `parser:"@@* '}')?"` // Direct components within the block
|
||||
}
|
||||
|
||||
// Meta tags for SEO
|
||||
// MetaTag Meta tags for SEO
|
||||
type MetaTag struct {
|
||||
Name string `parser:"'meta' @Ident"`
|
||||
Content string `parser:"@String"`
|
||||
}
|
||||
|
||||
// Unified Section type that replaces Container, Tab, Panel, Modal, MasterDetail
|
||||
// Section Unified Section type that replaces Container, Tab, Panel, Modal, MasterDetail
|
||||
type Section struct {
|
||||
Name string `parser:"'section' @Ident"`
|
||||
Type *string `parser:"('type' @('container' | 'tab' | 'panel' | 'modal' | 'master' | 'detail'))?"`
|
||||
@ -120,7 +152,7 @@ type Section struct {
|
||||
Elements []SectionElement `parser:"('{' @@* '}')?"` // Block-delimited elements for unambiguous nesting
|
||||
}
|
||||
|
||||
// New unified element type for sections
|
||||
// SectionElement New unified element type for sections
|
||||
type SectionElement struct {
|
||||
Attribute *SectionAttribute `parser:"@@"`
|
||||
Component *Component `parser:"| @@"`
|
||||
@ -128,7 +160,7 @@ type SectionElement struct {
|
||||
When *WhenCondition `parser:"| @@"`
|
||||
}
|
||||
|
||||
// Flexible section attributes (replaces complex config types)
|
||||
// SectionAttribute Flexible section attributes (replaces complex config types)
|
||||
type SectionAttribute struct {
|
||||
DataSource *string `parser:"('data' 'from' @String)"`
|
||||
Style *string `parser:"| ('style' @String)"`
|
||||
@ -137,14 +169,14 @@ type SectionAttribute struct {
|
||||
Theme *string `parser:"| ('theme' @String)"`
|
||||
}
|
||||
|
||||
// Simplified Component with unified attributes - reordered for better parsing
|
||||
// Component Simplified Component with unified attributes - reordered for better parsing
|
||||
type Component struct {
|
||||
Type string `parser:"'component' @Ident"`
|
||||
Entity *string `parser:"('for' @Ident)?"`
|
||||
Elements []ComponentElement `parser:"('{' @@* '}')?"` // Parse everything inside the block
|
||||
}
|
||||
|
||||
// Enhanced ComponentElement with recursive section support - now includes attributes
|
||||
// ComponentElement Enhanced ComponentElement with recursive section support - now includes attributes
|
||||
type ComponentElement struct {
|
||||
Attribute *ComponentAttr `parser:"@@"` // Component attributes can be inside the block
|
||||
Field *ComponentField `parser:"| @@"`
|
||||
@ -153,7 +185,7 @@ type ComponentElement struct {
|
||||
When *WhenCondition `parser:"| @@"`
|
||||
}
|
||||
|
||||
// Simplified component attributes using key-value pattern - reordered for precedence
|
||||
// ComponentAttr Simplified component attributes using key-value pattern - reordered for precedence
|
||||
type ComponentAttr struct {
|
||||
DataSource *string `parser:"('data' 'from' @String)"`
|
||||
Fields []string `parser:"| ('fields' '[' @Ident (',' @Ident)* ']')"`
|
||||
@ -164,14 +196,14 @@ type ComponentAttr struct {
|
||||
Validate bool `parser:"| @'validate'"`
|
||||
}
|
||||
|
||||
// Enhanced component field with detailed configuration using flexible attributes
|
||||
// ComponentField Enhanced component field with detailed configuration using flexible attributes
|
||||
type ComponentField struct {
|
||||
Name string `parser:"'field' @Ident"`
|
||||
Type string `parser:"'type' @Ident"`
|
||||
Attributes []ComponentFieldAttribute `parser:"@@* ('{' @@* '}')?"` // Support both inline and block attributes
|
||||
}
|
||||
|
||||
// Flexible field attribute system
|
||||
// ComponentFieldAttribute Flexible field attribute system
|
||||
type ComponentFieldAttribute struct {
|
||||
Label *string `parser:"('label' @String)"`
|
||||
Placeholder *string `parser:"| ('placeholder' @String)"`
|
||||
@ -192,18 +224,18 @@ type ComponentFieldAttribute struct {
|
||||
Validation *ComponentValidation `parser:"| @@"`
|
||||
}
|
||||
|
||||
// Field relationship for autocomplete and select fields
|
||||
// FieldRelation Field relationship for autocomplete and select fields
|
||||
type FieldRelation struct {
|
||||
Type string `parser:"'relates' 'to' @Ident"`
|
||||
}
|
||||
|
||||
// Component validation
|
||||
// ComponentValidation Component validation
|
||||
type ComponentValidation struct {
|
||||
Type string `parser:"'validate' @Ident"`
|
||||
Value *string `parser:"@String?"`
|
||||
}
|
||||
|
||||
// Enhanced WhenCondition with recursive support for both sections and components
|
||||
// WhenCondition Enhanced WhenCondition with recursive support for both sections and components
|
||||
type WhenCondition struct {
|
||||
Field string `parser:"'when' @Ident"`
|
||||
Operator string `parser:"@('equals' | 'not_equals' | 'contains')"`
|
||||
@ -214,14 +246,14 @@ type WhenCondition struct {
|
||||
Buttons []ComponentButton `parser:"@@* '}')?"` // Block-delimited for unambiguous nesting
|
||||
}
|
||||
|
||||
// Simplified button with flexible attribute ordering
|
||||
// ComponentButton Simplified button with flexible attribute ordering
|
||||
type ComponentButton struct {
|
||||
Name string `parser:"'button' @Ident"`
|
||||
Label string `parser:"'label' @String"`
|
||||
Attributes []ComponentButtonAttr `parser:"@@*"`
|
||||
}
|
||||
|
||||
// Flexible button attribute system - each attribute is a separate alternative
|
||||
// ComponentButtonAttr Flexible button attribute system - each attribute is a separate alternative
|
||||
type ComponentButtonAttr struct {
|
||||
Style *ComponentButtonStyle `parser:"@@"`
|
||||
Icon *ComponentButtonIcon `parser:"| @@"`
|
||||
@ -233,7 +265,7 @@ type ComponentButtonAttr struct {
|
||||
Via *ComponentButtonVia `parser:"| @@"`
|
||||
}
|
||||
|
||||
// Individual button attribute types
|
||||
// ComponentButtonStyle Individual button attribute types
|
||||
type ComponentButtonStyle struct {
|
||||
Value string `parser:"'style' @String"`
|
||||
}
|
||||
|
Reference in New Issue
Block a user