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 |
|
||||
CharLiteral | ComptimeCall | ConcatExpr | EnumVal | FloatLiteral | Ident | IfExpr | IfGuardExpr |
|
||||
IndexExpr | InfixExpr | IntegerLiteral | Likely | LockExpr | MapInit | MatchExpr | None | OrExpr |
|
||||
ParExpr | PostfixExpr | PrefixExpr | RangeExpr | SelectorExpr | SizeOf | SqlExpr | StringInterLiteral |
|
||||
StringLiteral | StructInit | Type | TypeOf
|
||||
IndexExpr | InfixExpr | IntegerLiteral | Likely | LockExpr | MapInit | MatchExpr | None |
|
||||
OrExpr | ParExpr | PostfixExpr | PrefixExpr | RangeExpr | SelectorExpr | SizeOf | SqlExpr |
|
||||
StringInterLiteral | StringLiteral | StructInit | Type | TypeOf
|
||||
|
||||
pub type Stmt = AssertStmt | AssignStmt | Attr | Block | BranchStmt | Comment | CompFor |
|
||||
CompIf | ConstDecl | DeferStmt | EnumDecl | ExprStmt | FnDecl | ForCStmt | ForInStmt |
|
||||
|
@ -587,6 +587,7 @@ pub mut:
|
|||
pub struct Attr {
|
||||
pub:
|
||||
name string
|
||||
is_string bool // `['xxx']`
|
||||
}
|
||||
|
||||
pub fn (attrs []Attr) contains(attr Attr) bool {
|
||||
|
|
|
@ -278,8 +278,12 @@ pub fn (mut f Fmt) stmt(node ast.Stmt) {
|
|||
f.writeln('')
|
||||
}
|
||||
ast.Attr {
|
||||
if node.is_string {
|
||||
f.writeln("['$node.name']")
|
||||
} else {
|
||||
f.writeln('[$node.name]')
|
||||
}
|
||||
}
|
||||
ast.Block {
|
||||
f.writeln('{')
|
||||
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() {
|
||||
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` {
|
||||
break
|
||||
}
|
||||
|
|
|
@ -656,7 +656,8 @@ fn (mut p Parser) parse_attr() ast.Attr {
|
|||
is_if_attr = true
|
||||
}
|
||||
mut name := ''
|
||||
if p.tok.kind == .string {
|
||||
is_string := p.tok.kind == .string
|
||||
if is_string {
|
||||
name = p.tok.lit
|
||||
p.next()
|
||||
} else {
|
||||
|
@ -677,6 +678,7 @@ fn (mut p Parser) parse_attr() ast.Attr {
|
|||
}
|
||||
return ast.Attr{
|
||||
name: name
|
||||
is_string: is_string
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue