parse.y.go 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531
  1. //line build/parse.y:13
  2. package build
  3. import __yyfmt__ "fmt"
  4. //line build/parse.y:13
  5. //line build/parse.y:18
  6. type yySymType struct {
  7. yys int
  8. // input tokens
  9. tok string // raw input syntax
  10. str string // decoding of quoted string
  11. pos Position // position of token
  12. triple bool // was string triple quoted?
  13. // partial syntax trees
  14. expr Expr
  15. exprs []Expr
  16. forc *ForClause
  17. ifs []*IfClause
  18. forifs *ForClauseWithIfClausesOpt
  19. forsifs []*ForClauseWithIfClausesOpt
  20. string *StringExpr
  21. strings []*StringExpr
  22. block CodeBlock
  23. // supporting information
  24. comma Position // position of trailing comma in list, if present
  25. lastRule Expr // most recent rule, to attach line comments to
  26. }
  27. const _AUGM = 57346
  28. const _AND = 57347
  29. const _COMMENT = 57348
  30. const _EOF = 57349
  31. const _EQ = 57350
  32. const _FOR = 57351
  33. const _GE = 57352
  34. const _IDENT = 57353
  35. const _IF = 57354
  36. const _ELSE = 57355
  37. const _ELIF = 57356
  38. const _IN = 57357
  39. const _IS = 57358
  40. const _LAMBDA = 57359
  41. const _LOAD = 57360
  42. const _LE = 57361
  43. const _NE = 57362
  44. const _NOT = 57363
  45. const _OR = 57364
  46. const _PYTHON = 57365
  47. const _STRING = 57366
  48. const _DEF = 57367
  49. const _RETURN = 57368
  50. const _INDENT = 57369
  51. const _UNINDENT = 57370
  52. const ShiftInstead = 57371
  53. const _ASSERT = 57372
  54. const _UNARY = 57373
  55. var yyToknames = [...]string{
  56. "$end",
  57. "error",
  58. "$unk",
  59. "'%'",
  60. "'('",
  61. "')'",
  62. "'*'",
  63. "'+'",
  64. "','",
  65. "'-'",
  66. "'.'",
  67. "'/'",
  68. "':'",
  69. "'<'",
  70. "'='",
  71. "'>'",
  72. "'['",
  73. "']'",
  74. "'{'",
  75. "'}'",
  76. "_AUGM",
  77. "_AND",
  78. "_COMMENT",
  79. "_EOF",
  80. "_EQ",
  81. "_FOR",
  82. "_GE",
  83. "_IDENT",
  84. "_IF",
  85. "_ELSE",
  86. "_ELIF",
  87. "_IN",
  88. "_IS",
  89. "_LAMBDA",
  90. "_LOAD",
  91. "_LE",
  92. "_NE",
  93. "_NOT",
  94. "_OR",
  95. "_PYTHON",
  96. "_STRING",
  97. "_DEF",
  98. "_RETURN",
  99. "_INDENT",
  100. "_UNINDENT",
  101. "ShiftInstead",
  102. "'\\n'",
  103. "_ASSERT",
  104. "_UNARY",
  105. "';'",
  106. }
  107. var yyStatenames = [...]string{}
  108. const yyEofCode = 1
  109. const yyErrCode = 2
  110. const yyInitialStackSize = 16
  111. //line build/parse.y:738
  112. // Go helper code.
  113. // unary returns a unary expression with the given
  114. // position, operator, and subexpression.
  115. func unary(pos Position, op string, x Expr) Expr {
  116. return &UnaryExpr{
  117. OpStart: pos,
  118. Op: op,
  119. X: x,
  120. }
  121. }
  122. // binary returns a binary expression with the given
  123. // operands, position, and operator.
  124. func binary(x Expr, pos Position, op string, y Expr) Expr {
  125. _, xend := x.Span()
  126. ystart, _ := y.Span()
  127. return &BinaryExpr{
  128. X: x,
  129. OpStart: pos,
  130. Op: op,
  131. LineBreak: xend.Line < ystart.Line,
  132. Y: y,
  133. }
  134. }
  135. // isSimpleExpression returns whether an expression is simple and allowed to exist in
  136. // compact forms of sequences.
  137. // The formal criteria are the following: an expression is considered simple if it's
  138. // a literal (variable, string or a number), a literal with a unary operator or an empty sequence.
  139. func isSimpleExpression(expr *Expr) bool {
  140. switch x := (*expr).(type) {
  141. case *LiteralExpr, *StringExpr:
  142. return true
  143. case *UnaryExpr:
  144. _, ok := x.X.(*LiteralExpr)
  145. return ok
  146. case *ListExpr:
  147. return len(x.List) == 0
  148. case *TupleExpr:
  149. return len(x.List) == 0
  150. case *DictExpr:
  151. return len(x.List) == 0
  152. case *SetExpr:
  153. return len(x.List) == 0
  154. default:
  155. return false
  156. }
  157. }
  158. // forceCompact returns the setting for the ForceCompact field for a call or tuple.
  159. //
  160. // NOTE 1: The field is called ForceCompact, not ForceSingleLine,
  161. // because it only affects the formatting associated with the call or tuple syntax,
  162. // not the formatting of the arguments. For example:
  163. //
  164. // call([
  165. // 1,
  166. // 2,
  167. // 3,
  168. // ])
  169. //
  170. // is still a compact call even though it runs on multiple lines.
  171. //
  172. // In contrast the multiline form puts a linebreak after the (.
  173. //
  174. // call(
  175. // [
  176. // 1,
  177. // 2,
  178. // 3,
  179. // ],
  180. // )
  181. //
  182. // NOTE 2: Because of NOTE 1, we cannot use start and end on the
  183. // same line as a signal for compact mode: the formatting of an
  184. // embedded list might move the end to a different line, which would
  185. // then look different on rereading and cause buildifier not to be
  186. // idempotent. Instead, we have to look at properties guaranteed
  187. // to be preserved by the reformatting, namely that the opening
  188. // paren and the first expression are on the same line and that
  189. // each subsequent expression begins on the same line as the last
  190. // one ended (no line breaks after comma).
  191. func forceCompact(start Position, list []Expr, end Position) bool {
  192. if len(list) <= 1 {
  193. // The call or tuple will probably be compact anyway; don't force it.
  194. return false
  195. }
  196. // If there are any named arguments or non-string, non-literal
  197. // arguments, cannot force compact mode.
  198. line := start.Line
  199. for _, x := range list {
  200. start, end := x.Span()
  201. if start.Line != line {
  202. return false
  203. }
  204. line = end.Line
  205. if !isSimpleExpression(&x) {
  206. return false
  207. }
  208. }
  209. return end.Line == line
  210. }
  211. // forceMultiLine returns the setting for the ForceMultiLine field.
  212. func forceMultiLine(start Position, list []Expr, end Position) bool {
  213. if len(list) > 1 {
  214. // The call will be multiline anyway, because it has multiple elements. Don't force it.
  215. return false
  216. }
  217. if len(list) == 0 {
  218. // Empty list: use position of brackets.
  219. return start.Line != end.Line
  220. }
  221. // Single-element list.
  222. // Check whether opening bracket is on different line than beginning of
  223. // element, or closing bracket is on different line than end of element.
  224. elemStart, elemEnd := list[0].Span()
  225. return start.Line != elemStart.Line || end.Line != elemEnd.Line
  226. }
  227. //line yacctab:1
  228. var yyExca = [...]int{
  229. -1, 1,
  230. 1, -1,
  231. -2, 0,
  232. }
  233. const yyPrivate = 57344
  234. const yyLast = 739
  235. var yyAct = [...]int{
  236. 13, 112, 136, 2, 138, 74, 17, 7, 118, 69,
  237. 34, 9, 117, 81, 130, 58, 31, 59, 35, 64,
  238. 65, 66, 161, 30, 102, 70, 72, 77, 37, 38,
  239. 166, 84, 108, 33, 79, 73, 76, 85, 84, 120,
  240. 88, 89, 90, 91, 92, 93, 94, 95, 96, 97,
  241. 98, 99, 100, 101, 167, 103, 104, 105, 106, 86,
  242. 163, 83, 110, 111, 154, 149, 153, 129, 64, 127,
  243. 120, 109, 29, 120, 178, 87, 25, 115, 20, 126,
  244. 120, 27, 116, 64, 133, 123, 120, 125, 24, 172,
  245. 26, 134, 132, 131, 171, 61, 68, 71, 114, 28,
  246. 168, 60, 113, 139, 145, 18, 22, 62, 121, 19,
  247. 141, 158, 30, 148, 146, 147, 63, 40, 142, 82,
  248. 39, 124, 147, 143, 67, 41, 150, 35, 80, 155,
  249. 157, 152, 150, 36, 150, 156, 40, 1, 160, 39,
  250. 42, 162, 43, 23, 41, 78, 165, 164, 75, 32,
  251. 12, 8, 150, 4, 151, 21, 119, 122, 25, 0,
  252. 20, 0, 169, 27, 0, 170, 0, 173, 174, 0,
  253. 24, 175, 26, 165, 177, 7, 6, 0, 25, 11,
  254. 0, 28, 16, 27, 0, 0, 0, 18, 22, 0,
  255. 24, 19, 26, 15, 30, 10, 14, 25, 176, 20,
  256. 5, 28, 27, 0, 0, 0, 0, 0, 22, 24,
  257. 0, 26, 0, 0, 30, 6, 3, 25, 11, 20,
  258. 28, 16, 27, 0, 0, 0, 18, 22, 0, 24,
  259. 19, 26, 15, 30, 10, 14, 0, 0, 0, 5,
  260. 28, 0, 0, 0, 0, 0, 18, 22, 0, 0,
  261. 19, 0, 15, 30, 40, 14, 0, 39, 42, 137,
  262. 43, 0, 41, 128, 44, 50, 45, 0, 0, 0,
  263. 0, 51, 55, 0, 0, 46, 0, 49, 0, 57,
  264. 0, 0, 52, 56, 0, 0, 47, 48, 53, 54,
  265. 40, 0, 0, 39, 42, 0, 43, 0, 41, 159,
  266. 44, 50, 45, 0, 0, 0, 0, 51, 55, 0,
  267. 0, 46, 0, 49, 0, 57, 0, 0, 52, 56,
  268. 0, 0, 47, 48, 53, 54, 40, 0, 0, 39,
  269. 42, 0, 43, 0, 41, 0, 44, 50, 45, 0,
  270. 144, 0, 0, 51, 55, 0, 0, 46, 0, 49,
  271. 0, 57, 0, 0, 52, 56, 0, 0, 47, 48,
  272. 53, 54, 40, 0, 0, 39, 42, 0, 43, 0,
  273. 41, 0, 44, 50, 45, 0, 0, 0, 0, 51,
  274. 55, 0, 0, 46, 120, 49, 0, 57, 0, 0,
  275. 52, 56, 0, 0, 47, 48, 53, 54, 40, 0,
  276. 0, 39, 42, 0, 43, 0, 41, 0, 44, 50,
  277. 45, 0, 0, 0, 0, 51, 55, 0, 0, 46,
  278. 0, 49, 0, 57, 140, 0, 52, 56, 0, 0,
  279. 47, 48, 53, 54, 40, 0, 0, 39, 42, 0,
  280. 43, 0, 41, 135, 44, 50, 45, 0, 0, 0,
  281. 0, 51, 55, 0, 0, 46, 0, 49, 0, 57,
  282. 0, 0, 52, 56, 0, 0, 47, 48, 53, 54,
  283. 40, 0, 0, 39, 42, 0, 43, 0, 41, 107,
  284. 44, 50, 45, 0, 0, 0, 0, 51, 55, 0,
  285. 0, 46, 0, 49, 0, 57, 0, 0, 52, 56,
  286. 0, 0, 47, 48, 53, 54, 40, 0, 0, 39,
  287. 42, 0, 43, 0, 41, 0, 44, 50, 45, 0,
  288. 0, 0, 0, 51, 55, 0, 0, 46, 0, 49,
  289. 0, 57, 0, 0, 52, 56, 0, 0, 47, 48,
  290. 53, 54, 40, 0, 0, 39, 42, 0, 43, 0,
  291. 41, 0, 44, 50, 45, 0, 0, 0, 0, 51,
  292. 55, 0, 0, 46, 0, 49, 0, 0, 0, 0,
  293. 52, 56, 0, 0, 47, 48, 53, 54, 40, 0,
  294. 0, 39, 42, 0, 43, 0, 41, 0, 44, 0,
  295. 45, 0, 0, 0, 0, 0, 55, 0, 0, 46,
  296. 0, 49, 0, 57, 0, 0, 52, 56, 0, 0,
  297. 47, 48, 53, 54, 40, 0, 0, 39, 42, 0,
  298. 43, 0, 41, 0, 44, 0, 45, 0, 0, 0,
  299. 0, 0, 55, 0, 0, 46, 0, 49, 0, 25,
  300. 0, 20, 52, 56, 27, 0, 47, 48, 53, 54,
  301. 0, 24, 0, 26, 0, 40, 0, 0, 39, 42,
  302. 0, 43, 28, 41, 0, 44, 0, 45, 18, 22,
  303. 0, 0, 19, 55, 15, 30, 46, 14, 49, 0,
  304. 0, 0, 0, 0, 0, 0, 0, 47, 48, 40,
  305. 54, 0, 39, 42, 0, 43, 0, 41, 0, 44,
  306. 0, 45, 0, 0, 0, 40, 0, 55, 39, 42,
  307. 46, 43, 49, 41, 0, 44, 0, 45, 0, 0,
  308. 0, 47, 48, 0, 0, 0, 46, 0, 49, 0,
  309. 0, 0, 0, 0, 0, 0, 0, 47, 48,
  310. }
  311. var yyPact = [...]int{
  312. -1000, -1000, 192, -1000, -1000, -1000, -31, -1000, -1000, -1000,
  313. 5, 173, -2, 502, 71, -1000, 71, 90, 71, 71,
  314. 71, -1000, 119, -18, 71, 71, 71, 173, -1000, -1000,
  315. -1000, -1000, -37, 114, 29, 90, 71, 46, -1000, 71,
  316. 71, 71, 71, 71, 71, 71, 71, 71, 71, 71,
  317. 71, 71, 71, -8, 71, 71, 71, 71, 502, 466,
  318. 4, 71, 71, 89, 502, -1000, -1000, 71, -1000, 64,
  319. 358, 99, 358, 115, 13, 59, 49, 250, 58, -1000,
  320. -33, 634, 71, 71, 173, 430, 212, -1000, -1000, -1000,
  321. -1000, 113, 113, 132, 132, 132, 132, 132, 132, 574,
  322. 574, 651, 71, 685, 701, 651, 394, 212, -1000, 112,
  323. 358, 322, 91, 71, 71, 107, -1000, 47, -1000, -1000,
  324. 173, 71, -1000, 60, -1000, 44, -1000, -1000, 71, 71,
  325. -1000, -1000, 105, 286, 90, 212, -1000, -22, -1000, 651,
  326. 71, -1000, -1000, 54, -1000, 71, 610, 502, -1000, -1000,
  327. -1000, 1, 22, -1000, -1000, 502, -1000, 250, 87, 212,
  328. -1000, -1000, 610, -1000, 76, 502, 71, 71, 212, -1000,
  329. 153, -1000, 71, 538, 538, -1000, -1000, 56, -1000,
  330. }
  331. var yyPgo = [...]int{
  332. 0, 157, 0, 1, 6, 97, 9, 10, 156, 8,
  333. 12, 155, 154, 3, 153, 151, 150, 4, 11, 149,
  334. 5, 148, 145, 72, 143, 2, 137, 133, 128,
  335. }
  336. var yyR1 = [...]int{
  337. 0, 26, 25, 25, 13, 13, 13, 13, 14, 14,
  338. 15, 15, 15, 16, 16, 16, 27, 27, 17, 19,
  339. 19, 18, 18, 18, 18, 28, 28, 4, 4, 4,
  340. 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  341. 4, 4, 4, 4, 2, 2, 2, 2, 2, 2,
  342. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  343. 2, 2, 2, 2, 2, 2, 2, 3, 3, 1,
  344. 1, 20, 22, 22, 21, 21, 5, 5, 6, 6,
  345. 7, 7, 23, 24, 24, 11, 8, 9, 10, 10,
  346. 12, 12,
  347. }
  348. var yyR2 = [...]int{
  349. 0, 2, 4, 1, 0, 2, 2, 3, 1, 1,
  350. 7, 6, 1, 4, 5, 4, 2, 1, 4, 0,
  351. 3, 1, 2, 1, 1, 0, 1, 1, 3, 4,
  352. 4, 4, 6, 8, 5, 1, 3, 4, 4, 4,
  353. 3, 3, 3, 2, 1, 4, 2, 2, 3, 3,
  354. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  355. 3, 3, 4, 3, 3, 3, 5, 0, 1, 0,
  356. 1, 3, 1, 3, 1, 2, 1, 3, 0, 2,
  357. 1, 3, 1, 1, 2, 1, 4, 2, 1, 2,
  358. 0, 3,
  359. }
  360. var yyChk = [...]int{
  361. -1000, -26, -13, 24, -14, 47, 23, -17, -15, -18,
  362. 42, 26, -16, -2, 43, 40, 29, -4, 34, 38,
  363. 7, -11, 35, -24, 17, 5, 19, 10, 28, -23,
  364. 41, 47, -19, 28, -7, -4, -27, 30, 31, 7,
  365. 4, 12, 8, 10, 14, 16, 25, 36, 37, 27,
  366. 15, 21, 32, 38, 39, 22, 33, 29, -2, -2,
  367. 11, 5, 17, -5, -2, -2, -2, 5, -23, -6,
  368. -2, -5, -2, -6, -20, -21, -6, -2, -22, -4,
  369. -28, 50, 5, 32, 9, -2, 13, 29, -2, -2,
  370. -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
  371. -2, -2, 32, -2, -2, -2, -2, 13, 28, -6,
  372. -2, -2, -3, 13, 9, -6, 18, -10, -9, -8,
  373. 26, 9, -1, -10, 6, -10, 20, 20, 13, 9,
  374. 47, -18, -6, -2, -4, 13, -25, 47, -17, -2,
  375. 30, -25, 6, -10, 18, 13, -2, -2, 6, 18,
  376. -9, -12, -7, 6, 20, -2, -20, -2, 6, 13,
  377. -25, 44, -2, 6, -3, -2, 29, 32, 13, -25,
  378. -13, 18, 13, -2, -2, -25, 45, -3, 18,
  379. }
  380. var yyDef = [...]int{
  381. 4, -2, 0, 1, 5, 6, 0, 8, 9, 19,
  382. 0, 0, 12, 21, 23, 24, 0, 44, 0, 0,
  383. 0, 27, 0, 35, 78, 78, 78, 0, 85, 83,
  384. 82, 7, 25, 0, 0, 80, 0, 0, 17, 0,
  385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  386. 0, 0, 0, 0, 0, 0, 0, 0, 22, 0,
  387. 0, 78, 67, 0, 76, 46, 47, 78, 84, 0,
  388. 76, 69, 76, 0, 72, 0, 0, 76, 74, 43,
  389. 0, 26, 78, 0, 0, 0, 0, 16, 48, 49,
  390. 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
  391. 60, 61, 0, 63, 64, 65, 0, 0, 28, 0,
  392. 76, 68, 0, 0, 0, 0, 36, 0, 88, 90,
  393. 0, 70, 79, 0, 42, 0, 40, 41, 0, 75,
  394. 18, 20, 0, 0, 81, 0, 15, 0, 3, 62,
  395. 0, 13, 30, 0, 31, 67, 45, 77, 29, 37,
  396. 89, 87, 0, 38, 39, 71, 73, 0, 0, 0,
  397. 14, 4, 66, 34, 0, 68, 0, 0, 0, 11,
  398. 0, 32, 67, 91, 86, 10, 2, 0, 33,
  399. }
  400. var yyTok1 = [...]int{
  401. 1, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  402. 47, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  403. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  404. 3, 3, 3, 3, 3, 3, 3, 4, 3, 3,
  405. 5, 6, 7, 8, 9, 10, 11, 12, 3, 3,
  406. 3, 3, 3, 3, 3, 3, 3, 3, 13, 50,
  407. 14, 15, 16, 3, 3, 3, 3, 3, 3, 3,
  408. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  409. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  410. 3, 17, 3, 18, 3, 3, 3, 3, 3, 3,
  411. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  412. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  413. 3, 3, 3, 19, 3, 20,
  414. }
  415. var yyTok2 = [...]int{
  416. 2, 3, 21, 22, 23, 24, 25, 26, 27, 28,
  417. 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
  418. 39, 40, 41, 42, 43, 44, 45, 46, 48, 49,
  419. }
  420. var yyTok3 = [...]int{
  421. 0,
  422. }
  423. var yyErrorMessages = [...]struct {
  424. state int
  425. token int
  426. msg string
  427. }{}
  428. //line yaccpar:1
  429. /* parser for yacc output */
  430. var (
  431. yyDebug = 0
  432. yyErrorVerbose = false
  433. )
  434. type yyLexer interface {
  435. Lex(lval *yySymType) int
  436. Error(s string)
  437. }
  438. type yyParser interface {
  439. Parse(yyLexer) int
  440. Lookahead() int
  441. }
  442. type yyParserImpl struct {
  443. lval yySymType
  444. stack [yyInitialStackSize]yySymType
  445. char int
  446. }
  447. func (p *yyParserImpl) Lookahead() int {
  448. return p.char
  449. }
  450. func yyNewParser() yyParser {
  451. return &yyParserImpl{}
  452. }
  453. const yyFlag = -1000
  454. func yyTokname(c int) string {
  455. if c >= 1 && c-1 < len(yyToknames) {
  456. if yyToknames[c-1] != "" {
  457. return yyToknames[c-1]
  458. }
  459. }
  460. return __yyfmt__.Sprintf("tok-%v", c)
  461. }
  462. func yyStatname(s int) string {
  463. if s >= 0 && s < len(yyStatenames) {
  464. if yyStatenames[s] != "" {
  465. return yyStatenames[s]
  466. }
  467. }
  468. return __yyfmt__.Sprintf("state-%v", s)
  469. }
  470. func yyErrorMessage(state, lookAhead int) string {
  471. const TOKSTART = 4
  472. if !yyErrorVerbose {
  473. return "syntax error"
  474. }
  475. for _, e := range yyErrorMessages {
  476. if e.state == state && e.token == lookAhead {
  477. return "syntax error: " + e.msg
  478. }
  479. }
  480. res := "syntax error: unexpected " + yyTokname(lookAhead)
  481. // To match Bison, suggest at most four expected tokens.
  482. expected := make([]int, 0, 4)
  483. // Look for shiftable tokens.
  484. base := yyPact[state]
  485. for tok := TOKSTART; tok-1 < len(yyToknames); tok++ {
  486. if n := base + tok; n >= 0 && n < yyLast && yyChk[yyAct[n]] == tok {
  487. if len(expected) == cap(expected) {
  488. return res
  489. }
  490. expected = append(expected, tok)
  491. }
  492. }
  493. if yyDef[state] == -2 {
  494. i := 0
  495. for yyExca[i] != -1 || yyExca[i+1] != state {
  496. i += 2
  497. }
  498. // Look for tokens that we accept or reduce.
  499. for i += 2; yyExca[i] >= 0; i += 2 {
  500. tok := yyExca[i]
  501. if tok < TOKSTART || yyExca[i+1] == 0 {
  502. continue
  503. }
  504. if len(expected) == cap(expected) {
  505. return res
  506. }
  507. expected = append(expected, tok)
  508. }
  509. // If the default action is to accept or reduce, give up.
  510. if yyExca[i+1] != 0 {
  511. return res
  512. }
  513. }
  514. for i, tok := range expected {
  515. if i == 0 {
  516. res += ", expecting "
  517. } else {
  518. res += " or "
  519. }
  520. res += yyTokname(tok)
  521. }
  522. return res
  523. }
  524. func yylex1(lex yyLexer, lval *yySymType) (char, token int) {
  525. token = 0
  526. char = lex.Lex(lval)
  527. if char <= 0 {
  528. token = yyTok1[0]
  529. goto out
  530. }
  531. if char < len(yyTok1) {
  532. token = yyTok1[char]
  533. goto out
  534. }
  535. if char >= yyPrivate {
  536. if char < yyPrivate+len(yyTok2) {
  537. token = yyTok2[char-yyPrivate]
  538. goto out
  539. }
  540. }
  541. for i := 0; i < len(yyTok3); i += 2 {
  542. token = yyTok3[i+0]
  543. if token == char {
  544. token = yyTok3[i+1]
  545. goto out
  546. }
  547. }
  548. out:
  549. if token == 0 {
  550. token = yyTok2[1] /* unknown char */
  551. }
  552. if yyDebug >= 3 {
  553. __yyfmt__.Printf("lex %s(%d)\n", yyTokname(token), uint(char))
  554. }
  555. return char, token
  556. }
  557. func yyParse(yylex yyLexer) int {
  558. return yyNewParser().Parse(yylex)
  559. }
  560. func (yyrcvr *yyParserImpl) Parse(yylex yyLexer) int {
  561. var yyn int
  562. var yyVAL yySymType
  563. var yyDollar []yySymType
  564. _ = yyDollar // silence set and not used
  565. yyS := yyrcvr.stack[:]
  566. Nerrs := 0 /* number of errors */
  567. Errflag := 0 /* error recovery flag */
  568. yystate := 0
  569. yyrcvr.char = -1
  570. yytoken := -1 // yyrcvr.char translated into internal numbering
  571. defer func() {
  572. // Make sure we report no lookahead when not parsing.
  573. yystate = -1
  574. yyrcvr.char = -1
  575. yytoken = -1
  576. }()
  577. yyp := -1
  578. goto yystack
  579. ret0:
  580. return 0
  581. ret1:
  582. return 1
  583. yystack:
  584. /* put a state and value onto the stack */
  585. if yyDebug >= 4 {
  586. __yyfmt__.Printf("char %v in %v\n", yyTokname(yytoken), yyStatname(yystate))
  587. }
  588. yyp++
  589. if yyp >= len(yyS) {
  590. nyys := make([]yySymType, len(yyS)*2)
  591. copy(nyys, yyS)
  592. yyS = nyys
  593. }
  594. yyS[yyp] = yyVAL
  595. yyS[yyp].yys = yystate
  596. yynewstate:
  597. yyn = yyPact[yystate]
  598. if yyn <= yyFlag {
  599. goto yydefault /* simple state */
  600. }
  601. if yyrcvr.char < 0 {
  602. yyrcvr.char, yytoken = yylex1(yylex, &yyrcvr.lval)
  603. }
  604. yyn += yytoken
  605. if yyn < 0 || yyn >= yyLast {
  606. goto yydefault
  607. }
  608. yyn = yyAct[yyn]
  609. if yyChk[yyn] == yytoken { /* valid shift */
  610. yyrcvr.char = -1
  611. yytoken = -1
  612. yyVAL = yyrcvr.lval
  613. yystate = yyn
  614. if Errflag > 0 {
  615. Errflag--
  616. }
  617. goto yystack
  618. }
  619. yydefault:
  620. /* default state action */
  621. yyn = yyDef[yystate]
  622. if yyn == -2 {
  623. if yyrcvr.char < 0 {
  624. yyrcvr.char, yytoken = yylex1(yylex, &yyrcvr.lval)
  625. }
  626. /* look through exception table */
  627. xi := 0
  628. for {
  629. if yyExca[xi+0] == -1 && yyExca[xi+1] == yystate {
  630. break
  631. }
  632. xi += 2
  633. }
  634. for xi += 2; ; xi += 2 {
  635. yyn = yyExca[xi+0]
  636. if yyn < 0 || yyn == yytoken {
  637. break
  638. }
  639. }
  640. yyn = yyExca[xi+1]
  641. if yyn < 0 {
  642. goto ret0
  643. }
  644. }
  645. if yyn == 0 {
  646. /* error ... attempt to resume parsing */
  647. switch Errflag {
  648. case 0: /* brand new error */
  649. yylex.Error(yyErrorMessage(yystate, yytoken))
  650. Nerrs++
  651. if yyDebug >= 1 {
  652. __yyfmt__.Printf("%s", yyStatname(yystate))
  653. __yyfmt__.Printf(" saw %s\n", yyTokname(yytoken))
  654. }
  655. fallthrough
  656. case 1, 2: /* incompletely recovered error ... try again */
  657. Errflag = 3
  658. /* find a state where "error" is a legal shift action */
  659. for yyp >= 0 {
  660. yyn = yyPact[yyS[yyp].yys] + yyErrCode
  661. if yyn >= 0 && yyn < yyLast {
  662. yystate = yyAct[yyn] /* simulate a shift of "error" */
  663. if yyChk[yystate] == yyErrCode {
  664. goto yystack
  665. }
  666. }
  667. /* the current p has no shift on "error", pop stack */
  668. if yyDebug >= 2 {
  669. __yyfmt__.Printf("error recovery pops state %d\n", yyS[yyp].yys)
  670. }
  671. yyp--
  672. }
  673. /* there is no state on the stack with an error shift ... abort */
  674. goto ret1
  675. case 3: /* no shift yet; clobber input char */
  676. if yyDebug >= 2 {
  677. __yyfmt__.Printf("error recovery discards %s\n", yyTokname(yytoken))
  678. }
  679. if yytoken == yyEofCode {
  680. goto ret1
  681. }
  682. yyrcvr.char = -1
  683. yytoken = -1
  684. goto yynewstate /* try again in the same state */
  685. }
  686. }
  687. /* reduction by production yyn */
  688. if yyDebug >= 2 {
  689. __yyfmt__.Printf("reduce %v in:\n\t%v\n", yyn, yyStatname(yystate))
  690. }
  691. yynt := yyn
  692. yypt := yyp
  693. _ = yypt // guard against "declared and not used"
  694. yyp -= yyR2[yyn]
  695. // yyp is now the index of $0. Perform the default action. Iff the
  696. // reduced production is ε, $1 is possibly out of range.
  697. if yyp+1 >= len(yyS) {
  698. nyys := make([]yySymType, len(yyS)*2)
  699. copy(nyys, yyS)
  700. yyS = nyys
  701. }
  702. yyVAL = yyS[yyp+1]
  703. /* consult goto table to find next state */
  704. yyn = yyR1[yyn]
  705. yyg := yyPgo[yyn]
  706. yyj := yyg + yyS[yyp].yys + 1
  707. if yyj >= yyLast {
  708. yystate = yyAct[yyg]
  709. } else {
  710. yystate = yyAct[yyj]
  711. if yyChk[yystate] != -yyn {
  712. yystate = yyAct[yyg]
  713. }
  714. }
  715. // dummy call; replaced with literal code
  716. switch yynt {
  717. case 1:
  718. yyDollar = yyS[yypt-2 : yypt+1]
  719. //line build/parse.y:167
  720. {
  721. yylex.(*input).file = &File{Stmt: yyDollar[1].exprs}
  722. return 0
  723. }
  724. case 2:
  725. yyDollar = yyS[yypt-4 : yypt+1]
  726. //line build/parse.y:174
  727. {
  728. yyVAL.block = CodeBlock{
  729. Start: yyDollar[2].pos,
  730. Statements: yyDollar[3].exprs,
  731. End: End{Pos: yyDollar[4].pos},
  732. }
  733. }
  734. case 3:
  735. yyDollar = yyS[yypt-1 : yypt+1]
  736. //line build/parse.y:182
  737. {
  738. // simple_stmt is never empty
  739. start, _ := yyDollar[1].exprs[0].Span()
  740. _, end := yyDollar[1].exprs[len(yyDollar[1].exprs)-1].Span()
  741. yyVAL.block = CodeBlock{
  742. Start: start,
  743. Statements: yyDollar[1].exprs,
  744. End: End{Pos: end},
  745. }
  746. }
  747. case 4:
  748. yyDollar = yyS[yypt-0 : yypt+1]
  749. //line build/parse.y:194
  750. {
  751. yyVAL.exprs = nil
  752. yyVAL.lastRule = nil
  753. }
  754. case 5:
  755. yyDollar = yyS[yypt-2 : yypt+1]
  756. //line build/parse.y:199
  757. {
  758. // If this statement follows a comment block,
  759. // attach the comments to the statement.
  760. if cb, ok := yyDollar[1].lastRule.(*CommentBlock); ok {
  761. yyVAL.exprs = append(yyDollar[1].exprs[:len(yyDollar[1].exprs)-1], yyDollar[2].exprs...)
  762. yyDollar[2].exprs[0].Comment().Before = cb.After
  763. yyVAL.lastRule = yyDollar[2].exprs[len(yyDollar[2].exprs)-1]
  764. break
  765. }
  766. // Otherwise add to list.
  767. yyVAL.exprs = append(yyDollar[1].exprs, yyDollar[2].exprs...)
  768. yyVAL.lastRule = yyDollar[2].exprs[len(yyDollar[2].exprs)-1]
  769. // Consider this input:
  770. //
  771. // foo()
  772. // # bar
  773. // baz()
  774. //
  775. // If we've just parsed baz(), the # bar is attached to
  776. // foo() as an After comment. Make it a Before comment
  777. // for baz() instead.
  778. if x := yyDollar[1].lastRule; x != nil {
  779. com := x.Comment()
  780. // stmt is never empty
  781. yyDollar[2].exprs[0].Comment().Before = com.After
  782. com.After = nil
  783. }
  784. }
  785. case 6:
  786. yyDollar = yyS[yypt-2 : yypt+1]
  787. //line build/parse.y:230
  788. {
  789. // Blank line; sever last rule from future comments.
  790. yyVAL.exprs = yyDollar[1].exprs
  791. yyVAL.lastRule = nil
  792. }
  793. case 7:
  794. yyDollar = yyS[yypt-3 : yypt+1]
  795. //line build/parse.y:236
  796. {
  797. yyVAL.exprs = yyDollar[1].exprs
  798. yyVAL.lastRule = yyDollar[1].lastRule
  799. if yyVAL.lastRule == nil {
  800. cb := &CommentBlock{Start: yyDollar[2].pos}
  801. yyVAL.exprs = append(yyVAL.exprs, cb)
  802. yyVAL.lastRule = cb
  803. }
  804. com := yyVAL.lastRule.Comment()
  805. com.After = append(com.After, Comment{Start: yyDollar[2].pos, Token: yyDollar[2].tok})
  806. }
  807. case 8:
  808. yyDollar = yyS[yypt-1 : yypt+1]
  809. //line build/parse.y:250
  810. {
  811. yyVAL.exprs = yyDollar[1].exprs
  812. }
  813. case 9:
  814. yyDollar = yyS[yypt-1 : yypt+1]
  815. //line build/parse.y:254
  816. {
  817. yyVAL.exprs = []Expr{yyDollar[1].expr}
  818. }
  819. case 10:
  820. yyDollar = yyS[yypt-7 : yypt+1]
  821. //line build/parse.y:260
  822. {
  823. yyVAL.expr = &FuncDef{
  824. Start: yyDollar[1].pos,
  825. Name: yyDollar[2].tok,
  826. ListStart: yyDollar[3].pos,
  827. Args: yyDollar[4].exprs,
  828. Body: yyDollar[7].block,
  829. End: yyDollar[7].block.End,
  830. ForceCompact: forceCompact(yyDollar[3].pos, yyDollar[4].exprs, yyDollar[5].pos),
  831. ForceMultiLine: forceMultiLine(yyDollar[3].pos, yyDollar[4].exprs, yyDollar[5].pos),
  832. }
  833. }
  834. case 11:
  835. yyDollar = yyS[yypt-6 : yypt+1]
  836. //line build/parse.y:273
  837. {
  838. yyVAL.expr = &ForLoop{
  839. Start: yyDollar[1].pos,
  840. LoopVars: yyDollar[2].exprs,
  841. Iterable: yyDollar[4].expr,
  842. Body: yyDollar[6].block,
  843. End: yyDollar[6].block.End,
  844. }
  845. }
  846. case 12:
  847. yyDollar = yyS[yypt-1 : yypt+1]
  848. //line build/parse.y:283
  849. {
  850. yyVAL.expr = yyDollar[1].expr
  851. }
  852. case 13:
  853. yyDollar = yyS[yypt-4 : yypt+1]
  854. //line build/parse.y:289
  855. {
  856. yyVAL.expr = &IfElse{
  857. Start: yyDollar[1].pos,
  858. Conditions: []Condition{
  859. Condition{
  860. If: yyDollar[2].expr,
  861. Then: yyDollar[4].block,
  862. },
  863. },
  864. End: yyDollar[4].block.End,
  865. }
  866. }
  867. case 14:
  868. yyDollar = yyS[yypt-5 : yypt+1]
  869. //line build/parse.y:302
  870. {
  871. block := yyDollar[1].expr.(*IfElse)
  872. block.Conditions = append(block.Conditions, Condition{
  873. If: yyDollar[3].expr,
  874. Then: yyDollar[5].block,
  875. })
  876. block.End = yyDollar[5].block.End
  877. yyVAL.expr = block
  878. }
  879. case 15:
  880. yyDollar = yyS[yypt-4 : yypt+1]
  881. //line build/parse.y:312
  882. {
  883. block := yyDollar[1].expr.(*IfElse)
  884. block.Conditions = append(block.Conditions, Condition{
  885. Then: yyDollar[4].block,
  886. })
  887. block.End = yyDollar[4].block.End
  888. yyVAL.expr = block
  889. }
  890. case 18:
  891. yyDollar = yyS[yypt-4 : yypt+1]
  892. //line build/parse.y:327
  893. {
  894. yyVAL.exprs = append([]Expr{yyDollar[1].expr}, yyDollar[2].exprs...)
  895. yyVAL.lastRule = yyVAL.exprs[len(yyVAL.exprs)-1]
  896. }
  897. case 19:
  898. yyDollar = yyS[yypt-0 : yypt+1]
  899. //line build/parse.y:333
  900. {
  901. yyVAL.exprs = []Expr{}
  902. }
  903. case 20:
  904. yyDollar = yyS[yypt-3 : yypt+1]
  905. //line build/parse.y:337
  906. {
  907. yyVAL.exprs = append(yyDollar[1].exprs, yyDollar[3].expr)
  908. }
  909. case 22:
  910. yyDollar = yyS[yypt-2 : yypt+1]
  911. //line build/parse.y:344
  912. {
  913. _, end := yyDollar[2].expr.Span()
  914. yyVAL.expr = &ReturnExpr{
  915. X: yyDollar[2].expr,
  916. End: end,
  917. }
  918. }
  919. case 23:
  920. yyDollar = yyS[yypt-1 : yypt+1]
  921. //line build/parse.y:352
  922. {
  923. yyVAL.expr = &ReturnExpr{End: yyDollar[1].pos}
  924. }
  925. case 24:
  926. yyDollar = yyS[yypt-1 : yypt+1]
  927. //line build/parse.y:356
  928. {
  929. yyVAL.expr = &PythonBlock{Start: yyDollar[1].pos, Token: yyDollar[1].tok}
  930. }
  931. case 28:
  932. yyDollar = yyS[yypt-3 : yypt+1]
  933. //line build/parse.y:366
  934. {
  935. yyVAL.expr = &DotExpr{
  936. X: yyDollar[1].expr,
  937. Dot: yyDollar[2].pos,
  938. NamePos: yyDollar[3].pos,
  939. Name: yyDollar[3].tok,
  940. }
  941. }
  942. case 29:
  943. yyDollar = yyS[yypt-4 : yypt+1]
  944. //line build/parse.y:375
  945. {
  946. yyVAL.expr = &CallExpr{
  947. X: &LiteralExpr{Start: yyDollar[1].pos, Token: "load"},
  948. ListStart: yyDollar[2].pos,
  949. List: yyDollar[3].exprs,
  950. End: End{Pos: yyDollar[4].pos},
  951. ForceCompact: forceCompact(yyDollar[2].pos, yyDollar[3].exprs, yyDollar[4].pos),
  952. ForceMultiLine: forceMultiLine(yyDollar[2].pos, yyDollar[3].exprs, yyDollar[4].pos),
  953. }
  954. }
  955. case 30:
  956. yyDollar = yyS[yypt-4 : yypt+1]
  957. //line build/parse.y:386
  958. {
  959. yyVAL.expr = &CallExpr{
  960. X: yyDollar[1].expr,
  961. ListStart: yyDollar[2].pos,
  962. List: yyDollar[3].exprs,
  963. End: End{Pos: yyDollar[4].pos},
  964. ForceCompact: forceCompact(yyDollar[2].pos, yyDollar[3].exprs, yyDollar[4].pos),
  965. ForceMultiLine: forceMultiLine(yyDollar[2].pos, yyDollar[3].exprs, yyDollar[4].pos),
  966. }
  967. }
  968. case 31:
  969. yyDollar = yyS[yypt-4 : yypt+1]
  970. //line build/parse.y:397
  971. {
  972. yyVAL.expr = &IndexExpr{
  973. X: yyDollar[1].expr,
  974. IndexStart: yyDollar[2].pos,
  975. Y: yyDollar[3].expr,
  976. End: yyDollar[4].pos,
  977. }
  978. }
  979. case 32:
  980. yyDollar = yyS[yypt-6 : yypt+1]
  981. //line build/parse.y:406
  982. {
  983. yyVAL.expr = &SliceExpr{
  984. X: yyDollar[1].expr,
  985. SliceStart: yyDollar[2].pos,
  986. From: yyDollar[3].expr,
  987. FirstColon: yyDollar[4].pos,
  988. To: yyDollar[5].expr,
  989. End: yyDollar[6].pos,
  990. }
  991. }
  992. case 33:
  993. yyDollar = yyS[yypt-8 : yypt+1]
  994. //line build/parse.y:417
  995. {
  996. yyVAL.expr = &SliceExpr{
  997. X: yyDollar[1].expr,
  998. SliceStart: yyDollar[2].pos,
  999. From: yyDollar[3].expr,
  1000. FirstColon: yyDollar[4].pos,
  1001. To: yyDollar[5].expr,
  1002. SecondColon: yyDollar[6].pos,
  1003. Step: yyDollar[7].expr,
  1004. End: yyDollar[8].pos,
  1005. }
  1006. }
  1007. case 34:
  1008. yyDollar = yyS[yypt-5 : yypt+1]
  1009. //line build/parse.y:430
  1010. {
  1011. yyVAL.expr = &CallExpr{
  1012. X: yyDollar[1].expr,
  1013. ListStart: yyDollar[2].pos,
  1014. List: []Expr{
  1015. &ListForExpr{
  1016. Brack: "",
  1017. Start: yyDollar[2].pos,
  1018. X: yyDollar[3].expr,
  1019. For: yyDollar[4].forsifs,
  1020. End: End{Pos: yyDollar[5].pos},
  1021. },
  1022. },
  1023. End: End{Pos: yyDollar[5].pos},
  1024. }
  1025. }
  1026. case 35:
  1027. yyDollar = yyS[yypt-1 : yypt+1]
  1028. //line build/parse.y:447
  1029. {
  1030. if len(yyDollar[1].strings) == 1 {
  1031. yyVAL.expr = yyDollar[1].strings[0]
  1032. break
  1033. }
  1034. yyVAL.expr = yyDollar[1].strings[0]
  1035. for _, x := range yyDollar[1].strings[1:] {
  1036. _, end := yyVAL.expr.Span()
  1037. yyVAL.expr = binary(yyVAL.expr, end, "+", x)
  1038. }
  1039. }
  1040. case 36:
  1041. yyDollar = yyS[yypt-3 : yypt+1]
  1042. //line build/parse.y:459
  1043. {
  1044. yyVAL.expr = &ListExpr{
  1045. Start: yyDollar[1].pos,
  1046. List: yyDollar[2].exprs,
  1047. Comma: yyDollar[2].comma,
  1048. End: End{Pos: yyDollar[3].pos},
  1049. ForceMultiLine: forceMultiLine(yyDollar[1].pos, yyDollar[2].exprs, yyDollar[3].pos),
  1050. }
  1051. }
  1052. case 37:
  1053. yyDollar = yyS[yypt-4 : yypt+1]
  1054. //line build/parse.y:469
  1055. {
  1056. exprStart, _ := yyDollar[2].expr.Span()
  1057. yyVAL.expr = &ListForExpr{
  1058. Brack: "[]",
  1059. Start: yyDollar[1].pos,
  1060. X: yyDollar[2].expr,
  1061. For: yyDollar[3].forsifs,
  1062. End: End{Pos: yyDollar[4].pos},
  1063. ForceMultiLine: yyDollar[1].pos.Line != exprStart.Line,
  1064. }
  1065. }
  1066. case 38:
  1067. yyDollar = yyS[yypt-4 : yypt+1]
  1068. //line build/parse.y:481
  1069. {
  1070. exprStart, _ := yyDollar[2].expr.Span()
  1071. yyVAL.expr = &ListForExpr{
  1072. Brack: "()",
  1073. Start: yyDollar[1].pos,
  1074. X: yyDollar[2].expr,
  1075. For: yyDollar[3].forsifs,
  1076. End: End{Pos: yyDollar[4].pos},
  1077. ForceMultiLine: yyDollar[1].pos.Line != exprStart.Line,
  1078. }
  1079. }
  1080. case 39:
  1081. yyDollar = yyS[yypt-4 : yypt+1]
  1082. //line build/parse.y:493
  1083. {
  1084. exprStart, _ := yyDollar[2].expr.Span()
  1085. yyVAL.expr = &ListForExpr{
  1086. Brack: "{}",
  1087. Start: yyDollar[1].pos,
  1088. X: yyDollar[2].expr,
  1089. For: yyDollar[3].forsifs,
  1090. End: End{Pos: yyDollar[4].pos},
  1091. ForceMultiLine: yyDollar[1].pos.Line != exprStart.Line,
  1092. }
  1093. }
  1094. case 40:
  1095. yyDollar = yyS[yypt-3 : yypt+1]
  1096. //line build/parse.y:505
  1097. {
  1098. yyVAL.expr = &DictExpr{
  1099. Start: yyDollar[1].pos,
  1100. List: yyDollar[2].exprs,
  1101. Comma: yyDollar[2].comma,
  1102. End: End{Pos: yyDollar[3].pos},
  1103. ForceMultiLine: forceMultiLine(yyDollar[1].pos, yyDollar[2].exprs, yyDollar[3].pos),
  1104. }
  1105. }
  1106. case 41:
  1107. yyDollar = yyS[yypt-3 : yypt+1]
  1108. //line build/parse.y:515
  1109. {
  1110. yyVAL.expr = &SetExpr{
  1111. Start: yyDollar[1].pos,
  1112. List: yyDollar[2].exprs,
  1113. Comma: yyDollar[2].comma,
  1114. End: End{Pos: yyDollar[3].pos},
  1115. ForceMultiLine: forceMultiLine(yyDollar[1].pos, yyDollar[2].exprs, yyDollar[3].pos),
  1116. }
  1117. }
  1118. case 42:
  1119. yyDollar = yyS[yypt-3 : yypt+1]
  1120. //line build/parse.y:525
  1121. {
  1122. if len(yyDollar[2].exprs) == 1 && yyDollar[2].comma.Line == 0 {
  1123. // Just a parenthesized expression, not a tuple.
  1124. yyVAL.expr = &ParenExpr{
  1125. Start: yyDollar[1].pos,
  1126. X: yyDollar[2].exprs[0],
  1127. End: End{Pos: yyDollar[3].pos},
  1128. ForceMultiLine: forceMultiLine(yyDollar[1].pos, yyDollar[2].exprs, yyDollar[3].pos),
  1129. }
  1130. } else {
  1131. yyVAL.expr = &TupleExpr{
  1132. Start: yyDollar[1].pos,
  1133. List: yyDollar[2].exprs,
  1134. Comma: yyDollar[2].comma,
  1135. End: End{Pos: yyDollar[3].pos},
  1136. ForceCompact: forceCompact(yyDollar[1].pos, yyDollar[2].exprs, yyDollar[3].pos),
  1137. ForceMultiLine: forceMultiLine(yyDollar[1].pos, yyDollar[2].exprs, yyDollar[3].pos),
  1138. }
  1139. }
  1140. }
  1141. case 43:
  1142. yyDollar = yyS[yypt-2 : yypt+1]
  1143. //line build/parse.y:545
  1144. {
  1145. yyVAL.expr = unary(yyDollar[1].pos, yyDollar[1].tok, yyDollar[2].expr)
  1146. }
  1147. case 45:
  1148. yyDollar = yyS[yypt-4 : yypt+1]
  1149. //line build/parse.y:550
  1150. {
  1151. yyVAL.expr = &LambdaExpr{
  1152. Lambda: yyDollar[1].pos,
  1153. Var: yyDollar[2].exprs,
  1154. Colon: yyDollar[3].pos,
  1155. Expr: yyDollar[4].expr,
  1156. }
  1157. }
  1158. case 46:
  1159. yyDollar = yyS[yypt-2 : yypt+1]
  1160. //line build/parse.y:558
  1161. {
  1162. yyVAL.expr = unary(yyDollar[1].pos, yyDollar[1].tok, yyDollar[2].expr)
  1163. }
  1164. case 47:
  1165. yyDollar = yyS[yypt-2 : yypt+1]
  1166. //line build/parse.y:559
  1167. {
  1168. yyVAL.expr = unary(yyDollar[1].pos, yyDollar[1].tok, yyDollar[2].expr)
  1169. }
  1170. case 48:
  1171. yyDollar = yyS[yypt-3 : yypt+1]
  1172. //line build/parse.y:560
  1173. {
  1174. yyVAL.expr = binary(yyDollar[1].expr, yyDollar[2].pos, yyDollar[2].tok, yyDollar[3].expr)
  1175. }
  1176. case 49:
  1177. yyDollar = yyS[yypt-3 : yypt+1]
  1178. //line build/parse.y:561
  1179. {
  1180. yyVAL.expr = binary(yyDollar[1].expr, yyDollar[2].pos, yyDollar[2].tok, yyDollar[3].expr)
  1181. }
  1182. case 50:
  1183. yyDollar = yyS[yypt-3 : yypt+1]
  1184. //line build/parse.y:562
  1185. {
  1186. yyVAL.expr = binary(yyDollar[1].expr, yyDollar[2].pos, yyDollar[2].tok, yyDollar[3].expr)
  1187. }
  1188. case 51:
  1189. yyDollar = yyS[yypt-3 : yypt+1]
  1190. //line build/parse.y:563
  1191. {
  1192. yyVAL.expr = binary(yyDollar[1].expr, yyDollar[2].pos, yyDollar[2].tok, yyDollar[3].expr)
  1193. }
  1194. case 52:
  1195. yyDollar = yyS[yypt-3 : yypt+1]
  1196. //line build/parse.y:564
  1197. {
  1198. yyVAL.expr = binary(yyDollar[1].expr, yyDollar[2].pos, yyDollar[2].tok, yyDollar[3].expr)
  1199. }
  1200. case 53:
  1201. yyDollar = yyS[yypt-3 : yypt+1]
  1202. //line build/parse.y:565
  1203. {
  1204. yyVAL.expr = binary(yyDollar[1].expr, yyDollar[2].pos, yyDollar[2].tok, yyDollar[3].expr)
  1205. }
  1206. case 54:
  1207. yyDollar = yyS[yypt-3 : yypt+1]
  1208. //line build/parse.y:566
  1209. {
  1210. yyVAL.expr = binary(yyDollar[1].expr, yyDollar[2].pos, yyDollar[2].tok, yyDollar[3].expr)
  1211. }
  1212. case 55:
  1213. yyDollar = yyS[yypt-3 : yypt+1]
  1214. //line build/parse.y:567
  1215. {
  1216. yyVAL.expr = binary(yyDollar[1].expr, yyDollar[2].pos, yyDollar[2].tok, yyDollar[3].expr)
  1217. }
  1218. case 56:
  1219. yyDollar = yyS[yypt-3 : yypt+1]
  1220. //line build/parse.y:568
  1221. {
  1222. yyVAL.expr = binary(yyDollar[1].expr, yyDollar[2].pos, yyDollar[2].tok, yyDollar[3].expr)
  1223. }
  1224. case 57:
  1225. yyDollar = yyS[yypt-3 : yypt+1]
  1226. //line build/parse.y:569
  1227. {
  1228. yyVAL.expr = binary(yyDollar[1].expr, yyDollar[2].pos, yyDollar[2].tok, yyDollar[3].expr)
  1229. }
  1230. case 58:
  1231. yyDollar = yyS[yypt-3 : yypt+1]
  1232. //line build/parse.y:570
  1233. {
  1234. yyVAL.expr = binary(yyDollar[1].expr, yyDollar[2].pos, yyDollar[2].tok, yyDollar[3].expr)
  1235. }
  1236. case 59:
  1237. yyDollar = yyS[yypt-3 : yypt+1]
  1238. //line build/parse.y:571
  1239. {
  1240. yyVAL.expr = binary(yyDollar[1].expr, yyDollar[2].pos, yyDollar[2].tok, yyDollar[3].expr)
  1241. }
  1242. case 60:
  1243. yyDollar = yyS[yypt-3 : yypt+1]
  1244. //line build/parse.y:572
  1245. {
  1246. yyVAL.expr = binary(yyDollar[1].expr, yyDollar[2].pos, yyDollar[2].tok, yyDollar[3].expr)
  1247. }
  1248. case 61:
  1249. yyDollar = yyS[yypt-3 : yypt+1]
  1250. //line build/parse.y:573
  1251. {
  1252. yyVAL.expr = binary(yyDollar[1].expr, yyDollar[2].pos, yyDollar[2].tok, yyDollar[3].expr)
  1253. }
  1254. case 62:
  1255. yyDollar = yyS[yypt-4 : yypt+1]
  1256. //line build/parse.y:574
  1257. {
  1258. yyVAL.expr = binary(yyDollar[1].expr, yyDollar[2].pos, "not in", yyDollar[4].expr)
  1259. }
  1260. case 63:
  1261. yyDollar = yyS[yypt-3 : yypt+1]
  1262. //line build/parse.y:575
  1263. {
  1264. yyVAL.expr = binary(yyDollar[1].expr, yyDollar[2].pos, yyDollar[2].tok, yyDollar[3].expr)
  1265. }
  1266. case 64:
  1267. yyDollar = yyS[yypt-3 : yypt+1]
  1268. //line build/parse.y:576
  1269. {
  1270. yyVAL.expr = binary(yyDollar[1].expr, yyDollar[2].pos, yyDollar[2].tok, yyDollar[3].expr)
  1271. }
  1272. case 65:
  1273. yyDollar = yyS[yypt-3 : yypt+1]
  1274. //line build/parse.y:578
  1275. {
  1276. if b, ok := yyDollar[3].expr.(*UnaryExpr); ok && b.Op == "not" {
  1277. yyVAL.expr = binary(yyDollar[1].expr, yyDollar[2].pos, "is not", b.X)
  1278. } else {
  1279. yyVAL.expr = binary(yyDollar[1].expr, yyDollar[2].pos, yyDollar[2].tok, yyDollar[3].expr)
  1280. }
  1281. }
  1282. case 66:
  1283. yyDollar = yyS[yypt-5 : yypt+1]
  1284. //line build/parse.y:586
  1285. {
  1286. yyVAL.expr = &ConditionalExpr{
  1287. Then: yyDollar[1].expr,
  1288. IfStart: yyDollar[2].pos,
  1289. Test: yyDollar[3].expr,
  1290. ElseStart: yyDollar[4].pos,
  1291. Else: yyDollar[5].expr,
  1292. }
  1293. }
  1294. case 67:
  1295. yyDollar = yyS[yypt-0 : yypt+1]
  1296. //line build/parse.y:597
  1297. {
  1298. yyVAL.expr = nil
  1299. }
  1300. case 69:
  1301. yyDollar = yyS[yypt-0 : yypt+1]
  1302. //line build/parse.y:607
  1303. {
  1304. yyVAL.pos = Position{}
  1305. }
  1306. case 71:
  1307. yyDollar = yyS[yypt-3 : yypt+1]
  1308. //line build/parse.y:613
  1309. {
  1310. yyVAL.expr = &KeyValueExpr{
  1311. Key: yyDollar[1].expr,
  1312. Colon: yyDollar[2].pos,
  1313. Value: yyDollar[3].expr,
  1314. }
  1315. }
  1316. case 72:
  1317. yyDollar = yyS[yypt-1 : yypt+1]
  1318. //line build/parse.y:623
  1319. {
  1320. yyVAL.exprs = []Expr{yyDollar[1].expr}
  1321. }
  1322. case 73:
  1323. yyDollar = yyS[yypt-3 : yypt+1]
  1324. //line build/parse.y:627
  1325. {
  1326. yyVAL.exprs = append(yyDollar[1].exprs, yyDollar[3].expr)
  1327. }
  1328. case 74:
  1329. yyDollar = yyS[yypt-1 : yypt+1]
  1330. //line build/parse.y:633
  1331. {
  1332. yyVAL.exprs = yyDollar[1].exprs
  1333. }
  1334. case 75:
  1335. yyDollar = yyS[yypt-2 : yypt+1]
  1336. //line build/parse.y:637
  1337. {
  1338. yyVAL.exprs = yyDollar[1].exprs
  1339. }
  1340. case 76:
  1341. yyDollar = yyS[yypt-1 : yypt+1]
  1342. //line build/parse.y:643
  1343. {
  1344. yyVAL.exprs = []Expr{yyDollar[1].expr}
  1345. }
  1346. case 77:
  1347. yyDollar = yyS[yypt-3 : yypt+1]
  1348. //line build/parse.y:647
  1349. {
  1350. yyVAL.exprs = append(yyDollar[1].exprs, yyDollar[3].expr)
  1351. }
  1352. case 78:
  1353. yyDollar = yyS[yypt-0 : yypt+1]
  1354. //line build/parse.y:652
  1355. {
  1356. yyVAL.exprs, yyVAL.comma = nil, Position{}
  1357. }
  1358. case 79:
  1359. yyDollar = yyS[yypt-2 : yypt+1]
  1360. //line build/parse.y:656
  1361. {
  1362. yyVAL.exprs, yyVAL.comma = yyDollar[1].exprs, yyDollar[2].pos
  1363. }
  1364. case 80:
  1365. yyDollar = yyS[yypt-1 : yypt+1]
  1366. //line build/parse.y:662
  1367. {
  1368. yyVAL.exprs = []Expr{yyDollar[1].expr}
  1369. }
  1370. case 81:
  1371. yyDollar = yyS[yypt-3 : yypt+1]
  1372. //line build/parse.y:666
  1373. {
  1374. yyVAL.exprs = append(yyDollar[1].exprs, yyDollar[3].expr)
  1375. }
  1376. case 82:
  1377. yyDollar = yyS[yypt-1 : yypt+1]
  1378. //line build/parse.y:672
  1379. {
  1380. yyVAL.string = &StringExpr{
  1381. Start: yyDollar[1].pos,
  1382. Value: yyDollar[1].str,
  1383. TripleQuote: yyDollar[1].triple,
  1384. End: yyDollar[1].pos.add(yyDollar[1].tok),
  1385. Token: yyDollar[1].tok,
  1386. }
  1387. }
  1388. case 83:
  1389. yyDollar = yyS[yypt-1 : yypt+1]
  1390. //line build/parse.y:684
  1391. {
  1392. yyVAL.strings = []*StringExpr{yyDollar[1].string}
  1393. }
  1394. case 84:
  1395. yyDollar = yyS[yypt-2 : yypt+1]
  1396. //line build/parse.y:688
  1397. {
  1398. yyVAL.strings = append(yyDollar[1].strings, yyDollar[2].string)
  1399. }
  1400. case 85:
  1401. yyDollar = yyS[yypt-1 : yypt+1]
  1402. //line build/parse.y:694
  1403. {
  1404. yyVAL.expr = &LiteralExpr{Start: yyDollar[1].pos, Token: yyDollar[1].tok}
  1405. }
  1406. case 86:
  1407. yyDollar = yyS[yypt-4 : yypt+1]
  1408. //line build/parse.y:700
  1409. {
  1410. yyVAL.forc = &ForClause{
  1411. For: yyDollar[1].pos,
  1412. Var: yyDollar[2].exprs,
  1413. In: yyDollar[3].pos,
  1414. Expr: yyDollar[4].expr,
  1415. }
  1416. }
  1417. case 87:
  1418. yyDollar = yyS[yypt-2 : yypt+1]
  1419. //line build/parse.y:710
  1420. {
  1421. yyVAL.forifs = &ForClauseWithIfClausesOpt{
  1422. For: yyDollar[1].forc,
  1423. Ifs: yyDollar[2].ifs,
  1424. }
  1425. }
  1426. case 88:
  1427. yyDollar = yyS[yypt-1 : yypt+1]
  1428. //line build/parse.y:719
  1429. {
  1430. yyVAL.forsifs = []*ForClauseWithIfClausesOpt{yyDollar[1].forifs}
  1431. }
  1432. case 89:
  1433. yyDollar = yyS[yypt-2 : yypt+1]
  1434. //line build/parse.y:722
  1435. {
  1436. yyVAL.forsifs = append(yyDollar[1].forsifs, yyDollar[2].forifs)
  1437. }
  1438. case 90:
  1439. yyDollar = yyS[yypt-0 : yypt+1]
  1440. //line build/parse.y:727
  1441. {
  1442. yyVAL.ifs = nil
  1443. }
  1444. case 91:
  1445. yyDollar = yyS[yypt-3 : yypt+1]
  1446. //line build/parse.y:731
  1447. {
  1448. yyVAL.ifs = append(yyDollar[1].ifs, &IfClause{
  1449. If: yyDollar[2].pos,
  1450. Cond: yyDollar[3].expr,
  1451. })
  1452. }
  1453. }
  1454. goto yystack /* stack new state and value */
  1455. }