@@ -3,7 +3,6 @@ package vibes
33import (
44 "fmt"
55 "strconv"
6- "strings"
76)
87
98func (p * parser ) parseExpression (precedence int ) Expression {
@@ -349,134 +348,6 @@ func isLabelNameToken(tt TokenType) bool {
349348 }
350349}
351350
352- func (p * parser ) parseBlockLiteral () * BlockLiteral {
353- pos := p .curToken .Pos
354- params := []Param {}
355-
356- p .nextToken ()
357- if p .curToken .Type == tokenPipe {
358- var ok bool
359- params , ok = p .parseBlockParameters ()
360- if ! ok {
361- return nil
362- }
363- p .nextToken ()
364- }
365-
366- body := p .parseBlock (tokenEnd )
367- if p .curToken .Type != tokenEnd {
368- p .errorExpected (p .curToken , "end" )
369- }
370-
371- return & BlockLiteral {Params : params , Body : body , position : pos }
372- }
373-
374- func (p * parser ) parseBlockParameters () ([]Param , bool ) {
375- params := []Param {}
376- p .nextToken ()
377- if p .curToken .Type == tokenPipe {
378- return params , true
379- }
380-
381- param , ok := p .parseBlockParameter ()
382- if ! ok {
383- return nil , false
384- }
385- params = append (params , param )
386-
387- for p .peekToken .Type == tokenComma {
388- p .nextToken ()
389- p .nextToken ()
390- if p .curToken .Type == tokenPipe {
391- p .addParseError (p .curToken .Pos , "trailing comma in block parameter list" )
392- return nil , false
393- }
394- param , ok := p .parseBlockParameter ()
395- if ! ok {
396- return nil , false
397- }
398- params = append (params , param )
399- }
400-
401- if ! p .expectPeek (tokenPipe ) {
402- return nil , false
403- }
404-
405- return params , true
406- }
407-
408- func (p * parser ) parseBlockParameter () (Param , bool ) {
409- if p .curToken .Type != tokenIdent {
410- p .errorExpected (p .curToken , "block parameter" )
411- return Param {}, false
412- }
413- param := Param {Name : p .curToken .Literal }
414- if p .peekToken .Type == tokenColon {
415- p .nextToken ()
416- p .nextToken ()
417- param .Type = p .parseBlockParamType ()
418- if param .Type == nil {
419- return Param {}, false
420- }
421- }
422- return param , true
423- }
424-
425- func (p * parser ) parseBlockParamType () * TypeExpr {
426- first := p .parseTypeAtom ()
427- if first == nil {
428- return nil
429- }
430-
431- union := []* TypeExpr {first }
432- for p .peekToken .Type == tokenPipe && p .blockParamUnionContinues () {
433- p .nextToken ()
434- p .nextToken ()
435- next := p .parseTypeAtom ()
436- if next == nil {
437- return nil
438- }
439- union = append (union , next )
440- }
441-
442- if len (union ) == 1 {
443- return first
444- }
445-
446- names := make ([]string , len (union ))
447- for i , option := range union {
448- names [i ] = formatTypeExpr (option )
449- }
450- return & TypeExpr {
451- Name : strings .Join (names , " | " ),
452- Kind : TypeUnion ,
453- Union : union ,
454- position : first .position ,
455- }
456- }
457-
458- func (p * parser ) blockParamUnionContinues () bool {
459- if p .peekToken .Type != tokenPipe {
460- return false
461- }
462-
463- savedLexer := * p .l
464- savedCur := p .curToken
465- savedPeek := p .peekToken
466- savedErrors := len (p .errors )
467-
468- p .nextToken ()
469- p .nextToken ()
470- atom := p .parseTypeAtom ()
471- ok := atom != nil && (p .peekToken .Type == tokenComma || p .peekToken .Type == tokenPipe )
472-
473- p .l = & savedLexer
474- p .curToken = savedCur
475- p .peekToken = savedPeek
476- p .errors = p .errors [:savedErrors ]
477- return ok
478- }
479-
480351func (p * parser ) parseMemberExpression (object Expression ) Expression {
481352 if object == nil {
482353 return nil
0 commit comments