@Override
    public void parse(String text) {
        errors = new LinkedList<>();
        graph = new NetworkGraph();
        inputs = new LinkedList<>();
        productionRules = new LinkedList<>();
        massCreations = new HashMap<>();
        springCreations = new HashMap<>();
        numberOfRandomMasses = 0;
        numberOfRandomSprings = 0;
        options = new LinkedList<>();
        expansionRangeX = DEFAULT_EXPANSION_RANGE_X;

        if (text == null) {
            return;
        }

        String[] lines = text.split("\n");

        for (int i = 0; i < lines.length; i++) {
            if (isEmpty(lines[i]) || isComment(lines[i])) {
                continue;
            }

            if (isKeywordLine(lines[i])) {
                switch (getKeywordOfLine(lines[i])) {
                    case shoulder:
                        shoulder = parseMasses(lines[i]).get(0);
                        shoulder.setType(SHOULDER);
                        graph.addMasses(shoulder);
                        break;
                    case elbow:
                        elbow = parseMasses(lines[i]).get(0);
                        elbow.setType(ELBOW);
                        graph.addMasses(elbow);
                        break;
                    case hand:
                        hand = parseMasses(lines[i]).get(0);
                        hand.setType(HAND);
                        graph.addMasses(hand);
                        break;
                    case input:
                        Mass input = parseMasses(lines[i]).get(0);
                        input.setType(INPUT);
                        inputs.add(input);
                        graph.addMasses(input);
                        break;
                    case productionRules:
                        productionRules.addAll(parseProductionRule(lines[i]));
                        break;
                    case expansionRangeX:
                        expansionRangeX = parseExpansionRange(lines[i]);
                        break;
                    case createMass:
                        String massLetter = parseCreateLetter(lines[i]);
                        Range createMassRange = parseCreateRange(lines[i]);
                        massCreations.put(massLetter, createMassRange);
                        break;
                    case createSpring:
                        String springLetter = parseCreateLetter(lines[i]);
                        Range createSpringRange = parseCreateRange(lines[i]);
                        springCreations.put(springLetter, createSpringRange);
                        break;
                    case randomMasses:
                        numberOfRandomMasses = parseInteger(lines[i]);
                        break;
                    case randomSprings:
                        numberOfRandomSprings = parseInteger(lines[i]);
                        break;
                    case options:
                        options.addAll(parseOptions(lines[i]));
                        break;
                }

                continue;
            }

            errors.add(new ParserError(i, "Cannot understand this line."));
        }

        createAndConnectSegmentsToInputs();
    }