private Maybe<Symbol> processYaml(Symbol yaml, Symbol symbolList) { boolean addToPrevious = false; String key = null, value = ""; for (Symbol symbol : symbolList.getChildren()) { if (symbol.isType(SymbolType.Whitespace) && key == null) { addToPrevious = true; } else if (symbol.isType(SymbolType.Text) && key == null) { key = symbol.getContent(); } else if (symbol.isType(SymbolType.Text) || symbol.isType(SymbolType.Whitespace) || (symbol.isType(SymbolType.Colon) && !isBlank(value))) { value += symbol.getContent(); } else if (symbol.isType(SymbolType.Colon)) { // Now start filling value if (key == null) return Symbol.nothing; } else if (symbol.isType(SymbolType.Newline)) { if (key != null) { if (addToPrevious) yaml.getChildren().get(yaml.getChildren().size() - 1).add(yamlLine(key, value.trim())); else yaml.add(yamlLine(key, value.trim())); } key = null; value = ""; addToPrevious = false; } else { // All possible alternatives should be covered now. return Symbol.nothing; } } return new Maybe<>(yaml); }
private Maybe<Symbol> processYaml(Symbol yaml, Symbol symbolList) { boolean addToPrevious = false; String key = null, value = ""; for (Symbol symbol : symbolList.getChildren()) { if (symbol.isType(SymbolType.Whitespace) && key == null) { addToPrevious = true; } else if (symbol.isType(SymbolType.Text) && key == null) { key = symbol.getContent(); } else if (symbol.isType(SymbolType.Text) || symbol.isType(SymbolType.Whitespace) || (symbol.isType(SymbolType.Colon) && !isBlank(value))) { value += symbol.getContent(); } else if (symbol.isType(SymbolType.Colon)) { // Now start filling value if (key == null) return Symbol.nothing; } else if (symbol.isType(SymbolType.Newline)) { if (key != null) { if (addToPrevious) yaml.getChildren().get(yaml.getChildren().size() - 1).add(yamlLine(key, value.trim())); else yaml.add(yamlLine(key, value.trim())); } key = null; value = ""; addToPrevious = false; } else { // All possible alternatives should be covered now. return Symbol.nothing; } } return new Maybe<>(yaml); }