Moved all classes to single package to reduce visibility.

Only Toml class is public.
This commit is contained in:
moandji.ezana 2014-08-12 17:38:23 +02:00
parent 0a4ac0d875
commit bc6fa8e736
13 changed files with 47 additions and 47 deletions

View file

@ -1,6 +1,6 @@
package com.moandjiezana.toml.values;
package com.moandjiezana.toml;
import static com.moandjiezana.toml.values.ValueConverter.INVALID;
import static com.moandjiezana.toml.ValueParserUtils.INVALID;
import java.util.ArrayList;
import java.util.List;
@ -9,8 +9,6 @@ import org.parboiled.Parboiled;
import org.parboiled.parserunners.BasicParseRunner;
import org.parboiled.support.ParsingResult;
import com.moandjiezana.toml.StatementParser;
class ArrayParser implements ValueParser {
static final ArrayParser ARRAY_PARSER = new ArrayParser();

View file

@ -1,4 +1,6 @@
package com.moandjiezana.toml.values;
package com.moandjiezana.toml;
import static com.moandjiezana.toml.ValueParserUtils.INVALID;
class BooleanParser implements ValueParser {
@ -13,7 +15,7 @@ class BooleanParser implements ValueParser {
public Object parse(String s) {
if (s.startsWith("true") && !ValueParserUtils.isComment(s.substring(4)) ||
s.startsWith("false") && !ValueParserUtils.isComment(s.substring(5))) {
return ValueConverter.INVALID;
return INVALID;
}
return s.startsWith("true") ? Boolean.TRUE : Boolean.FALSE;

View file

@ -1,12 +1,12 @@
package com.moandjiezana.toml.values;
package com.moandjiezana.toml;
import static com.moandjiezana.toml.values.ValueConverter.INVALID;
import static com.moandjiezana.toml.ValueParserUtils.INVALID;
import java.text.SimpleDateFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class DateParser implements ValueParser {
class DateParser implements ValueParser {
static final DateParser DATE_PARSER = new DateParser();
private static final Pattern DATE_REGEX = Pattern.compile("(\\d{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]:[0-5][0-9]:[0-5][0-9]Z)(.*)");

View file

@ -1,9 +1,9 @@
package com.moandjiezana.toml.values;
package com.moandjiezana.toml;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class FloatParser implements ValueParser {
class FloatParser implements ValueParser {
public static final FloatParser FLOAT_PARSER = new FloatParser();
private static final Pattern FLOAT_REGEX = Pattern.compile("(-?\\d+\\.\\d+)(.*)");

View file

@ -1,11 +1,11 @@
package com.moandjiezana.toml.values;
package com.moandjiezana.toml;
import static com.moandjiezana.toml.values.ValueParserUtils.isComment;
import static com.moandjiezana.toml.ValueParserUtils.isComment;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class IntegerParser implements ValueParser {
class IntegerParser implements ValueParser {
private static final Pattern INTEGER_REGEX = Pattern.compile("(-?[0-9]*)(.*)");
static final IntegerParser INTEGER_PARSER = new IntegerParser();
@ -25,4 +25,5 @@ public class IntegerParser implements ValueParser {
return Long.valueOf(matcher.group(1));
}
private IntegerParser() {}
}

View file

@ -7,15 +7,15 @@ import java.util.Map;
import java.util.Set;
class Results {
public Set<String> tables = new HashSet<String>();
public StringBuilder errors = new StringBuilder();
Set<String> tables = new HashSet<String>();
StringBuilder errors = new StringBuilder();
private Deque<Container> stack = new ArrayDeque<Container>();
public Results() {
Results() {
stack.push(new Container.Table());
}
public void addValue(String key, Object value) {
void addValue(String key, Object value) {
Container currentTable = stack.peek();
if (currentTable.accepts(key)) {
currentTable.put(key, value);
@ -24,7 +24,7 @@ class Results {
}
}
public void startTableArray(String tableName) {
void startTableArray(String tableName) {
while (stack.size() > 1) {
stack.pop();
}
@ -62,7 +62,7 @@ class Results {
}
}
public void startTables(String tableName) {
void startTables(String tableName) {
if (!tables.add(tableName)) {
errors.append("Table " + tableName + " defined twice!\n");
}
@ -95,7 +95,7 @@ class Results {
/**
* Warning: After this method has been called, this instance is no longer usable.
*/
public Map<String, Object> consume() {
Map<String, Object> consume() {
Container values = stack.getLast();
stack.clear();

View file

@ -7,7 +7,7 @@ import org.parboiled.BaseParser;
import org.parboiled.Rule;
import org.parboiled.annotations.SuppressNode;
public class StatementParser extends BaseParser<List<Object>> {
class StatementParser extends BaseParser<List<Object>> {
public Rule Array() {
return FirstOf(EmptyArray(), Sequence('[', startList(), OneOrMore(FirstOf(NonEmptyArray(), ' ', ',')), ']', endList()));

View file

@ -1,7 +1,7 @@
package com.moandjiezana.toml.values;
package com.moandjiezana.toml;
import static com.moandjiezana.toml.values.ValueConverter.INVALID;
import static com.moandjiezana.toml.values.ValueParserUtils.isComment;
import static com.moandjiezana.toml.ValueParserUtils.INVALID;
import static com.moandjiezana.toml.ValueParserUtils.isComment;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

View file

@ -1,6 +1,6 @@
package com.moandjiezana.toml;
import static com.moandjiezana.toml.values.ValueConverter.INVALID;
import static com.moandjiezana.toml.ValueParserUtils.INVALID;
import java.util.List;
import java.util.regex.Pattern;
@ -9,16 +9,14 @@ import org.parboiled.Parboiled;
import org.parboiled.parserunners.BasicParseRunner;
import org.parboiled.support.ParsingResult;
import com.moandjiezana.toml.values.ValueConverter;
public class TomlParser {
class TomlParser {
private static final Pattern MULTILINE_ARRAY_REGEX = Pattern.compile("\\s*\\[([^\\]]*)");
private static final Pattern MULTILINE_ARRAY_REGEX_END = Pattern.compile("\\s*\\]");
private static final ValueConverter VALUE_ANALYSIS = new ValueConverter();
private final Results results = new Results();
public Results run(String tomlString) {
Results run(String tomlString) {
if (tomlString.isEmpty()) {
return results;
}

View file

@ -1,14 +1,14 @@
package com.moandjiezana.toml.values;
package com.moandjiezana.toml;
import static com.moandjiezana.toml.values.ArrayParser.ARRAY_PARSER;
import static com.moandjiezana.toml.values.BooleanParser.BOOLEAN_PARSER;
import static com.moandjiezana.toml.values.DateParser.DATE_PARSER;
import static com.moandjiezana.toml.values.FloatParser.FLOAT_PARSER;
import static com.moandjiezana.toml.values.IntegerParser.INTEGER_PARSER;
import static com.moandjiezana.toml.values.StringParser.STRING_PARSER;
import static com.moandjiezana.toml.ArrayParser.ARRAY_PARSER;
import static com.moandjiezana.toml.BooleanParser.BOOLEAN_PARSER;
import static com.moandjiezana.toml.DateParser.DATE_PARSER;
import static com.moandjiezana.toml.FloatParser.FLOAT_PARSER;
import static com.moandjiezana.toml.IntegerParser.INTEGER_PARSER;
import static com.moandjiezana.toml.StringParser.STRING_PARSER;
import static com.moandjiezana.toml.ValueParserUtils.INVALID;
public class ValueConverter {
public static final Object INVALID = new Object();
class ValueConverter {
public Object convert(String value) {
if (STRING_PARSER.canParse(value)) {

View file

@ -0,0 +1,7 @@
package com.moandjiezana.toml;
interface ValueParser {
boolean canParse(String s);
Object parse(String s);
}

View file

@ -1,6 +1,7 @@
package com.moandjiezana.toml.values;
package com.moandjiezana.toml;
class ValueParserUtils {
static final Object INVALID = new Object();
static boolean isComment(String line) {
if (line == null || line.isEmpty()) {

View file

@ -1,7 +0,0 @@
package com.moandjiezana.toml.values;
public interface ValueParser {
boolean canParse(String s);
Object parse(String s);
}