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.
This commit is contained in:
33
examples/langV2/debug.go
Normal file
33
examples/langV2/debug.go
Normal file
@ -0,0 +1,33 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"masonry/langV2"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Read the example.masonry file
|
||||
content, err := ioutil.ReadFile("example.masonry2")
|
||||
if err != nil {
|
||||
fmt.Printf("Error reading example.masonry: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
input := string(content)
|
||||
|
||||
ast, err := langV2.ParseInput(input)
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
} else {
|
||||
fmt.Printf("🎉 Successfully parsed complete DSL with pages!\n\n")
|
||||
|
||||
out, err := json.MarshalIndent(ast, "", " ")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
println(string(out))
|
||||
|
||||
}
|
||||
}
|
39
examples/langV2/example.masonry2
Normal file
39
examples/langV2/example.masonry2
Normal file
@ -0,0 +1,39 @@
|
||||
entity User {
|
||||
id: string required unique
|
||||
email: string required unique validate email
|
||||
name: string required
|
||||
age: int validate min "18"
|
||||
created_at: datetime
|
||||
}
|
||||
|
||||
entity Post {
|
||||
id: string required unique
|
||||
title: string required validate maxlen "100"
|
||||
content: string required
|
||||
author_id: string required relates to User as one via "user_id"
|
||||
published: bool default "false"
|
||||
}
|
||||
|
||||
server UserService {
|
||||
GET "/users" entity User
|
||||
POST "/users" entity User
|
||||
GET "/users/{id}" entity User
|
||||
PUT "/users/{id}" entity User
|
||||
}
|
||||
|
||||
server BlogService {
|
||||
GET "/posts" entity Post
|
||||
POST "/posts" entity Post
|
||||
GET "/posts/{id}" entity Post
|
||||
DELETE "/posts/{id}" entity Post
|
||||
}
|
||||
|
||||
page UserProfile {
|
||||
User from UserService
|
||||
Post from BlogService
|
||||
}
|
||||
|
||||
page Dashboard {
|
||||
User from UserService
|
||||
Post from BlogService
|
||||
}
|
Reference in New Issue
Block a user