Files
masonry/examples/lang/debug.go

151 lines
3.9 KiB
Go

package main
import (
"fmt"
"masonry/lang"
"os"
)
func main() {
// Read the example.masonry file from the correct path
content, err := os.ReadFile("examples/lang/example.masonry")
if err != nil {
fmt.Printf("Error reading example.masonry: %v\n", err)
return
}
input := string(content)
// Try to parse the DSL
ast, err := lang.ParseInput(input)
if err != nil {
fmt.Printf("❌ Parse Error: %v\n", err)
return
}
// If we get here, parsing was successful!
fmt.Printf("🎉 Successfully parsed DSL with block delimiters!\n\n")
// Count what we parsed
var servers, entities, endpoints, pages int
for _, def := range ast.Definitions {
if def.Server != nil {
servers++
}
if def.Entity != nil {
entities++
}
if def.Endpoint != nil {
endpoints++
}
if def.Page != nil {
pages++
}
}
fmt.Printf("📊 Parsing Summary:\n")
fmt.Printf(" Servers: %d\n", servers)
fmt.Printf(" Entities: %d\n", entities)
fmt.Printf(" Endpoints: %d\n", endpoints)
fmt.Printf(" Pages: %d\n", pages)
fmt.Printf(" Total Definitions: %d\n", len(ast.Definitions))
// Verify key structures parsed correctly
fmt.Printf("\n✅ Validation Results:\n")
// Check server has settings in block
for _, def := range ast.Definitions {
if def.Server != nil {
if len(def.Server.Settings) > 0 {
fmt.Printf(" ✓ Server '%s' has %d settings (block syntax working)\n", def.Server.Name, len(def.Server.Settings))
}
break
}
}
// Check entities have fields in blocks
entityCount := 0
for _, def := range ast.Definitions {
if def.Entity != nil {
entityCount++
if len(def.Entity.Fields) > 0 {
fmt.Printf(" ✓ Entity '%s' has %d fields (block syntax working)\n", def.Entity.Name, len(def.Entity.Fields))
}
if entityCount >= 2 { // Just show first couple
break
}
}
}
// Check endpoints have params in blocks
endpointCount := 0
for _, def := range ast.Definitions {
if def.Endpoint != nil {
endpointCount++
if len(def.Endpoint.Params) > 0 {
fmt.Printf(" ✓ Endpoint '%s %s' has %d params (block syntax working)\n", def.Endpoint.Method, def.Endpoint.Path, len(def.Endpoint.Params))
}
if endpointCount >= 2 { // Just show first couple
break
}
}
}
// Check pages have content in blocks
pageCount := 0
for _, def := range ast.Definitions {
if def.Page != nil {
pageCount++
totalContent := len(def.Page.Meta) + len(def.Page.Elements)
if totalContent > 0 {
fmt.Printf(" ✓ Page '%s' has %d content items (block syntax working)\n", def.Page.Name, totalContent)
}
if pageCount >= 2 { // Just show first couple
break
}
}
}
// Check for nested sections (complex structures)
var totalSections, nestedSections int
for _, def := range ast.Definitions {
if def.Page != nil {
for _, element := range def.Page.Elements {
if element.Section != nil {
totalSections++
nestedSections += countNestedSections(*element.Section)
}
}
}
}
if totalSections > 0 {
fmt.Printf(" ✓ Found %d sections with %d nested levels (recursive parsing working)\n", totalSections, nestedSections)
}
fmt.Printf("\n🎯 Block delimiter syntax is working correctly!\n")
fmt.Printf(" All constructs (server, entity, endpoint, page, section, component) now use { } blocks\n")
fmt.Printf(" No more ambiguous whitespace-dependent parsing\n")
fmt.Printf(" Language is now unambiguous and consistent\n")
}
// Helper function to count nested sections recursively
func countNestedSections(section lang.Section) int {
count := 0
for _, element := range section.Elements {
if element.Section != nil {
count++
count += countNestedSections(*element.Section)
}
if element.Component != nil {
for _, compElement := range element.Component.Elements {
if compElement.Section != nil {
count++
count += countNestedSections(*compElement.Section)
}
}
}
}
return count
}