2014-08-12 15:38:23 +00:00
|
|
|
package com.moandjiezana.toml;
|
|
|
|
|
|
|
|
import static com.moandjiezana.toml.ValueParserUtils.INVALID;
|
2014-08-12 14:44:47 +00:00
|
|
|
|
2014-08-13 12:27:23 +00:00
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.parboiled.Parboiled;
|
|
|
|
import org.parboiled.parserunners.BasicParseRunner;
|
|
|
|
|
2014-08-12 14:44:47 +00:00
|
|
|
class BooleanParser implements ValueParser {
|
|
|
|
|
|
|
|
static final BooleanParser BOOLEAN_PARSER = new BooleanParser();
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canParse(String s) {
|
|
|
|
return s.startsWith("true") || s.startsWith("false");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object parse(String s) {
|
2014-08-13 12:27:23 +00:00
|
|
|
StatementParser parser = Parboiled.createParser(StatementParser.class);
|
|
|
|
|
|
|
|
List<String> resultValue = new BasicParseRunner<List<String>>(parser.Boolean()).run(s).resultValue;
|
|
|
|
|
|
|
|
if (resultValue == null) {
|
2014-08-12 15:38:23 +00:00
|
|
|
return INVALID;
|
2014-08-12 14:44:47 +00:00
|
|
|
}
|
|
|
|
|
2014-08-13 12:27:23 +00:00
|
|
|
return Boolean.valueOf(resultValue.get(0));
|
2014-08-12 14:44:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private BooleanParser() {}
|
|
|
|
}
|