Compare commits

...

2 Commits

Author SHA1 Message Date
f1a998c25b Update example bulma version 2024-06-06 18:52:26 -07:00
167f448ae1 Improve ternary expression parsing definition 2024-06-06 18:52:14 -07:00
5 changed files with 482 additions and 468 deletions

View File

@ -1,4 +1,4 @@
<head> <head>
<title>#(title)</title> <title>#(title)</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.4/css/bulma.min.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@1.0.0/css/bulma.min.css">
</head> </head>

View File

@ -1,7 +1,7 @@
<html> <html>
<head> <head>
<title>#(title)</title> <title>#(title)</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.4/css/bulma.min.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@1.0.0/css/bulma.min.css">
</head> </head>
<body> <body>
<nav class="navbar is-dark"> <nav class="navbar is-dark">

View File

@ -1,7 +1,9 @@
<html> <html>
<head> <head>
<title>#(page.Title)</title> <title>#(page.Title)</title>
</head> </head>
<body> <body>
#for(i, user in users): #for(i, user in users):
<div> <div>
@ -13,4 +15,5 @@
</div> </div>
#!for #!for
</body> </body>
</html> </html>

File diff suppressed because it is too large Load Diff

View File

@ -83,8 +83,21 @@ ExprTag = '#' ignoreErr:'?'? '(' item:Expr ')' {
}, nil }, nil
} }
Expr = Ternary / Assignment / LogicalExpr Expr = Assignment / TernaryExpr
Assignable = Ternary / LogicalExpr Assignable = TernaryExpr
TernaryExpr = _ cond:LogicalExpr vals:(_ '?' _ Value _ ':' _ Value)? {
if vals == nil {
return cond, nil
} else {
s := toAnySlice(vals)
return ast.Ternary{
Condition: cond.(ast.Node),
IfTrue: s[3].(ast.Node),
Else: s[7].(ast.Node),
}, nil
}
}
LogicalExpr = _ first:ComparisonExpr rest:(_ LogicalOp _ ComparisonExpr)* _ { LogicalExpr = _ first:ComparisonExpr rest:(_ LogicalOp _ ComparisonExpr)* _ {
return toExpr(c, first, rest), nil return toExpr(c, first, rest), nil
@ -174,14 +187,6 @@ Assignment = name:Ident _ '=' _ value:Assignable {
}, nil }, nil
} }
Ternary = cond:Assignable _ '?' _ ifTrue:Value _ ':' _ elseVal:Value {
return ast.Ternary{
Condition: cond.(ast.Node),
IfTrue: ifTrue.(ast.Node),
Else: elseVal.(ast.Node),
}, nil
}
MethodCall = value:Value '.' name:Ident params:ParamList { MethodCall = value:Value '.' name:Ident params:ParamList {
return ast.MethodCall{ return ast.MethodCall{
Value: value.(ast.Node), Value: value.(ast.Node),