vfmt: handle string attrs
parent
7778cbe9f5
commit
188bad4f38
|
@ -11,9 +11,9 @@ pub type TypeDecl = AliasTypeDecl | FnTypeDecl | SumTypeDecl
|
||||||
|
|
||||||
pub type Expr = AnonFn | ArrayInit | AsCast | Assoc | BoolLiteral | CallExpr | CastExpr |
|
pub type Expr = AnonFn | ArrayInit | AsCast | Assoc | BoolLiteral | CallExpr | CastExpr |
|
||||||
CharLiteral | ComptimeCall | ConcatExpr | EnumVal | FloatLiteral | Ident | IfExpr | IfGuardExpr |
|
CharLiteral | ComptimeCall | ConcatExpr | EnumVal | FloatLiteral | Ident | IfExpr | IfGuardExpr |
|
||||||
IndexExpr | InfixExpr | IntegerLiteral | Likely | LockExpr | MapInit | MatchExpr | None | OrExpr |
|
IndexExpr | InfixExpr | IntegerLiteral | Likely | LockExpr | MapInit | MatchExpr | None |
|
||||||
ParExpr | PostfixExpr | PrefixExpr | RangeExpr | SelectorExpr | SizeOf | SqlExpr | StringInterLiteral |
|
OrExpr | ParExpr | PostfixExpr | PrefixExpr | RangeExpr | SelectorExpr | SizeOf | SqlExpr |
|
||||||
StringLiteral | StructInit | Type | TypeOf
|
StringInterLiteral | StringLiteral | StructInit | Type | TypeOf
|
||||||
|
|
||||||
pub type Stmt = AssertStmt | AssignStmt | Attr | Block | BranchStmt | Comment | CompFor |
|
pub type Stmt = AssertStmt | AssignStmt | Attr | Block | BranchStmt | Comment | CompFor |
|
||||||
CompIf | ConstDecl | DeferStmt | EnumDecl | ExprStmt | FnDecl | ForCStmt | ForInStmt |
|
CompIf | ConstDecl | DeferStmt | EnumDecl | ExprStmt | FnDecl | ForCStmt | ForInStmt |
|
||||||
|
@ -587,6 +587,7 @@ pub mut:
|
||||||
pub struct Attr {
|
pub struct Attr {
|
||||||
pub:
|
pub:
|
||||||
name string
|
name string
|
||||||
|
is_string bool // `['xxx']`
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (attrs []Attr) contains(attr Attr) bool {
|
pub fn (attrs []Attr) contains(attr Attr) bool {
|
||||||
|
|
|
@ -278,8 +278,12 @@ pub fn (mut f Fmt) stmt(node ast.Stmt) {
|
||||||
f.writeln('')
|
f.writeln('')
|
||||||
}
|
}
|
||||||
ast.Attr {
|
ast.Attr {
|
||||||
|
if node.is_string {
|
||||||
|
f.writeln("['$node.name']")
|
||||||
|
} else {
|
||||||
f.writeln('[$node.name]')
|
f.writeln('[$node.name]')
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ast.Block {
|
ast.Block {
|
||||||
f.writeln('{')
|
f.writeln('{')
|
||||||
f.stmts(node.stmts)
|
f.stmts(node.stmts)
|
||||||
|
@ -1375,8 +1379,7 @@ pub fn (mut f Fmt) match_expr(it ast.MatchExpr) {
|
||||||
|
|
||||||
pub fn (mut f Fmt) remove_new_line() {
|
pub fn (mut f Fmt) remove_new_line() {
|
||||||
mut i := 0
|
mut i := 0
|
||||||
for i = f.out.len - 1; i >= 0; i--
|
for i = f.out.len - 1; i >= 0; i-- {
|
||||||
{
|
|
||||||
if !f.out.buf[i].is_space() { // != `\n` {
|
if !f.out.buf[i].is_space() { // != `\n` {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
@ -656,7 +656,8 @@ fn (mut p Parser) parse_attr() ast.Attr {
|
||||||
is_if_attr = true
|
is_if_attr = true
|
||||||
}
|
}
|
||||||
mut name := ''
|
mut name := ''
|
||||||
if p.tok.kind == .string {
|
is_string := p.tok.kind == .string
|
||||||
|
if is_string {
|
||||||
name = p.tok.lit
|
name = p.tok.lit
|
||||||
p.next()
|
p.next()
|
||||||
} else {
|
} else {
|
||||||
|
@ -677,6 +678,7 @@ fn (mut p Parser) parse_attr() ast.Attr {
|
||||||
}
|
}
|
||||||
return ast.Attr{
|
return ast.Attr{
|
||||||
name: name
|
name: name
|
||||||
|
is_string: is_string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue