github.com/benhoyt/goawk@v1.8.1/internal/ast/specialvars.go (about)

     1  // Special variable constants
     2  
     3  package ast
     4  
     5  const (
     6  	V_ILLEGAL = iota
     7  	V_ARGC
     8  	V_CONVFMT
     9  	V_FILENAME
    10  	V_FNR
    11  	V_FS
    12  	V_NF
    13  	V_NR
    14  	V_OFMT
    15  	V_OFS
    16  	V_ORS
    17  	V_RLENGTH
    18  	V_RS
    19  	V_RSTART
    20  	V_SUBSEP
    21  
    22  	V_LAST = V_SUBSEP
    23  )
    24  
    25  var specialVars = map[string]int{
    26  	"ARGC":     V_ARGC,
    27  	"CONVFMT":  V_CONVFMT,
    28  	"FILENAME": V_FILENAME,
    29  	"FNR":      V_FNR,
    30  	"FS":       V_FS,
    31  	"NF":       V_NF,
    32  	"NR":       V_NR,
    33  	"OFMT":     V_OFMT,
    34  	"OFS":      V_OFS,
    35  	"ORS":      V_ORS,
    36  	"RLENGTH":  V_RLENGTH,
    37  	"RS":       V_RS,
    38  	"RSTART":   V_RSTART,
    39  	"SUBSEP":   V_SUBSEP,
    40  }
    41  
    42  // SpecialVarIndex returns the "index" of the special variable, or 0
    43  // if it's not a special variable.
    44  func SpecialVarIndex(name string) int {
    45  	return specialVars[name]
    46  }