~mna/snow

9027aa7d60072102903af785e656e6660b730f9f — Martin Angers 1 year, 9 months ago 719c17d
pkg/parser: test parsing tuple values and field selectors
M pkg/parser/parser.go => pkg/parser/parser.go +3 -2
@@ 239,10 239,11 @@ func (p *parser) parseVarDecl() *ast.VarDecl {
func (p *parser) parseIdentOrTupleIndex() *ast.Ident {
	if p.tok == token.Int {
		// must be a base10 integer (i.e. not 0xabc nor 0b1101)
		ix, err := strconv.ParseInt(p.lit, 10, 32)
		lit := p.lit
		ix, err := strconv.ParseInt(lit, 10, 32)
		if err == nil {
			return &ast.Ident{
				Name:       p.lit,
				Name:       lit,
				TupleIndex: int(ix),
				IdentPos:   p.expect(token.Int),
			}

A pkg/parser/testdata/fn_invalid_empty_tuple.snow => pkg/parser/testdata/fn_invalid_empty_tuple.snow +3 -0
@@ 0,0 1,3 @@
fn main() {
  let x = ()
}

A pkg/parser/testdata/fn_invalid_empty_tuple.snow.err => pkg/parser/testdata/fn_invalid_empty_tuple.snow.err +1 -0
@@ 0,0 1,1 @@
testdata/fn_invalid_empty_tuple.snow:2:11: expected expression

A pkg/parser/testdata/fn_invalid_empty_tuple.snow.want => pkg/parser/testdata/fn_invalid_empty_tuple.snow.want +8 -0
@@ 0,0 1,8 @@
file [1, #0] [0:26]
  fn [0:26]
    ident [main] [3:7]
    sig [0->0] [7:9]
    block [1] [10:26]
      let= [14:24]
        ident [x] [18:19]
        bad expr [22:24]

A pkg/parser/testdata/fn_nested_tuples.snow => pkg/parser/testdata/fn_nested_tuples.snow +6 -0
@@ 0,0 1,6 @@
fn main() {
  var a = (1, 2)
  var b = ("x", a)
  var c = a.0
  var d = b.1.1
}

A pkg/parser/testdata/fn_nested_tuples.snow.err => pkg/parser/testdata/fn_nested_tuples.snow.err +0 -0
A pkg/parser/testdata/fn_nested_tuples.snow.want => pkg/parser/testdata/fn_nested_tuples.snow.want +31 -0
@@ 0,0 1,31 @@
file [1, #0] [0:79]
  fn [0:79]
    ident [main] [3:7]
    sig [0->0] [7:9]
    block [4] [10:79]
      var= [14:28]
        ident [a] [18:19]
        tuple value [2] [22:28]
          item [23:25]
            int [1] [23:24]
          item [26:27]
            int [2] [26:27]
      var= [31:47]
        ident [b] [35:36]
        tuple value [2] [39:47]
          item [40:44]
            string ["x"] [40:43]
          item [45:46]
            ident [a] [45:46]
      var= [50:61]
        ident [c] [54:55]
        select [58:61]
          ident [a] [58:59]
          ident [0] [60:61]
      var= [64:77]
        ident [d] [68:69]
        select [72:77]
          select [72:75]
            ident [b] [72:73]
            ident [1] [74:75]
          ident [1] [76:77]

A pkg/parser/testdata/var_tuple.snow => pkg/parser/testdata/var_tuple.snow +1 -0
@@ 0,0 1,1 @@
var t = (1, "a", true,)

A pkg/parser/testdata/var_tuple.snow.err => pkg/parser/testdata/var_tuple.snow.err +0 -0
A pkg/parser/testdata/var_tuple.snow.want => pkg/parser/testdata/var_tuple.snow.want +10 -0
@@ 0,0 1,10 @@
file [1, #0] [0:23]
  var= [0:23]
    ident [t] [4:5]
    tuple value [3] [8:23]
      item [9:11]
        int [1] [9:10]
      item [12:16]
        string ["a"] [12:15]
      item [17:22]
        ident [true] [17:21]