fix right angle yaml
This commit is contained in:
parent
e9558c906f
commit
44a3d601c4
7 changed files with 20 additions and 23 deletions
|
@ -5,6 +5,5 @@ module org.xbib.datastructures.yaml.tiny {
|
||||||
exports org.xbib.datastructures.yaml.tiny;
|
exports org.xbib.datastructures.yaml.tiny;
|
||||||
requires org.xbib.datastructures.api;
|
requires org.xbib.datastructures.api;
|
||||||
requires org.xbib.datastructures.tiny;
|
requires org.xbib.datastructures.tiny;
|
||||||
requires java.logging;
|
|
||||||
provides DataStructure with Yaml;
|
provides DataStructure with Yaml;
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,8 +84,7 @@ public class Lexer {
|
||||||
if (indent > prevToken.getDepth()) {
|
if (indent > prevToken.getDepth()) {
|
||||||
do {
|
do {
|
||||||
valueTokens.add(token);
|
valueTokens.add(token);
|
||||||
}
|
} while ((token = nextToken()) != null && token.getDepth() > prevToken.getDepth());
|
||||||
while ((token = nextToken()) != null && token.getDepth() > prevToken.getDepth());
|
|
||||||
nextToken = token;
|
nextToken = token;
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
boolean lf = false;
|
boolean lf = false;
|
||||||
|
@ -131,7 +130,15 @@ public class Lexer {
|
||||||
if (isEOL()) {
|
if (isEOL()) {
|
||||||
return nextToken();
|
return nextToken();
|
||||||
}
|
}
|
||||||
if (isText()) {
|
if (isPipe()) {
|
||||||
|
indent = index;
|
||||||
|
read();
|
||||||
|
return new Token(TokenType.PIPE, indent);
|
||||||
|
} else if (isRAngle()) {
|
||||||
|
indent = index;
|
||||||
|
read();
|
||||||
|
return new Token(TokenType.ANGLE, indent);
|
||||||
|
} else if (isText()) {
|
||||||
indent = index;
|
indent = index;
|
||||||
value = extractText();
|
value = extractText();
|
||||||
if (isColon() && hasRightGap()) {
|
if (isColon() && hasRightGap()) {
|
||||||
|
@ -150,14 +157,6 @@ public class Lexer {
|
||||||
indent = index;
|
indent = index;
|
||||||
read(2);
|
read(2);
|
||||||
return new Token(TokenType.ITEM, indent);
|
return new Token(TokenType.ITEM, indent);
|
||||||
} else if (isPipe()) {
|
|
||||||
indent = index;
|
|
||||||
read();
|
|
||||||
return new Token(TokenType.PIPE, indent);
|
|
||||||
} else if (isRAngle()) {
|
|
||||||
indent = index;
|
|
||||||
read();
|
|
||||||
return new Token(TokenType.ANGLE, indent);
|
|
||||||
} else if (isDocumentStart()) {
|
} else if (isDocumentStart()) {
|
||||||
read(3);
|
read(3);
|
||||||
return new Token(TokenType.DOCUMENT_START, 0);
|
return new Token(TokenType.DOCUMENT_START, 0);
|
||||||
|
|
|
@ -4,8 +4,6 @@ import org.xbib.datastructures.api.Node;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
public class ValueNode implements org.xbib.datastructures.api.ValueNode {
|
public class ValueNode implements org.xbib.datastructures.api.ValueNode {
|
||||||
|
|
||||||
|
|
|
@ -8,15 +8,11 @@ import java.io.Reader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import static org.xbib.datastructures.yaml.tiny.TokenType.ITEM;
|
import static org.xbib.datastructures.yaml.tiny.TokenType.ITEM;
|
||||||
|
|
||||||
public class YamlParser implements Parser {
|
public class YamlParser implements Parser {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(YamlParser.class.getName());
|
|
||||||
|
|
||||||
private final List<Token> comments;
|
private final List<Token> comments;
|
||||||
|
|
||||||
private Lexer lexer;
|
private Lexer lexer;
|
||||||
|
|
|
@ -25,7 +25,7 @@ public class YamlSettingsLoader extends AbstractSettingsLoader {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, String> load(String source) throws IOException {
|
public Map<String, String> load(String source) throws IOException {
|
||||||
// replace tabs with whitespace (yaml does not accept tabs, but many users might use it still...)
|
// replace tabs with two whitespace (yaml does not accept tabs, but many users might use it still...)
|
||||||
return super.load(source.replace("\t", " "));
|
return super.load(source.replace("\t", " "));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,18 +50,18 @@ public class YamlSettingsTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRightAngleString() throws IOException {
|
public void testRightAngleString() throws IOException {
|
||||||
String s = "test: >\n this is a\n multiline\n string\na: b\b";
|
String s = "test: >\n this is a\n right-angle multiline\n string\na: b\b";
|
||||||
SettingsLoader loader = new YamlSettingsLoader();
|
SettingsLoader loader = new YamlSettingsLoader();
|
||||||
Map<String, String> map = loader.load(s);
|
Map<String, String> map = loader.load(s);
|
||||||
assertEquals("{test=this is a multiline string, a=b}", map.toString());
|
assertEquals("{test=this is a right-angle multiline string, a=b}", map.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPipeString() throws IOException {
|
public void testPipeString() throws IOException {
|
||||||
String s = "test: |\n this is a\n multiline\n string\na: b\b";
|
String s = "test: |\n this is a\n pipe multiline\n string\na: b\b";
|
||||||
SettingsLoader loader = new YamlSettingsLoader();
|
SettingsLoader loader = new YamlSettingsLoader();
|
||||||
Map<String, String> map = loader.load(s);
|
Map<String, String> map = loader.load(s);
|
||||||
assertEquals("{test=this is a\nmultiline\nstring, a=b}", map.toString());
|
assertEquals("{test=this is a\npipe multiline\nstring, a=b}", map.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
handlers=java.util.logging.ConsoleHandler
|
||||||
|
.level=ALL
|
||||||
|
java.util.logging.SimpleFormatter.format=%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS.%1$tL %4$-7s [%3$s] %5$s %6$s%n
|
||||||
|
java.util.logging.ConsoleHandler.level=ALL
|
||||||
|
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
|
Loading…
Reference in a new issue