Files
masonry/examples/langV1/debug.go
Mason Payne 9b209dfe63 try an SDK and a manually defined lang
I don't think I like the SDK way, and langV2 seems to be so simialr to
V1 that I'm probably going to stick with V1 for now and see if i can get
it to do what I need.
2025-08-20 00:13:41 -06:00

158 lines
3.8 KiB
Go

package main
import (
"fmt"
"io/ioutil"
"masonry/lang"
)
func main() {
// Read the example.masonry file
content, err := ioutil.ReadFile("example.masonry")
if err != nil {
fmt.Printf("Error reading example.masonry: %v\n", err)
return
}
input := string(content)
ast, err := lang.ParseInput(input)
if err != nil {
fmt.Printf("Error: %v\n", err)
} else {
fmt.Printf("🎉 Successfully parsed complete DSL with pages!\n\n")
for _, def := range ast.Definitions {
if def.Server != nil {
fmt.Printf("📡 Server: %s\n", def.Server.Name)
for _, setting := range def.Server.Settings {
if setting.Host != nil {
fmt.Printf(" host: %s\n", *setting.Host)
}
if setting.Port != nil {
fmt.Printf(" port: %d\n", *setting.Port)
}
}
fmt.Printf("\n")
}
if def.Entity != nil {
entity := def.Entity
fmt.Printf("🏗️ Entity: %s", entity.Name)
if entity.Description != nil {
fmt.Printf(" - %s", *entity.Description)
}
fmt.Printf("\n")
for _, field := range entity.Fields {
fmt.Printf(" %s: %s", field.Name, field.Type)
if field.Required {
fmt.Printf(" (required)")
}
if field.Unique {
fmt.Printf(" (unique)")
}
if field.Default != nil {
fmt.Printf(" default=%s", *field.Default)
}
fmt.Printf("\n")
}
fmt.Printf("\n")
}
if def.Endpoint != nil {
endpoint := def.Endpoint
fmt.Printf("🚀 Endpoint: %s %s", endpoint.Method, endpoint.Path)
if endpoint.Entity != nil {
fmt.Printf(" (for %s)", *endpoint.Entity)
}
if endpoint.Description != nil {
fmt.Printf(" - %s", *endpoint.Description)
}
if endpoint.Auth {
fmt.Printf(" [AUTH]")
}
fmt.Printf("\n\n")
}
if def.Page != nil {
page := def.Page
fmt.Printf("🎨 Page: %s at %s", page.Name, page.Path)
if page.Title != nil {
fmt.Printf(" - %s", *page.Title)
}
if page.Auth {
fmt.Printf(" [AUTH]")
}
fmt.Printf("\n")
fmt.Printf(" Layout: %s\n", page.Layout)
for _, meta := range page.Meta {
fmt.Printf(" Meta %s: %s\n", meta.Name, meta.Content)
}
for _, comp := range page.Components {
fmt.Printf(" 📦 Component: %s", comp.Type)
if comp.Entity != nil {
fmt.Printf(" for %s", *comp.Entity)
}
fmt.Printf("\n")
for _, attr := range comp.Config {
if attr.Fields != nil {
fmt.Printf(" fields: %v\n", attr.Fields.Fields)
}
if attr.Actions != nil {
fmt.Printf(" actions: ")
for i, action := range attr.Actions.Actions {
if i > 0 {
fmt.Printf(", ")
}
fmt.Printf("%s", action.Name)
if action.Endpoint != nil {
fmt.Printf(" via %s", *action.Endpoint)
}
}
fmt.Printf("\n")
}
if attr.DataSource != nil {
fmt.Printf(" data from: %s\n", attr.DataSource.Endpoint)
}
if attr.Style != nil {
fmt.Printf(" style: %s", *attr.Style.Theme)
if len(attr.Style.Classes) > 0 {
fmt.Printf(" classes: %v", attr.Style.Classes)
}
fmt.Printf("\n")
}
if attr.Pagination != nil {
fmt.Printf(" pagination: enabled")
if attr.Pagination.PageSize != nil {
fmt.Printf(" size %d", *attr.Pagination.PageSize)
}
fmt.Printf("\n")
}
if attr.Filters != nil {
fmt.Printf(" filters: ")
for i, filter := range attr.Filters.Filters {
if i > 0 {
fmt.Printf(", ")
}
fmt.Printf("%s as %s", filter.Field, filter.Type)
if filter.Label != nil {
fmt.Printf(" (%s)", *filter.Label)
}
}
fmt.Printf("\n")
}
if attr.Validation {
fmt.Printf(" validation: enabled\n")
}
}
}
fmt.Printf("\n")
}
}
}
}