"How would swift grammar look if written in swift itself?"
4K lines, several 's, few
's and 2 days later got to this answer:
func test() {
let app = top_level_declaration(
statements(
.declaration(
.function_declaration(
.init(
function_name: .identifier(
.identifier_name(.init("main"))
),
function_signature: .normal(
.init(
parameter_clause: .empty()
)
),
function_body: .init(
statements: .init(
.expression(
.init(
.normal(
.init(
.function_call_expression(
.normal(
postfix_expression: .primary_expression(
.identifier_with_arguments(
.init(
.identifier_name(.init("print"))
)
)
),
function_call_argument_clause: .normal(
.init(
.single(
.expression(
.init(
.normal(
.init(
.primary_expression(
.literal_expression(
.literal(
.string_literal(
.static_string_literal(.single_line("Hello, World"))
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)!
print(app)
}
Prints this obviously:
func main(){print("Hello, World")}
Perhaps the most ridiculous "Hello World" app ever.