use of net.coderbot.iris.shaderpack.parsing.ParsedString in project Iris by IrisShaders.
the class OptionAnnotatedSource method parseDefineOption.
private static void parseDefineOption(AnnotationsBuilder builder, int index, ParsedString line) {
// Remove the leading comment for processing.
boolean hasLeadingComment = line.takeComments();
// allow but do not require whitespace between comments and #define
line.takeSomeWhitespace();
if (!line.takeLiteral("#define")) {
builder.diagnostics.put(index, "This line contains an occurrence of \"#define\" " + "but it wasn't in a place we expected, ignoring it.");
return;
}
if (!line.takeSomeWhitespace()) {
builder.diagnostics.put(index, "This line properly starts with a #define statement but doesn't have " + "any whitespace characters after the #define.");
return;
}
String name = line.takeWord();
if (name == null) {
builder.diagnostics.put(index, "Invalid syntax after #define directive. " + "No alphanumeric or underscore characters detected.");
return;
}
// Maybe take some whitespace
boolean tookWhitespace = line.takeSomeWhitespace();
if (line.isEnd()) {
// Plain define directive without a comment.
builder.booleanOptions.put(index, new BooleanOption(OptionType.DEFINE, name, null, !hasLeadingComment));
return;
}
if (line.takeComments()) {
// Note that this is a bare comment, we don't need to look for the allowed values part.
// Obviously that part isn't necessary since boolean options only have two possible
// values (true and false)
String comment = line.takeRest().trim();
builder.booleanOptions.put(index, new BooleanOption(OptionType.DEFINE, name, comment, !hasLeadingComment));
return;
} else if (!tookWhitespace) {
// Invalid syntax.
builder.diagnostics.put(index, "Invalid syntax after #define directive. Only alphanumeric or underscore " + "characters are allowed in option names.");
return;
}
if (hasLeadingComment) {
builder.diagnostics.put(index, "Ignoring potential non-boolean #define option since it has a leading comment. " + "Leading comments (//) are only allowed on boolean #define options.");
return;
}
String value = line.takeWordOrNumber();
if (value == null) {
builder.diagnostics.put(index, "Ignoring this #define directive because it doesn't appear to be a boolean #define, " + "and its potential value wasn't a valid number or a valid word.");
return;
}
tookWhitespace = line.takeSomeWhitespace();
if (line.isEnd()) {
builder.diagnostics.put(index, "Ignoring this #define because it doesn't have a comment containing" + " a list of allowed values afterwards, but it has a value so is therefore not a boolean.");
return;
} else if (!tookWhitespace) {
builder.diagnostics.put(index, "Invalid syntax after value #define directive. " + "Invalid characters after number or word.");
return;
}
if (!line.takeComments()) {
builder.diagnostics.put(index, "Invalid syntax after value #define directive. " + "Only comments may come after the value.");
return;
}
String comment = line.takeRest().trim();
StringOption option = StringOption.create(OptionType.DEFINE, name, comment, value);
if (option == null) {
builder.diagnostics.put(index, "Ignoring this #define because it is missing an allowed values list" + "in a comment, but is not a boolean define.");
return;
}
builder.stringOptions.put(index, option);
/*
//#define SHADOWS // Whether shadows are enabled
SHADOWS // Whether shadows are enabled
// Whether shadows are enabled
Whether shadows are enabled
#define OPTION 0.5 // A test option
OPTION 0.5 // A test option
0.5 // A test option
*/
}
use of net.coderbot.iris.shaderpack.parsing.ParsedString in project Iris by IrisShaders.
the class OptionAnnotatedSource method removeLeadingComment.
private static String removeLeadingComment(String line) {
ParsedString parsed = new ParsedString(line);
parsed.takeSomeWhitespace();
parsed.takeComments();
return parsed.takeRest();
}
use of net.coderbot.iris.shaderpack.parsing.ParsedString in project Iris by IrisShaders.
the class OptionAnnotatedSource method parseConst.
private static void parseConst(AnnotationsBuilder builder, int index, ParsedString line) {
if (!line.takeSomeWhitespace()) {
builder.diagnostics.put(index, "Expected whitespace after const and before type declaration");
return;
}
boolean isString;
if (line.takeLiteral("int") || line.takeLiteral("float")) {
isString = true;
} else if (line.takeLiteral("bool")) {
isString = false;
} else {
builder.diagnostics.put(index, "Unexpected type declaration after const. " + "Expected int, float, or bool. " + "Vector const declarations cannot be configured using shader options.");
return;
}
if (!line.takeSomeWhitespace()) {
builder.diagnostics.put(index, "Expected whitespace after type declaration.");
return;
}
String name = line.takeWord();
if (name == null) {
builder.diagnostics.put(index, "Expected name of option after type declaration, " + "but an unexpected character was detected first.");
return;
}
line.takeSomeWhitespace();
if (!line.takeLiteral("=")) {
builder.diagnostics.put(index, "Unexpected characters before equals sign in const declaration.");
return;
}
line.takeSomeWhitespace();
String value = line.takeWordOrNumber();
if (value == null) {
builder.diagnostics.put(index, "Unexpected non-whitespace characters after equals sign");
return;
}
line.takeSomeWhitespace();
if (!line.takeLiteral(";")) {
builder.diagnostics.put(index, "Value between the equals sign and the semicolon wasn't parsed as a valid word or number.");
return;
}
line.takeSomeWhitespace();
String comment;
if (line.takeComments()) {
comment = line.takeRest().trim();
} else if (!line.isEnd()) {
builder.diagnostics.put(index, "Unexpected non-whitespace characters outside of comment after semicolon");
return;
} else {
comment = null;
}
if (!isString) {
boolean booleanValue;
if ("true".equals(value)) {
booleanValue = true;
} else if ("false".equals(value)) {
booleanValue = false;
} else {
builder.diagnostics.put(index, "Expected true or false as the value of a boolean const option, but got " + value + ".");
return;
}
if (!VALID_CONST_OPTION_NAMES.contains(name)) {
builder.diagnostics.put(index, "This was a valid const boolean option declaration, but " + name + " was not recognized as being a name of one of the configurable const options.");
return;
}
builder.booleanOptions.put(index, new BooleanOption(OptionType.CONST, name, comment, booleanValue));
return;
}
if (!VALID_CONST_OPTION_NAMES.contains(name)) {
builder.diagnostics.put(index, "This was a valid const option declaration, but " + name + " was not recognized as being a name of one of the configurable const options.");
return;
}
StringOption option = StringOption.create(OptionType.CONST, name, comment, value);
if (option != null) {
builder.stringOptions.put(index, option);
} else {
builder.diagnostics.put(index, "Ignoring this const option because it is missing an allowed values list" + "in a comment, but is not a boolean const option.");
}
}
use of net.coderbot.iris.shaderpack.parsing.ParsedString in project Iris by IrisShaders.
the class OptionAnnotatedSource method parseIfdef.
private static void parseIfdef(AnnotationsBuilder builder, int index, ParsedString line) {
if (!line.takeSomeWhitespace()) {
return;
}
String name = line.takeWord();
line.takeSomeWhitespace();
if (name == null || !line.isEnd()) {
return;
}
builder.booleanDefineReferences.computeIfAbsent(name, n -> new IntArrayList()).add(index);
}
Aggregations