Browse Source

PropertyLoader: Resolve references in more places

pull/336/head
Jannis Weis 2 years ago
parent
commit
aeb63935c2
No known key found for this signature in database
GPG Key ID: 7C9D8D4B558049AB
  1. 7
      property-loader/src/main/java/com/github/weisj/darklaf/properties/parser/IconParser.java
  2. 29
      property-loader/src/main/java/com/github/weisj/darklaf/properties/parser/Parser.java

7
property-loader/src/main/java/com/github/weisj/darklaf/properties/parser/IconParser.java

@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2021 Jannis Weis
* Copyright (c) 2021-2023 Jannis Weis
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
@ -54,7 +54,8 @@ public class IconParser extends KeyFilteredParser implements Delimiters {
Dimension dim = new Dimension(-1, -1);
if (parseResult.value.endsWith(String.valueOf(ARG_END))) {
List<Integer> dimensions = ParserUtil.parseDelimited(ARG_START, ARG_END, ARG_SEPARATOR, false,
PropertyParser.of(Integer::parseInt), Integer.class, parseResult, context);
Parser.PREPROCESSOR.andThen(PropertyParser.of(Integer::parseInt)),
Integer.class, parseResult, context);
if (dimensions.size() != 2) return ParserUtil.error(parseResult, "Invalid dimension.");
dim.width = dimensions.get(0);
dim.height = dimensions.get(1);
@ -63,7 +64,7 @@ public class IconParser extends KeyFilteredParser implements Delimiters {
List<String> modifiers;
if (parseResult.value.endsWith(String.valueOf(MODIFIER_END))) {
modifiers = ParserUtil.parseDelimited(MODIFIER_START, MODIFIER_END, MODIFIER_DELIMITER, false,
PropertyParser.of(s -> s), String.class, parseResult, context);
Parser.PREPROCESSOR.andThen(PropertyParser.of(s -> s)), String.class, parseResult, context);
} else {
modifiers = Collections.emptyList();

29
property-loader/src/main/java/com/github/weisj/darklaf/properties/parser/Parser.java

@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2019-2021 Jannis Weis
* Copyright (c) 2019-2023 Jannis Weis
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
@ -28,10 +28,12 @@ public final class Parser {
public static final Object EMPTY_VALUE = new Object();
private static final List<PropertyParser> preprocessorSteps = Arrays.asList(
new FallbackParser(),
new ReferenceParser());
static final PropertyParser PREPROCESSOR = Parser::applyPreprocessors;
private static final List<PropertyParser> steps = Arrays.asList(
new NullParser(),
new FallbackParser(),
new ReferenceParser(),
new PrimitiveParser(),
new InsetParser(),
new LazyObjectParser(),
@ -52,13 +54,28 @@ public final class Parser {
return debugMode;
}
public static ParseResult parse(final ParseResult parseResult, final ParserContext context) {
private static ParseResult applySteps(final ParseResult parseResult,
final ParserContext context,
final List<PropertyParser> parsers) {
ParseResult p = parseResult;
String savedValue = parseResult.value;
for (PropertyParser step : steps) {
for (PropertyParser step : parsers) {
if (p.finished) return p;
p = step.parse(p, context);
}
return p;
}
public static ParseResult applyPreprocessors(final ParseResult parseResult, final ParserContext context) {
return applySteps(parseResult, context, preprocessorSteps);
}
public static ParseResult parse(final ParseResult parseResult, final ParserContext context) {
ParseResult p = parseResult;
String savedValue = parseResult.value;
p = applyPreprocessors(p, context);
if (p.finished) return p;
p = applySteps(p, context, steps);
if (!p.finished) {
for (String warning : p.warnings) {
ParserUtil.warning(warning);

Loading…
Cancel
Save