mirror of
https://github.com/lightbend/config.git
synced 2025-02-22 01:00:31 +08:00
add SyntaxFlavor to the parser (not used for anything yet)
This commit is contained in:
parent
5a5eb7acfe
commit
986e2a24cb
@ -23,31 +23,36 @@ final class Parser {
|
||||
* buffered. Does not close the stream; you have to arrange to do that
|
||||
* yourself.
|
||||
*/
|
||||
static AbstractConfigValue parse(ConfigOrigin origin, InputStream input) {
|
||||
static AbstractConfigValue parse(SyntaxFlavor flavor, ConfigOrigin origin,
|
||||
InputStream input) {
|
||||
try {
|
||||
return parse(origin, new InputStreamReader(input, "UTF-8"));
|
||||
return parse(flavor, origin, new InputStreamReader(input, "UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new ConfigException.BugOrBroken(
|
||||
"Java runtime does not support UTF-8");
|
||||
}
|
||||
}
|
||||
|
||||
static AbstractConfigValue parse(ConfigOrigin origin, Reader input) {
|
||||
static AbstractConfigValue parse(SyntaxFlavor flavor, ConfigOrigin origin,
|
||||
Reader input) {
|
||||
Iterator<Token> tokens = Tokenizer.tokenize(origin, input);
|
||||
return parse(origin, tokens);
|
||||
return parse(flavor, origin, tokens);
|
||||
}
|
||||
|
||||
static AbstractConfigValue parse(ConfigOrigin origin, String input) {
|
||||
return parse(origin, new StringReader(input));
|
||||
static AbstractConfigValue parse(SyntaxFlavor flavor, ConfigOrigin origin,
|
||||
String input) {
|
||||
return parse(flavor, origin, new StringReader(input));
|
||||
}
|
||||
|
||||
static private final class ParseContext {
|
||||
private int lineNumber;
|
||||
private SyntaxFlavor flavor;
|
||||
private ConfigOrigin baseOrigin;
|
||||
|
||||
ParseContext(ConfigOrigin origin) {
|
||||
ParseContext(SyntaxFlavor flavor, ConfigOrigin origin) {
|
||||
lineNumber = 0;
|
||||
baseOrigin = origin;
|
||||
this.flavor = flavor;
|
||||
this.baseOrigin = origin;
|
||||
}
|
||||
|
||||
private Token nextTokenIgnoringNewline(Iterator<Token> tokens) {
|
||||
@ -207,9 +212,10 @@ final class Parser {
|
||||
}
|
||||
}
|
||||
|
||||
private static AbstractConfigValue parse(ConfigOrigin origin,
|
||||
private static AbstractConfigValue parse(SyntaxFlavor flavor,
|
||||
ConfigOrigin origin,
|
||||
Iterator<Token> tokens) {
|
||||
ParseContext context = new ParseContext(origin);
|
||||
ParseContext context = new ParseContext(flavor, origin);
|
||||
return context.parse(tokens);
|
||||
}
|
||||
}
|
||||
|
5
src/main/java/com/typesafe/config/impl/SyntaxFlavor.java
Normal file
5
src/main/java/com/typesafe/config/impl/SyntaxFlavor.java
Normal file
@ -0,0 +1,5 @@
|
||||
package com.typesafe.config.impl;
|
||||
|
||||
enum SyntaxFlavor {
|
||||
JSON, HOCON
|
||||
}
|
@ -32,7 +32,7 @@ class JsonTest extends TestUtils {
|
||||
}
|
||||
|
||||
def parse(s: String): ConfigValue = {
|
||||
Parser.parse(new SimpleConfigOrigin("test string"), s)
|
||||
Parser.parse(SyntaxFlavor.JSON, new SimpleConfigOrigin("test string"), s)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user