| 1 |
// Copyright (c) 2016, Daniel Martà <[email protected]> |
| 2 |
// See LICENSE for licensing information |
| 3 |
|
| 4 |
package syntax |
| 5 |
|
| 6 |
//go:generate go tool stringer -type token -linecomment -trimprefix _ |
| 7 |
//go:generate go run gen_token_parse.go |
| 8 |
|
| 9 |
type token uint32 |
| 10 |
|
| 11 |
// The list of all possible tokens. |
| 12 |
const ( |
| 13 |
illegalTok token = iota |
| 14 |
|
| 15 |
_EOF |
| 16 |
_Newl |
| 17 |
_Lit |
| 18 |
_LitWord |
| 19 |
_LitRedir |
| 20 |
|
| 21 |
// Token values beyond this point stringify as exact source. |
| 22 |
_realTokenBoundary |
| 23 |
|
| 24 |
sglQuote // ' |
| 25 |
dblQuote // " |
| 26 |
bckQuote // ` |
| 27 |
|
| 28 |
and // & |
| 29 |
andAnd // && |
| 30 |
orOr // || |
| 31 |
or // | |
| 32 |
orAnd // |& |
| 33 |
andPipe // &| |
| 34 |
andBang // &! |
| 35 |
|
| 36 |
dollar // $ |
| 37 |
dollSglQuote // $' |
| 38 |
dollDblQuote // $" |
| 39 |
dollBrace // ${ |
| 40 |
dollBrack // $[ |
| 41 |
dollParen // $( |
| 42 |
dollDblParen // $(( |
| 43 |
leftBrace // { |
| 44 |
leftBrack // [ |
| 45 |
dblLeftBrack // [[ |
| 46 |
leftParen // ( |
| 47 |
dblLeftParen // (( |
| 48 |
|
| 49 |
rightBrace // } |
| 50 |
rightBrack // ] |
| 51 |
dblRightBrack // ]] |
| 52 |
rightParen // ) |
| 53 |
dblRightParen // )) |
| 54 |
semicolon // ; |
| 55 |
|
| 56 |
dblSemicolon // ;; |
| 57 |
semiAnd // ;& |
| 58 |
dblSemiAnd // ;;& |
| 59 |
semiOr // ;| |
| 60 |
|
| 61 |
exclMark // ! |
| 62 |
tilde // ~ |
| 63 |
addAdd // ++ |
| 64 |
subSub // -- |
| 65 |
star // * |
| 66 |
power // ** |
| 67 |
equal // == |
| 68 |
nequal // != |
| 69 |
lequal // <= |
| 70 |
gequal // >= |
| 71 |
|
| 72 |
addAssgn // += |
| 73 |
subAssgn // -= |
| 74 |
mulAssgn // *= |
| 75 |
quoAssgn // /= |
| 76 |
remAssgn // %= |
| 77 |
andAssgn // &= |
| 78 |
orAssgn // |= |
| 79 |
xorAssgn // ^= |
| 80 |
shlAssgn // <<= |
| 81 |
shrAssgn // >>= |
| 82 |
andBoolAssgn // &&= |
| 83 |
orBoolAssgn // ||= |
| 84 |
xorBoolAssgn // ^^= |
| 85 |
powAssgn // **= |
| 86 |
|
| 87 |
rdrOut // > |
| 88 |
appOut // >> |
| 89 |
rdrIn // < |
| 90 |
rdrInOut // <> |
| 91 |
dplIn // <& |
| 92 |
dplOut // >& |
| 93 |
rdrClob // >| |
| 94 |
appClob // >>| |
| 95 |
hdoc // << |
| 96 |
dashHdoc // <<- |
| 97 |
wordHdoc // <<< |
| 98 |
rdrAll // &> |
| 99 |
rdrAllClob // &>| |
| 100 |
appAll // &>> |
| 101 |
appAllClob // &>>| |
| 102 |
|
| 103 |
cmdIn // <( |
| 104 |
assgnParen // =( |
| 105 |
cmdOut // >( |
| 106 |
|
| 107 |
plus // + |
| 108 |
colPlus // :+ |
| 109 |
minus // - |
| 110 |
colMinus // :- |
| 111 |
quest // ? |
| 112 |
colQuest // :? |
| 113 |
assgn // = |
| 114 |
colAssgn // := |
| 115 |
perc // % |
| 116 |
dblPerc // %% |
| 117 |
hash // # |
| 118 |
dblHash // ## |
| 119 |
colHash // :# |
| 120 |
colPipe // :| |
| 121 |
colStar // :* |
| 122 |
caret // ^ |
| 123 |
dblCaret // ^^ |
| 124 |
comma // , |
| 125 |
dblComma // ,, |
| 126 |
at // @ |
| 127 |
slash // / |
| 128 |
dblSlash // // |
| 129 |
period // . |
| 130 |
colon // : |
| 131 |
|
| 132 |
tsExists // -e |
| 133 |
tsRegFile // -f |
| 134 |
tsDirect // -d |
| 135 |
tsCharSp // -c |
| 136 |
tsBlckSp // -b |
| 137 |
tsNmPipe // -p |
| 138 |
tsSocket // -S |
| 139 |
tsSmbLink // -L |
| 140 |
tsSticky // -k |
| 141 |
tsGIDSet // -g |
| 142 |
tsUIDSet // -u |
| 143 |
tsGrpOwn // -G |
| 144 |
tsUsrOwn // -O |
| 145 |
tsModif // -N |
| 146 |
tsRead // -r |
| 147 |
tsWrite // -w |
| 148 |
tsExec // -x |
| 149 |
tsNoEmpty // -s |
| 150 |
tsFdTerm // -t |
| 151 |
tsEmpStr // -z |
| 152 |
tsNempStr // -n |
| 153 |
tsOptSet // -o |
| 154 |
tsVarSet // -v |
| 155 |
tsRefVar // -R |
| 156 |
|
| 157 |
tsReMatch // =~ |
| 158 |
tsNewer // -nt |
| 159 |
tsOlder // -ot |
| 160 |
tsDevIno // -ef |
| 161 |
tsEql // -eq |
| 162 |
tsNeq // -ne |
| 163 |
tsLeq // -le |
| 164 |
tsGeq // -ge |
| 165 |
tsLss // -lt |
| 166 |
tsGtr // -gt |
| 167 |
|
| 168 |
globQuest // ?( |
| 169 |
globStar // *( |
| 170 |
globPlus // +( |
| 171 |
globAt // @( |
| 172 |
globExcl // !( |
| 173 |
) |
| 174 |
|
| 175 |
func (t token) isLit() bool { |
| 176 |
return t == _Lit || t == _LitWord || t == _LitRedir |
| 177 |
} |
| 178 |
|
| 179 |
type RedirOperator token |
| 180 |
|
| 181 |
const ( |
| 182 |
RdrOut = RedirOperator(rdrOut) + iota // > |
| 183 |
AppOut // >> |
| 184 |
RdrIn // < |
| 185 |
RdrInOut // <> |
| 186 |
DplIn // <& |
| 187 |
DplOut // >& |
| 188 |
RdrClob // >| |
| 189 |
AppClob // >>| with [LangZsh] |
| 190 |
Hdoc // << |
| 191 |
DashHdoc // <<- |
| 192 |
WordHdoc // <<< |
| 193 |
RdrAll // &> |
| 194 |
RdrAllClob // &>| with [LangZsh] |
| 195 |
AppAll // &>> |
| 196 |
AppAllClob // &>>| with [LangZsh] |
| 197 |
|
| 198 |
// Deprecated: use [RdrClob] |
| 199 |
// |
| 200 |
//go:fix inline |
| 201 |
ClbOut = RdrClob |
| 202 |
) |
| 203 |
|
| 204 |
type ProcOperator token |
| 205 |
|
| 206 |
const ( |
| 207 |
CmdIn = ProcOperator(cmdIn) + iota // <( |
| 208 |
CmdInTemp // =( |
| 209 |
CmdOut // >( |
| 210 |
) |
| 211 |
|
| 212 |
type GlobOperator token |
| 213 |
|
| 214 |
const ( |
| 215 |
GlobZeroOrOne = GlobOperator(globQuest) + iota // ?( |
| 216 |
GlobZeroOrMore // *( |
| 217 |
GlobOneOrMore // +( |
| 218 |
GlobOne // @( |
| 219 |
GlobExcept // !( |
| 220 |
) |
| 221 |
|
| 222 |
type BinCmdOperator token |
| 223 |
|
| 224 |
const ( |
| 225 |
AndStmt = BinCmdOperator(andAnd) + iota // && |
| 226 |
OrStmt // || |
| 227 |
Pipe // | |
| 228 |
PipeAll // |& |
| 229 |
) |
| 230 |
|
| 231 |
type CaseOperator token |
| 232 |
|
| 233 |
const ( |
| 234 |
Break = CaseOperator(dblSemicolon) + iota // ;; |
| 235 |
Fallthrough // ;& |
| 236 |
Resume // ;;& |
| 237 |
ResumeKorn // ;| |
| 238 |
) |
| 239 |
|
| 240 |
type ParNamesOperator token |
| 241 |
|
| 242 |
const ( |
| 243 |
NamesPrefix = ParNamesOperator(star) // * |
| 244 |
NamesPrefixWords = ParNamesOperator(at) // @ |
| 245 |
) |
| 246 |
|
| 247 |
type ParExpOperator token |
| 248 |
|
| 249 |
const ( |
| 250 |
AlternateUnset = ParExpOperator(plus) + iota // + |
| 251 |
AlternateUnsetOrNull // :+ |
| 252 |
DefaultUnset // - |
| 253 |
DefaultUnsetOrNull // :- |
| 254 |
ErrorUnset // ? |
| 255 |
ErrorUnsetOrNull // :? |
| 256 |
AssignUnset // = |
| 257 |
AssignUnsetOrNull // := |
| 258 |
RemSmallSuffix // % |
| 259 |
RemLargeSuffix // %% |
| 260 |
RemSmallPrefix // # |
| 261 |
RemLargePrefix // ## |
| 262 |
MatchEmpty // :# with [LangZsh] |
| 263 |
ArrayExclude // :| with [LangZsh] |
| 264 |
ArrayIntersect // :* with [LangZsh] |
| 265 |
UpperFirst // ^ |
| 266 |
UpperAll // ^^ |
| 267 |
LowerFirst // , |
| 268 |
LowerAll // ,, |
| 269 |
OtherParamOps // @ |
| 270 |
) |
| 271 |
|
| 272 |
type UnAritOperator token |
| 273 |
|
| 274 |
const ( |
| 275 |
Not = UnAritOperator(exclMark) + iota // ! |
| 276 |
BitNegation // ~ |
| 277 |
Inc // ++ |
| 278 |
Dec // -- |
| 279 |
Plus = UnAritOperator(plus) // + |
| 280 |
Minus = UnAritOperator(minus) // - |
| 281 |
) |
| 282 |
|
| 283 |
type BinAritOperator token |
| 284 |
|
| 285 |
const ( |
| 286 |
Add = BinAritOperator(plus) // + |
| 287 |
Sub = BinAritOperator(minus) // - |
| 288 |
Mul = BinAritOperator(star) // * |
| 289 |
Quo = BinAritOperator(slash) // / |
| 290 |
Rem = BinAritOperator(perc) // % |
| 291 |
Pow = BinAritOperator(power) // ** |
| 292 |
Eql = BinAritOperator(equal) // == |
| 293 |
Gtr = BinAritOperator(rdrOut) // > |
| 294 |
Lss = BinAritOperator(rdrIn) // < |
| 295 |
Neq = BinAritOperator(nequal) // != |
| 296 |
Leq = BinAritOperator(lequal) // <= |
| 297 |
Geq = BinAritOperator(gequal) // >= |
| 298 |
And = BinAritOperator(and) // & |
| 299 |
Or = BinAritOperator(or) // | |
| 300 |
Xor = BinAritOperator(caret) // ^ |
| 301 |
Shr = BinAritOperator(appOut) // >> |
| 302 |
Shl = BinAritOperator(hdoc) // << |
| 303 |
|
| 304 |
// TODO: use "Bool" consistently for logical operators like AndArit and OrArit; use //go:fix inline? |
| 305 |
|
| 306 |
AndArit = BinAritOperator(andAnd) // && |
| 307 |
OrArit = BinAritOperator(orOr) // || |
| 308 |
XorBool = BinAritOperator(dblCaret) // ^^ |
| 309 |
Comma = BinAritOperator(comma) // , |
| 310 |
TernQuest = BinAritOperator(quest) // ? |
| 311 |
TernColon = BinAritOperator(colon) // : |
| 312 |
|
| 313 |
Assgn = BinAritOperator(assgn) // = |
| 314 |
AddAssgn = BinAritOperator(addAssgn) // += |
| 315 |
SubAssgn = BinAritOperator(subAssgn) // -= |
| 316 |
MulAssgn = BinAritOperator(mulAssgn) // *= |
| 317 |
QuoAssgn = BinAritOperator(quoAssgn) // /= |
| 318 |
RemAssgn = BinAritOperator(remAssgn) // %= |
| 319 |
AndAssgn = BinAritOperator(andAssgn) // &= |
| 320 |
OrAssgn = BinAritOperator(orAssgn) // |= |
| 321 |
XorAssgn = BinAritOperator(xorAssgn) // ^= |
| 322 |
ShlAssgn = BinAritOperator(shlAssgn) // <<= |
| 323 |
ShrAssgn = BinAritOperator(shrAssgn) // >>= |
| 324 |
AndBoolAssgn = BinAritOperator(andBoolAssgn) // &&= |
| 325 |
OrBoolAssgn = BinAritOperator(orBoolAssgn) // ||= |
| 326 |
XorBoolAssgn = BinAritOperator(xorBoolAssgn) // ^^= |
| 327 |
PowAssgn = BinAritOperator(powAssgn) // **= |
| 328 |
) |
| 329 |
|
| 330 |
type UnTestOperator token |
| 331 |
|
| 332 |
const ( |
| 333 |
TsExists = UnTestOperator(tsExists) + iota // -e |
| 334 |
TsRegFile // -f |
| 335 |
TsDirect // -d |
| 336 |
TsCharSp // -c |
| 337 |
TsBlckSp // -b |
| 338 |
TsNmPipe // -p |
| 339 |
TsSocket // -S |
| 340 |
TsSmbLink // -L |
| 341 |
TsSticky // -k |
| 342 |
TsGIDSet // -g |
| 343 |
TsUIDSet // -u |
| 344 |
TsGrpOwn // -G |
| 345 |
TsUsrOwn // -O |
| 346 |
TsModif // -N |
| 347 |
TsRead // -r |
| 348 |
TsWrite // -w |
| 349 |
TsExec // -x |
| 350 |
TsNoEmpty // -s |
| 351 |
TsFdTerm // -t |
| 352 |
TsEmpStr // -z |
| 353 |
TsNempStr // -n |
| 354 |
TsOptSet // -o |
| 355 |
TsVarSet // -v |
| 356 |
TsRefVar // -R |
| 357 |
TsNot = UnTestOperator(exclMark) // ! |
| 358 |
TsParen = UnTestOperator(leftParen) // ( |
| 359 |
) |
| 360 |
|
| 361 |
type BinTestOperator token |
| 362 |
|
| 363 |
const ( |
| 364 |
TsReMatch = BinTestOperator(tsReMatch) + iota // =~ |
| 365 |
TsNewer // -nt |
| 366 |
TsOlder // -ot |
| 367 |
TsDevIno // -ef |
| 368 |
TsEql // -eq |
| 369 |
TsNeq // -ne |
| 370 |
TsLeq // -le |
| 371 |
TsGeq // -ge |
| 372 |
TsLss // -lt |
| 373 |
TsGtr // -gt |
| 374 |
AndTest = BinTestOperator(andAnd) // && |
| 375 |
OrTest = BinTestOperator(orOr) // || |
| 376 |
TsMatchShort = BinTestOperator(assgn) // = |
| 377 |
TsMatch = BinTestOperator(equal) // == |
| 378 |
TsNoMatch = BinTestOperator(nequal) // != |
| 379 |
TsBefore = BinTestOperator(rdrIn) // < |
| 380 |
TsAfter = BinTestOperator(rdrOut) // > |
| 381 |
) |
| 382 |
|
| 383 |
func (o RedirOperator) String() string { return token(o).String() } |
| 384 |
func (o ProcOperator) String() string { return token(o).String() } |
| 385 |
func (o GlobOperator) String() string { return token(o).String() } |
| 386 |
func (o BinCmdOperator) String() string { return token(o).String() } |
| 387 |
func (o CaseOperator) String() string { return token(o).String() } |
| 388 |
func (o ParNamesOperator) String() string { return token(o).String() } |
| 389 |
func (o ParExpOperator) String() string { return token(o).String() } |
| 390 |
func (o UnAritOperator) String() string { return token(o).String() } |
| 391 |
func (o BinAritOperator) String() string { return token(o).String() } |
| 392 |
func (o UnTestOperator) String() string { return token(o).String() } |
| 393 |
func (o BinTestOperator) String() string { return token(o).String() } |