[Question]
  [
My coworker, [Jimmy](https://blog.codinghorror.com/new-programming-jargon/) is kinda new to C/C++. He's also kind of a slow learner. Now, to be fair, his code always compiles, but he has some really sloppy habits. For example, everybody knows that you can define an array like this:
```
int spam[] = {4, 8, 15, 16, 23, 42};
```
Everybody that is, except for Jimmy. He is convinced that the *only* way to make an array is like this:
```
int spam[6];
spam[0] = 4;
spam[1] = 8;
spam[2] = 15;
spam[3] = 16;
spam[4] = 23;
spam[5] = 42;
```
I keep fixing this for him in code-review, but he won't learn. So I need you to write a tool that automagically does this for him when he commits¹.
# The challenge
I want you to write either a full program or a function that takes in a multiline string as input, and outputs the more compact version of the C array. The input will *always* follow this format, whitespace included:
```
identifier_one identifier_two[some_length];
identifier_two[0] = some_number;
identifier_two[1] = some_number;
identifier_two[2] = some_number;
...
identifier_two[some_length - 1] = some_number;
```
In short, the input will always be valid and well defined C. In more detail:
All of the identifiers will be made up of just letters and underscores. The length will always be at least one, and there will never be any missing or out of bounds indexes. You may also assume that the indexes are in order. For example:
```
foo bar[3];
bar[0] = 1
bar[2] = 9;
```
```
foo bar[1];
bar[0] = 1;
bar[1] = 3;
```
and
```
foo bar[3];
bar[2] = 9;
bar[0] = 1
bar[1] = 3
```
are all invalid inputs, and may cause undefined behavior in your submission. You may also assume that all of the numbers will be valid decimal numbers, negative or positive. The input will not have extraneous spaces. The output should always follow this format, whitespace included:
```
identifier_one identifier_two[] = {n1, n2, n3, ...};
```
Here is some sample data:
```
Input:
spam eggs[10];
eggs[0] = 0;
eggs[1] = 4;
eggs[2] = 8;
eggs[3] = -3;
eggs[4] = 3;
eggs[5] = 7;
eggs[6] = 888;
eggs[7] = 555;
eggs[8] = 0;
eggs[9] = -2;
Output:
spam eggs[] = {0, 4, 8, -3, 3, 7, 888, 555, 0, -2};
Input:
char ans[2];
ans[0] = 52;
ans[1] = 50;
Output:
char ans[] = {52, 50};
Input:
blah_blah quux[1];
quux[0] = 105;
Output:
blah_blah quux[] = {105};
```
You may take your input and output in any reasonable format, such as STDIN/STDOUT, function arguments and return value, reading and writing files etc. Standard loopholes apply. The shortest answer in bytes wins!
---
*¹This is passive-aggressive and a terrible idea. You did **not** get this idea from me.*
  
[Answer]
# Vim, ~~43~~ 36 bytes
You don't need to give Jimmy a script, just teach him to use a proper text editor. (literal returns for clarity)
```
:%s/.*=//|%s/;\n/,/<cr><cr>
3wcf ] = {<esc>
$s};
```
[Answer]
## CJam, ~~43~~ 36 bytes
```
qN/('[/~;"[] = {"@{S/W=W<}%", "*"};"
```
[**Online Example**](http://cjam.tryitonline.net/#code=cU4vKCdbL347IltdID0geyJAe1MvVz1XPH0lIiwgIioifTsi&input=c3BhbSBlZ2dzWzEwXTsKZWdnc1swXSA9IDA7CmVnZ3NbMV0gPSA0OwplZ2dzWzJdID0gODsKZWdnc1szXSA9IC0zOwplZ2dzWzRdID0gMzsKZWdnc1s1XSA9IDc7CmVnZ3NbNl0gPSA4ODg7CmVnZ3NbN10gPSA1NTU7CmVnZ3NbOF0gPSAwOwplZ2dzWzldID0gLTI7)
**Explanation:**
```
qN/                                     |Read all lines to array
   ('[/~;                               |slice first line left of [
         "[] = {"                       |add formatting to stack
                 @                      |rotate to remaining lines
                  {      }%             |for each line in array
                   S/W=                 |split after last space
                       W<               |remove last character (;)
                           ", "*        |insert ", " to array
                                "};"    |add formatting
```
A big thanks to [Martin Ender](https://codegolf.stackexchange.com/users/8478/martin-ender) for the improvements on my first CJam answer.
[Answer]
# JavaScript (ES6), ~~65~~ ~~64~~ 63 bytes
```
s=>`${s.split`[`[0]}[] = {${s.match(/-?\d+(?=;)/g).join`, `}};`
```
[Answer]
## [Retina](http://github.com/mbuettner/retina), ~~30~~ 28 bytes
Byte count assumes ISO 8859-1 encoding.
```
\d+];¶.+ 
] = {
;¶.+=
,
;
};
```
[Try it online!](http://retina.tryitonline.net/#code=XGQrXTvCti4rIApdID0gewo7wrYuKz0KLAo7Cn07&input=c3BhbSBlZ2dzWzEwXTsKZWdnc1swXSA9IDA7CmVnZ3NbMV0gPSA0OwplZ2dzWzJdID0gODsKZWdnc1szXSA9IC0zOwplZ2dzWzRdID0gMzsKZWdnc1s1XSA9IDc7CmVnZ3NbNl0gPSA4ODg7CmVnZ3NbN10gPSA1NTU7CmVnZ3NbOF0gPSAwOwplZ2dzWzldID0gLTI7)
### Explanation
We'll use the following input as an example:
```
spam eggs[4];
eggs[0] = 0;
eggs[1] = 4;
eggs[2] = 8;
eggs[3] = -3;
```
**Stage 1**
```
\d+];¶.+ 
] = {
```
Note that there's a trailing space on the first line.
We start by matching a number following by `];` and a linefeed, and then everything up to the last space on the next line. This match can only be found at the end of the first line (due to the `];`). All of this is replaced with `] = {`. That is, it transforms our example input to:
```
spam eggs[] = {0;
eggs[1] = 4;
eggs[2] = 8;
eggs[3] = -3;
```
**Stage 2**
```
;¶.+=
,
```
Now we match everything from a `;` up to the `=` on the next line and replace with a `,`. This transforms the string to:
```
spam eggs[] = {0, 4, 8, -3;
```
**Stage 3**
```
;
};
```
All that's left is fixing the end and we do this by replacing the only remaining `;` with `};`:
```
spam eggs[] = {0, 4, 8, -3};
```
[Answer]
## Julia, ~~112~~ ~~108~~ 105 Bytes
```
f(s)=string(split(s,'[')[1],"[] = {",join([m[1] for m in [eachmatch(r"= *(-?\d+)",s)...]],", "),"};")
```
**Explanation**
```
string(                                                         # build output string
split(s,'[')[1],                                                # get declaration (e.g. spam eggs)
"[] = {",                                                       # add [] = {
join(                                                           # collect numbers
    [m[1] for m in [eachmatch(r"= *(-?\d+)",s)...]],            # regex out (signed) numbers
    ", "),                                                      # and join comma separated
"};"                                                            # add };
)                                                               # close string(
```
Saved bytes by replacing collect(eachmatch()) with [eachmatch()...] and with a shorter regex
[Answer]
## Lua, 121 Bytes.
```
function g(s)print(s:gmatch('.-%[')()..'] = {'..s:gsub('.-\n','',1):gsub('.-([%d.-]+);\n?','%1, '):gsub(',%s+$','};'))end
```
## Explained
```
function g(s)
    print(                              -- Print, Self Explaintry.
        s:gmatch('.-%[')()..'] = {'     -- Find the 'header', match the first line's class and assignment name (everything up to the 'n]') and append that. Then, append ] = {.
                                        -- In the eggs example, this looks like; 'spam eggs[] = {' now
        ..                              -- concatenate...
        s:gsub('.-\n','',1)             -- the input, with the first line removed.
        :gsub('.-([%d.-]+);\n?','%1, ') -- Then that chunk is searched, quite boringly, a number followed by a semicolon, and the entire string is replaced with an array of those,
                                        -- EG, '1, 2, 3, 4, 5, 6, '
        :gsub(',%s+$','};')          -- Replace the final ', ' (if any) with a single '};', finishing our terrifying combination
    )
end
```
[Answer]
## Batch, 160 bytes
```
@echo off
set/ps=
set s=%s:[=[] = {&rem %
set r=
:l
set t=
set/pt=
if "%t%"=="" echo %r%};&exit/b
set t=%t:* =%
set r=%r%%s%%t:~2,-1%
set s=, 
goto l
```
Note: The line `set s=,` ends with a space. Takes input on STDIN. That weird line 3 takes the input (e.g. `int spam[6];` and changes the `[` into `[] = {&rem` resulting in `set s=int spam[] = {&rem 6];` which then gets interpreted as two statements, `set s=int spam[] = {` and `rem 6];`, the latter of which is a comment. Then for each line we delete the text up to the first space (because you can't use `=` in a pattern and the matching is non-greedy) and extract the value.
[Answer]
# C, 121 bytes
```
n=2;main(i){for(;putchar(getchar())^91;);for(printf("] = {");~scanf("%*[^=]%*c%d",&i);n=0)printf(", %d"+n,i);puts("};");}
```
[Answer]
### Python 112 111
Very straightforward to me, please suggest any improvement that comes to mind.
```
def f(l):
 a,*b=l.split('\n')
 return a[:a.index('[')]+'[] = {'+', '.join(r.split(' = ')[1][:-1]for r in b)+'};'
# TEST
lines = """spam eggs[10];
eggs[0] = 0;
eggs[1] = 4;
eggs[2] = 8;
eggs[3] = -3;
eggs[4] = 3;
eggs[5] = 7;
eggs[6] = 888;
eggs[7] = 555;
eggs[8] = 0;
eggs[9] = -2;"""
print (f(lines))
assert f(lines) == 'spam eggs[] = {0, 4, 8, -3, 3, 7, 888, 555, 0, -2};'
```
[Answer]
# [05AB1E](http://github.com/Adriandmen/05AB1E), ~~31~~ ~~30~~ 28 bytes
```
žh-|vy#¤¨ˆ\}¨… = ¯ïžuDÀÀ‡';J
```
**Explanation**
```
žh-¨                            # remove numbers and ";" from first input
    |v      }                   # for each of the rest of the inputs
      y#                        # split on spaces
        ¤¨                      # take the last element (number) minus the last char (";") 
          ˆ\                    # store in global array and throw the rest of the list away
             … =                # push the string " = "
                 ¯ï             # push global array and convert to int
                   žuDÀÀ‡       # replace square brackets of array with curly ones
                         ';     # push ";"
                           J    # join everything and display
```
[Try it online!](http://05ab1e.tryitonline.net/#code=xb5oLcKofHZ5I8KkwqjLhlx94oCmID0gwq_Dr8W-dUTDgMOA4oChJztK&input=c3BhbSBlZ2dzWzEwXTsKZWdnc1swXSA9IDA7CmVnZ3NbMV0gPSA0OwplZ2dzWzJdID0gODsKZWdnc1szXSA9IC0zOwplZ2dzWzRdID0gMzsKZWdnc1s1XSA9IDc7CmVnZ3NbNl0gPSA4ODg7CmVnZ3NbN10gPSA1NTU7CmVnZ3NbOF0gPSAwOwplZ2dzWzldID0gLTI7)
Saved a byte thanks to [Adnan](https://codegolf.stackexchange.com/users/34388/adnan)
[Answer]
# Java 7, ~~159~~ ~~158~~ ~~149~~ 154 bytes
```
String c(String[]a){a[0]=a[0].split("\\d")[0]+"] = {\b";for(String i:a)a[0]+=i.split("= [{]*")[1];return a[0].replace(";",", ").replaceFirst("..$","};");}
```
Multiple bytes saved thanks to *@cliffroot*.
**Ungolfed & test code:**
[Try it here.](https://ideone.com/qJ0a4u)
```
class M{
  static String c(String[] a){
    a[0] = a[0].split("\\d")[0] + "] = {\b";
    for(String i : a){
      a[0] += i.split("= [{]*")[1];
    }
    return a[0].replace(";", ", ").replaceFirst("..$", "};");
  }
  public static void main(String[] a){
    System.out.println(c(new String[]{ "spam eggs[10];", "eggs[0] = 0;", "eggs[1] = 4;",
      "eggs[2] = 8;", "eggs[3] = -3;", "eggs[4] = 3;", "eggs[5] = 7;", "eggs[6] = 888;",
      "eggs[7] = 555;", "eggs[8] = 0;", "eggs[9] = -2;" }));
    System.out.println(c(new String[]{ "char ans[2]", "ans[0] = 52;", "ans[1] = 50;" }));
    System.out.println(c(new String[]{ "blah_blah quux[1];", "quux[0] = 105;" }));
  }
}
```
**Output:**
```
spam eggs[] = {0, 4, 8, -3, 3, 7, 888, 555, 0, -2};
char ans[] = {52, 50};
blah_blah quux[] = {105};
```
[Answer]
## Perl, 42 + 2 (`-0p`) = 44 bytes
```
s%\d+].*%] = {@{[join",",/(-?\d+);/g]}};%s
```
Needs `-p` and `-0` flags to run. For instance :
```
perl -0pe 's%\d+].*%] = {@{[join",",/(-?\d+);/g]}};%s' <<< "blah_blah quux[1];
quux[0] = 105;"
```
[Answer]
# [jq](https://stedolan.github.io/jq/), 85 bytes
```
./"
"|(.[0]|gsub("\\d|;";""))+" = {"+(.[1:]|map([scan("-?\\d+")][-1])|join(", "))+"}"
```
[Try it online!](https://tio.run/##Vc3NDsIgDAfwu09BeoLMTdiGQ4nxQRgH/Mjiks0Z4kl8dgQSlnjrr@2/HV/eVzvYgMOVotoN9n3B0Pc3J0ECEFIAOqEPFGHMjtpNZsHKXs2MoTyHtQKIViXTxI3PR2huUcp8wXuwi5nQfRisYlTLfk4l1eEezWJRbVYdJbKaqLLJbCNX8agua5@CYo120ZzzbPH39JAO1xJ@ "jq – Try It Online")
I can probably remove the `map`, but not sure how to do it without breaking the thing. Otherwise quite satisfied with the solution.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 33 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
ỴḊḲ€Ṫ€K⁾;,yṖ“{“};”j
ỴḢḟØDṖ,⁾ =,ÇK
```
**[TryItOnline](http://jelly.tryitonline.net/#code=4bu04biK4biy4oKs4bmq4oKsS-KBvjsseeG5luKAnHvigJx9O-KAnWoK4bu04bii4bifw5hE4bmWLOKBviA9LMOHSw&input=&args=c3BhbSBlZ2dzWzEwXTsKZWdnc1swXSA9IDA7CmVnZ3NbMV0gPSA0OwplZ2dzWzJdID0gODsKZWdnc1szXSA9IC0zOwplZ2dzWzRdID0gMzsKZWdnc1s1XSA9IDc7CmVnZ3NbNl0gPSA4ODg7CmVnZ3NbN10gPSA1NTU7CmVnZ3NbOF0gPSAwOwplZ2dzWzldID0gLTI7)**
How?
```
ỴḊḲ€Ṫ€K⁾;,yṖ“{“};”j - Link 1, parse and reform the values, same input as the Main link
Ỵ                   - split on line feeds
 Ḋ                  - dequeue (remove the first line)
  Ḳ€                - split each on spaces
    Ṫ€              - tail each (get the numbers with trailing ';')
      K             - join on spaces
       ⁾;,          - ";,"
          y         - map (replace ';' with ',')
           Ṗ        - pop (remove the last ',')
            “{“};”  - list of strings ["{","};"]
                  j - join (making "{" + "n0, n1, ,n2, ..." + "};")
ỴḢḟØDṖ,⁾ =,ÇK - Main link, takes one argument, the multiline string
Ỵ             - split on line feeds
 Ḣ            - head (just the first line)
   ØD         - digits yield "0123456789"
  ḟ           - filter out
     Ṗ        - pop (remove the trailing ';')
      ,   ,   - pair
       ⁾ =    - the string " ="
           Ç  - call the previous Link (1)
            K - join on spaces (add the space after the '=')
```
[Answer]
# [Jelly](http://github.com/DennisMitchell/jelly), 27 bytes
```
Ỵ©ḢḟØDṖ“ = {”®Ḳ€Ṫ€Ṗ€j⁾, ⁾};
```
[Try it online!](http://jelly.tryitonline.net/#code=4bu0wqnhuKLhuJ_DmEThuZbigJwgPSB74oCdwq7huLLigqzhuarigqzhuZbigqxq4oG-LCDigb59Ow&input=&args=c3BhbSBlZ2dzWzEwXTsKZWdnc1swXSA9IDA7CmVnZ3NbMV0gPSA0OwplZ2dzWzJdID0gODsKZWdnc1szXSA9IC0zOwplZ2dzWzRdID0gMzsKZWdnc1s1XSA9IDc7CmVnZ3NbNl0gPSA4ODg7CmVnZ3NbN10gPSA1NTU7CmVnZ3NbOF0gPSAwOwplZ2dzWzldID0gLTI7)
## Explanation
```
Ỵ         Split into lines
 ©Ḣ       Take the first one, store the others in ®
   ḟØD    Remove digits
      Ṗ   Remove trailing ;
“ = {”    Print a literal string
®         Recall the remaining lines
 Ḳ€       Split each into words
   Ṫ€     Keep each last word
     Ṗ€   Remove each trailing ;
j⁾,       Join by “, ”
    ⁾};   Literal “};”
```
[Answer]
# sed 51
```
1s,\[.*,[] = {,
:
N
s,\n.*= ,,
s/;/, /
$s/, $/};/
t
```
[Answer]
# Java, 106 bytes
String manipulation in Java is hell, as always.
```
a->a[0].join("",a).replaceAll(";\\w+\\[\\d+\\] = ",", ").replaceAll("\\d+\\], ","] = {").replace(";","};")
```
This is a pure regex answer. Make a single concatenated `String`, then perform `replaceXxx` until it's ok.
## Testing and ungolfed:
```
import java.util.function.Function;
public class Main {
  public static void main(String[] args) {
    Function<String[], String> f = a ->
        String.join("", a)                          // I think this would join. Not sure, though. Golfed into a[0].join because static members are accessible from instances.
            .replaceAll(";\\w+\\[\\d+\\] = ", ", ") // replace with regex
            .replaceAll("\\d+\\], ", "] = {")       // replace with regex
            .replace(";", "};");                    // replace no regex
    String[] spam = {
      "int spam[6];",
      "spam[0] = 4;",
      "spam[1] = 8;",
      "spam[2] = 15;",
      "spam[3] = 16;",
      "spam[4] = 23;",
      "spam[5] = 42;"
    };
    test(f, spam, "int spam[] = {4, 8, 15, 16, 23, 42};");
    String[] eggs = {
      "spam eggs[10];",
      "eggs[0] = 0;",
      "eggs[1] = 4;",
      "eggs[2] = 8;",
      "eggs[3] = -3;",
      "eggs[4] = 3;",
      "eggs[5] = 7;",
      "eggs[6] = 888;",
      "eggs[7] = 555;",
      "eggs[8] = 0;",
      "eggs[9] = -2;"
    };
    test(f, eggs, "spam eggs[] = {0, 4, 8, -3, 3, 7, 888, 555, 0, -2};");
    String[] ans = {
      "char ans[2];",
      "ans[0] = 52;",
      "ans[1] = 50;"
    };
    test(f, ans, "char ans[] = {52, 50};");
    String[] quux = {
      "blah_blah quux[1];",
      "quux[0] = 105;"
    };
    test(f, quux, "blah_blah quux[] = {105};");
  }
  static void test(Function<String[], String> f, String[] input, String expected) {
    System.out.printf("Result:   %s%nExpected: %s%n", f.apply(input), expected);
  }
}
```
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal) `aṪ`, 28 bytes
```
ḣƛ⌈t⌊;‛, j\{p\}+$kd$FṪ` = `„
```
[Try it Online!](https://lyxal.pythonanywhere.com?flags=a%E1%B9%AA&code=%E1%B8%A3%C6%9B%E2%8C%88t%E2%8C%8A%3B%E2%80%9B%2C%20j%5C%7Bp%5C%7D%2B%24kd%24F%E1%B9%AA%60%20%3D%20%60%E2%80%9E&inputs=int%20spam%5B6%5D%3B%0Aspam%5B0%5D%20%3D%204%3B%0Aspam%5B1%5D%20%3D%208%3B%0Aspam%5B2%5D%20%3D%2015%3B%0Aspam%5B3%5D%20%3D%2016%3B%0Aspam%5B4%5D%20%3D%2023%3B%0Aspam%5B5%5D%20%3D%2042%3B&header=&footer=)
```
ḣ                            # Head extract
 ƛ   ;                       # Foreach line except the first
  ⌈t⌊                        # Split on spaces, get the last, parse an int
      ‛, j\{p\}+             # Join by commas and add {}
                $kd$FṪ       # Remove digits from line 1
                      ` = `„ # Push a ` = ` and prepare the stack for printing
```
[Answer]
# [Pip](https://github.com/dloscutoff/pip) `-r`, ~~32~~ 30 bytes
```
aRXI.']["] = {"(Z@>g@XI1)Jk'}]
```
[Try it online!](https://tio.run/##K8gs@P8/MSjCU089NlopVsFWoVpJI8rBLt0hwtNQ0ytbvTb2///igsRchdT09OJoQ4NYay4wywCk1gDKMQRxTKAcIxDHAsoxBnF0jaE8ExAPxjEFccyhHDOwJguYNnMQ19TUFMq1QLbMEmykkfV/3SIA "Pip – Try It Online")
### Explanation
The builtin regex for matching integers, `XI == `-?\d+``, came in really handy here.
```
aRXI.']["] = {"(Z@>g@XI1)Jk'}]
                                g is list of lines from stdin; a is first line (-r flag)
aR                              In the first line, replace
  XI.']                         integer followed by closing square bracket, with:
                 @>g             All but the first element in g
                    @XI          Find all (two) integers in each element
                Z                Zip that list of pairs into a pair of lists
               (       1)        and take the second list (the values)
                         Jk      Join on ", "
       [                     ]   Put the above string in a list
        "] = {"                  with this string before it
                           '}    and a curly brace after it
                                (The list is converted to a string when used as a
                                replacement; since there are no list-formatting flags
                                in use, its elements are simply concatenated together)
```
[Answer]
## Ruby, 64 bytes
```
->{gets.split(?[)[0]+"[]={"+$<.map{|s|s.scan /\ -?\d+/}*?,+"};"}
```
[Answer]
# JavaScript, 125 bytes
I know it's longer than others, but I really wanted to use `eval`. Just for fun.
```
f=function(s){m=/^(\w+ )(\w+).*?(;.*)/.exec(s)
eval("var "+m[2]+"=new Array()"+m[3]+'alert(m[1]+m[2]+"={"+eval(m[2])+"};")')}
```
To run, paste the following into [here](http://www.webtoolkitonline.com/javascript-tester.html):
```
s='int spam[6];\
spam[0] = 4;\
spam[1] = 8;\
spam[2] = 15;\
spam[3] = 16;\
spam[4] = 23;\
spam[5] = 42;'
f=function(s){m=/^(\w+ )(\w+).*?(;.*)/.exec(s)
eval("var "+m[2]+"=new Array()"+m[3]+'alert(m[1]+m[2]+"={"+eval(m[2])+"};")')}
f(s)
```
[Answer]
## Haxe, 234 bytes
```
function R(L:Array<String>){var S=L[0];var W=S.indexOf(" ");var T=S.substr(0,W),M=S.substring(W+1,S.indexOf("["));var r=[for(i in 1...L.length)L[i].substring(L[i].lastIndexOf(" ")+1,L[i].length-1)].join(', ');return'$T $M[] = {$r};';}
```
Long function names killed this :D
Try the testcases [here](http://try.haxe.org/#c8527)!
[Answer]
# [V](http://github.com/DJMcMayhem/V), ~~25~~, 24 bytes
```
3wC] = {òJd2f $s, òhC};
```
[Try it online!](http://v.tryitonline.net/#code=M3dDXSA9IHsbw7JKZDJmICRzLCDDsmhDfTs&input=aW50IHNwYW1bNl07CnNwYW1bMV0gPSA4OwpzcGFtWzJdID0gMTU7CnNwYW1bM10gPSAxNjsKc3BhbVs0XSA9IDIzOwpzcGFtWzVdID0gNDI7)
This contains an unprintable `<esc>` character, so here is a hexdump:
```
0000000: 3377 435d 203d 207b 1bf2 4a64 3266 2024  3wC] = {..Jd2f $
0000010: 732c 20f2 6843 7d3b                      s, .hC};
```
Explanation:
```
3w                              "Move forward 3 words
  C     <esc>                   "Delete everything until the end of the line, and enter this text:
   ] = {                        "'] = {'
             ò         ò        "Recursively:
              J                 "  Join these two lines (which enters a space)
               d                "  Delete everything until you
                2f              "  (f)ind the (2)nd space
                   $            "  Move to the end of this line
                    s           "  Delete a character, and enter:
                     ,          "  ', '
                                "
                        h       "Move one character to the left
                         C      "Delete everything until the end of the line, and enter this text:
                          };    "'};'
```
[Answer]
# [Julia 1.0](http://julialang.org/), 81 bytes
```
!s=split(s,"[")[1]*"[] = {"*join([s[1] for s=eachmatch(r"(-*\d+);",s)],", ")*"};"
```
[Try it online!](https://tio.run/##Tc3LCoMwEAXQfb8iziqxEXylWoJfkmYRrK0RXxgLhdJvT41E6G7OhXune/VaJW9rA1OZudcrNhQEEJHIEIREFfpA2E16xMJsGXpMCzJVo@p2UGvd4gVwFN7uZ8KBGiIpUAQkhC8HOy96XPsRB2BmNaDm@dwWYslP@xW77dgjccg9UofSI3OIMq/c6QBzKDwue6k8aoUjY8yz/H923SdTDsT@AA "Julia 1.0 – Try It Online")
[Answer]
# [Haskell](https://www.haskell.org/), 80 bytes
```
f x=takeWhile(/='[')x++"[] = {"++drop 2([", "++w|w<-words x,w<"="]>>=init)++"};"
```
[Try it online!](https://tio.run/##fc5LCoMwEAbgfU8RslFRqY@mKhqv0UVwEWrU4BMTUGh7dmskQled1XwD/8w0VLSs67atAiuWtGWPhnfMvGKDGNZq25AUAIMXtO1yHicQmAQ6YNfyXjJ3GedSgNVZMohhkeeYD1xae@iTwq2nfNgHks30KUG1iYn2gNW1IL5fpJej89RyT8NXuGkECrFGqOCGWjelE0gh0rgfofiMRYoIIc3491hyrAzO08cjbvK30i8 "Haskell – Try It Online") Haskell is normally not very good at string-process-y challenges but it does OK here.
## Explanation
`takeWhile(/='[')x` extracts the typename and identifier `"spam eggs"`. Then we append `"[] = {" ++ drop 2 nums ++ "};"`, where `nums` is:
```
 [", "++w|w<-words x,w<"="]>>=init
```
The "words" (whitespace-delimited parts) of the input that are lexicographically less than `"="` happen to be all the digit-plus-semicolon parts like `"0;"`. This is because `'-'` < `'0'..'9'` < `'='` < `'a'..'z'`.
The list comprehension says that to each such part, we prepend a comma and space:
```
[", 0;",", 4;",", 8;"]
```
Then `>>=init` (`concatMap init`) concatenates and chops off the semicolons:
```
", 0, 4, 8"
```
After which point `drop 2` gets rid of the initial comma.
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 42 bytes 39 bytes
```
+:++:h.z"\d"k" = {"j", "mecd\ t.z\;k"}; // `ecd\ ` takes last word rather than regex replace
+:++:h.z"\d"k" = {"j", "m:d".* "kt.z\;k"};
```
[Try it online!](https://tio.run/##Tc1NCoMwEIbhfU8xzLJpQ/xJjQmeRF0ULEqDIOhGpWePThihu3kW7zfTugwhCCuEHeSGTYceoYIdv/gAHG2H8g7oF7k1zuPPhTBP7xE@fT/XiWrdLV6qPRvFSAg5IyUYRkZ4ZqycdEETCsYrRubKCqLWmmn@n5VxMnUH "Pyth – Try It Online")
## Explanation
```
+:++:h.z"\d"k" = {"j", "m:d".* "kt.z\;k"};
  ++                                         // Join the following strings:
    :h.z"\d"k                                //   input[0] with regex \d replaced for empty string
             " = {"                          //   Literal ` = {`
                   j", "                     //   Join with `, ` the following:
                        m:d".* "kt.z         //      Rest of input, removing everything before the numbers
                                             // Now our string looks like:
                                             //   spam eggs[]; = {0;, 4;, 8;, -3;, 3;, 7;, 888;, 555;, 0;, -2;
 :            [our string]          \;k      // Remove ';'
+                                      "};   // Append "};"
```
]