mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 19:11:09 +01:00
Refactor struct literal parse nodes. (#4470)
Split StructComma into StructLiteralComma and StructTypeLiteralComma in order to easily differentiate handling (remains the same in this PR). Add "Literal" to StructField and StructTypeField because it feels inconsistent versus the other non-shared things. StructFieldDesignator remains shared between value literals and type literals. Note I probably would've made StructFieldDesignator non-shared too, but that'd require either a lookahead of 2 (to see the separator`) or a writeback after parsing the separator, neither of which felt especially crucial for this, when what I'm really trying to do is split type literal handling a little further.
This commit is contained in:
+1
-1
@@ -20,7 +20,7 @@ var x: {,} = {};
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'x'},
|
||||
// CHECK:STDOUT: {kind: 'StructLiteralStart', text: '{'},
|
||||
// CHECK:STDOUT: {kind: 'InvalidParse', text: ',', has_error: yes},
|
||||
// CHECK:STDOUT: {kind: 'StructComma', text: ','},
|
||||
// CHECK:STDOUT: {kind: 'InvalidParse', text: ','},
|
||||
// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', has_error: yes, subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'BindingPattern', text: ':', subtree_size: 6},
|
||||
// CHECK:STDOUT: {kind: 'VariableInitializer', text: '='},
|
||||
|
||||
@@ -22,10 +22,10 @@ var x: {.a: i32,,} = {};
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'a'},
|
||||
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
|
||||
// CHECK:STDOUT: {kind: 'StructTypeField', text: ':', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructComma', text: ','},
|
||||
// CHECK:STDOUT: {kind: 'StructTypeLiteralField', text: ':', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructTypeLiteralComma', text: ','},
|
||||
// CHECK:STDOUT: {kind: 'InvalidParse', text: ',', has_error: yes},
|
||||
// CHECK:STDOUT: {kind: 'StructComma', text: ','},
|
||||
// CHECK:STDOUT: {kind: 'StructTypeLiteralComma', text: ','},
|
||||
// CHECK:STDOUT: {kind: 'StructTypeLiteral', text: '}', has_error: yes, subtree_size: 9},
|
||||
// CHECK:STDOUT: {kind: 'BindingPattern', text: ':', subtree_size: 11},
|
||||
// CHECK:STDOUT: {kind: 'VariableInitializer', text: '='},
|
||||
|
||||
@@ -22,10 +22,10 @@ var x: {.a = 0,,} = {};
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'a'},
|
||||
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'IntLiteral', text: '0'},
|
||||
// CHECK:STDOUT: {kind: 'StructField', text: '=', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructComma', text: ','},
|
||||
// CHECK:STDOUT: {kind: 'StructLiteralField', text: '=', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructLiteralComma', text: ','},
|
||||
// CHECK:STDOUT: {kind: 'InvalidParse', text: ',', has_error: yes},
|
||||
// CHECK:STDOUT: {kind: 'StructComma', text: ','},
|
||||
// CHECK:STDOUT: {kind: 'StructLiteralComma', text: ','},
|
||||
// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', has_error: yes, subtree_size: 9},
|
||||
// CHECK:STDOUT: {kind: 'BindingPattern', text: ':', subtree_size: 11},
|
||||
// CHECK:STDOUT: {kind: 'VariableInitializer', text: '='},
|
||||
|
||||
@@ -22,7 +22,7 @@ var x: {.a: i32 banana} = {.a = 0};
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'a'},
|
||||
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
|
||||
// CHECK:STDOUT: {kind: 'StructTypeField', text: ':', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructTypeLiteralField', text: ':', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructTypeLiteral', text: '}', has_error: yes, subtree_size: 6},
|
||||
// CHECK:STDOUT: {kind: 'BindingPattern', text: ':', subtree_size: 8},
|
||||
// CHECK:STDOUT: {kind: 'VariableInitializer', text: '='},
|
||||
@@ -30,7 +30,7 @@ var x: {.a: i32 banana} = {.a = 0};
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'a'},
|
||||
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'IntLiteral', text: '0'},
|
||||
// CHECK:STDOUT: {kind: 'StructField', text: '=', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructLiteralField', text: '=', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 6},
|
||||
// CHECK:STDOUT: {kind: 'VariableDecl', text: ';', subtree_size: 17},
|
||||
// CHECK:STDOUT: {kind: 'FileEnd', text: ''},
|
||||
|
||||
@@ -22,7 +22,7 @@ var x: {.a: i32} = {.a = 0 banana};
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'a'},
|
||||
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
|
||||
// CHECK:STDOUT: {kind: 'StructTypeField', text: ':', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructTypeLiteralField', text: ':', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructTypeLiteral', text: '}', subtree_size: 6},
|
||||
// CHECK:STDOUT: {kind: 'BindingPattern', text: ':', subtree_size: 8},
|
||||
// CHECK:STDOUT: {kind: 'VariableInitializer', text: '='},
|
||||
@@ -30,7 +30,7 @@ var x: {.a: i32} = {.a = 0 banana};
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'a'},
|
||||
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'IntLiteral', text: '0'},
|
||||
// CHECK:STDOUT: {kind: 'StructField', text: '=', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructLiteralField', text: '=', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', has_error: yes, subtree_size: 6},
|
||||
// CHECK:STDOUT: {kind: 'VariableDecl', text: ';', subtree_size: 17},
|
||||
// CHECK:STDOUT: {kind: 'FileEnd', text: ''},
|
||||
|
||||
@@ -22,8 +22,8 @@ var x: {.a: i32, .b = 0} = {};
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'a'},
|
||||
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
|
||||
// CHECK:STDOUT: {kind: 'StructTypeField', text: ':', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructComma', text: ','},
|
||||
// CHECK:STDOUT: {kind: 'StructTypeLiteralField', text: ':', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructTypeLiteralComma', text: ','},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'b'},
|
||||
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'InvalidParse', text: '.', has_error: yes},
|
||||
|
||||
@@ -22,8 +22,8 @@ var x: {.a = 0, b: i32} = {};
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'a'},
|
||||
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'IntLiteral', text: '0'},
|
||||
// CHECK:STDOUT: {kind: 'StructField', text: '=', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructComma', text: ','},
|
||||
// CHECK:STDOUT: {kind: 'StructLiteralField', text: '=', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructLiteralComma', text: ','},
|
||||
// CHECK:STDOUT: {kind: 'InvalidParse', text: 'b', has_error: yes},
|
||||
// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', has_error: yes, subtree_size: 8},
|
||||
// CHECK:STDOUT: {kind: 'BindingPattern', text: ':', subtree_size: 10},
|
||||
|
||||
@@ -39,12 +39,12 @@ var x: i32 = {.a: i32, .b, .c = 1};
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'a'},
|
||||
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'IntLiteral', text: '1'},
|
||||
// CHECK:STDOUT: {kind: 'StructField', text: '=', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructComma', text: ','},
|
||||
// CHECK:STDOUT: {kind: 'StructLiteralField', text: '=', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructLiteralComma', text: ','},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'b'},
|
||||
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'InvalidParse', text: '.', has_error: yes},
|
||||
// CHECK:STDOUT: {kind: 'StructComma', text: ','},
|
||||
// CHECK:STDOUT: {kind: 'StructLiteralComma', text: ','},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'c'},
|
||||
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'InvalidParse', text: '.', has_error: yes},
|
||||
@@ -59,12 +59,12 @@ var x: i32 = {.a: i32, .b, .c = 1};
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'a'},
|
||||
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
|
||||
// CHECK:STDOUT: {kind: 'StructTypeField', text: ':', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructComma', text: ','},
|
||||
// CHECK:STDOUT: {kind: 'StructTypeLiteralField', text: ':', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructTypeLiteralComma', text: ','},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'b'},
|
||||
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'InvalidParse', text: '.', has_error: yes},
|
||||
// CHECK:STDOUT: {kind: 'StructComma', text: ','},
|
||||
// CHECK:STDOUT: {kind: 'StructTypeLiteralComma', text: ','},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'c'},
|
||||
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'InvalidParse', text: '.', has_error: yes},
|
||||
|
||||
@@ -23,11 +23,11 @@ var x: {."hello": i32, .y: i32} = {};
|
||||
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
|
||||
// CHECK:STDOUT: {kind: 'InvalidParse', text: ':', has_error: yes},
|
||||
// CHECK:STDOUT: {kind: 'StructComma', text: ','},
|
||||
// CHECK:STDOUT: {kind: 'StructTypeLiteralComma', text: ','},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'y'},
|
||||
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
|
||||
// CHECK:STDOUT: {kind: 'StructTypeField', text: ':', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructTypeLiteralField', text: ':', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructTypeLiteral', text: '}', has_error: yes, subtree_size: 11},
|
||||
// CHECK:STDOUT: {kind: 'BindingPattern', text: ':', subtree_size: 13},
|
||||
// CHECK:STDOUT: {kind: 'VariableInitializer', text: '='},
|
||||
|
||||
@@ -23,11 +23,11 @@ var x: {."hello" = 0, .y = 4} = {};
|
||||
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'IntLiteral', text: '0'},
|
||||
// CHECK:STDOUT: {kind: 'InvalidParse', text: '=', has_error: yes},
|
||||
// CHECK:STDOUT: {kind: 'StructComma', text: ','},
|
||||
// CHECK:STDOUT: {kind: 'StructLiteralComma', text: ','},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'y'},
|
||||
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'IntLiteral', text: '4'},
|
||||
// CHECK:STDOUT: {kind: 'StructField', text: '=', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructLiteralField', text: '=', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', has_error: yes, subtree_size: 11},
|
||||
// CHECK:STDOUT: {kind: 'BindingPattern', text: ':', subtree_size: 13},
|
||||
// CHECK:STDOUT: {kind: 'VariableInitializer', text: '='},
|
||||
|
||||
@@ -19,7 +19,7 @@ var z: {.n: i32} = {.n = 4};
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'n'},
|
||||
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
|
||||
// CHECK:STDOUT: {kind: 'StructTypeField', text: ':', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructTypeLiteralField', text: ':', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructTypeLiteral', text: '}', subtree_size: 6},
|
||||
// CHECK:STDOUT: {kind: 'BindingPattern', text: ':', subtree_size: 8},
|
||||
// CHECK:STDOUT: {kind: 'VariableInitializer', text: '='},
|
||||
@@ -27,7 +27,7 @@ var z: {.n: i32} = {.n = 4};
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'n'},
|
||||
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'IntLiteral', text: '4'},
|
||||
// CHECK:STDOUT: {kind: 'StructField', text: '=', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructLiteralField', text: '=', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 6},
|
||||
// CHECK:STDOUT: {kind: 'VariableDecl', text: ';', subtree_size: 17},
|
||||
// CHECK:STDOUT: {kind: 'FileEnd', text: ''},
|
||||
|
||||
@@ -19,8 +19,8 @@ var z: {.n: i32,} = {.n = 4,};
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'n'},
|
||||
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
|
||||
// CHECK:STDOUT: {kind: 'StructTypeField', text: ':', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructComma', text: ','},
|
||||
// CHECK:STDOUT: {kind: 'StructTypeLiteralField', text: ':', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructTypeLiteralComma', text: ','},
|
||||
// CHECK:STDOUT: {kind: 'StructTypeLiteral', text: '}', subtree_size: 7},
|
||||
// CHECK:STDOUT: {kind: 'BindingPattern', text: ':', subtree_size: 9},
|
||||
// CHECK:STDOUT: {kind: 'VariableInitializer', text: '='},
|
||||
@@ -28,8 +28,8 @@ var z: {.n: i32,} = {.n = 4,};
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'n'},
|
||||
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'IntLiteral', text: '4'},
|
||||
// CHECK:STDOUT: {kind: 'StructField', text: '=', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructComma', text: ','},
|
||||
// CHECK:STDOUT: {kind: 'StructLiteralField', text: '=', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructLiteralComma', text: ','},
|
||||
// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 7},
|
||||
// CHECK:STDOUT: {kind: 'VariableDecl', text: ';', subtree_size: 19},
|
||||
// CHECK:STDOUT: {kind: 'FileEnd', text: ''},
|
||||
|
||||
+6
-6
@@ -19,12 +19,12 @@ var x: {.a: i32, .b: i32} = {.a = 1, .b = 2};
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'a'},
|
||||
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
|
||||
// CHECK:STDOUT: {kind: 'StructTypeField', text: ':', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructComma', text: ','},
|
||||
// CHECK:STDOUT: {kind: 'StructTypeLiteralField', text: ':', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructTypeLiteralComma', text: ','},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'b'},
|
||||
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
|
||||
// CHECK:STDOUT: {kind: 'StructTypeField', text: ':', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructTypeLiteralField', text: ':', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructTypeLiteral', text: '}', subtree_size: 11},
|
||||
// CHECK:STDOUT: {kind: 'BindingPattern', text: ':', subtree_size: 13},
|
||||
// CHECK:STDOUT: {kind: 'VariableInitializer', text: '='},
|
||||
@@ -32,12 +32,12 @@ var x: {.a: i32, .b: i32} = {.a = 1, .b = 2};
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'a'},
|
||||
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'IntLiteral', text: '1'},
|
||||
// CHECK:STDOUT: {kind: 'StructField', text: '=', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructComma', text: ','},
|
||||
// CHECK:STDOUT: {kind: 'StructLiteralField', text: '=', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructLiteralComma', text: ','},
|
||||
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'b'},
|
||||
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
|
||||
// CHECK:STDOUT: {kind: 'IntLiteral', text: '2'},
|
||||
// CHECK:STDOUT: {kind: 'StructField', text: '=', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructLiteralField', text: '=', subtree_size: 4},
|
||||
// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 11},
|
||||
// CHECK:STDOUT: {kind: 'VariableDecl', text: ';', subtree_size: 27},
|
||||
// CHECK:STDOUT: {kind: 'FileEnd', text: ''},
|
||||
|
||||
Reference in New Issue
Block a user