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") } } } }