use of org.gradle.language.nativeplatform.internal.Expression in project gradle by gradle.
the class RegexBackedCSourceParser method parseExpression.
/**
* Parses an expression that forms the body of a directive or a macro function parameter:
*
* - A path or string
* - An argument list, ie zero or more expressions delimited by '(' and ')'
* - An identifier
* - Token concatenation
* - A macro function call
* - Any single character that does not delimit function arguments
*
* Returns null when an expression cannot be parsed and consumes input up to the parse failure point.
*/
@Nullable
private static Expression parseExpression(Buffer buffer) {
buffer.consumeWhitespace();
if (!buffer.hasAny()) {
// Empty or only whitespace
return null;
}
Expression expression = readPathExpression(buffer);
if (expression != null) {
// A path, either "" or <> delimited
return expression;
}
// A sequence of tokens that look like a function call argument list. Should support an arbitrary token sequence
List<Expression> arguments = readArgumentList(buffer);
if (arguments != null) {
if (arguments.isEmpty()) {
return SimpleExpression.EMPTY_ARGS;
} else {
return new ComplexExpression(IncludeType.ARGS_LIST, null, arguments);
}
}
String identifier = buffer.readIdentifier();
if (identifier == null) {
// No identifier, allow anything except '(' or ',' or ')'
String token = buffer.readAnyExcept("(),");
if (token != null) {
return new SimpleExpression(token, IncludeType.TOKEN);
}
return null;
}
// Either a macro function, a macro or token concatenation
buffer.consumeWhitespace();
arguments = readArgumentList(buffer);
if (arguments != null) {
// A macro function call
if (arguments.isEmpty()) {
return new SimpleExpression(identifier, IncludeType.MACRO_FUNCTION);
} else {
return new ComplexExpression(IncludeType.MACRO_FUNCTION, identifier, arguments);
}
}
expression = readTokenConcatenation(buffer, identifier);
if (expression != null) {
return expression;
}
// Just an identifier, this is a token
return new SimpleExpression(identifier, IncludeType.IDENTIFIER);
}
use of org.gradle.language.nativeplatform.internal.Expression in project gradle by gradle.
the class RegexBackedCSourceParser method parseMacroObjectDirectiveBody.
/**
* Parse an "object-like" macro directive body. Consumes all input.
*/
private void parseMacroObjectDirectiveBody(Buffer buffer, String macroName, Collection<Macro> macros) {
Expression expression = parseDirectiveBodyExpression(buffer);
expression = expression.asMacroExpansion();
if (!expression.getArguments().isEmpty()) {
// Body is an expression with one or more arguments
macros.add(new MacroWithComplexExpression(macroName, expression.getType(), expression.getValue(), expression.getArguments()));
} else if (expression.getType() != IncludeType.OTHER) {
// Body is a simple expression, including a macro function call with no arguments
macros.add(new MacroWithSimpleExpression(macroName, expression.getType(), expression.getValue()));
} else {
// Discard the body when the expression is not resolvable
macros.add(new UnresolveableMacro(macroName));
}
}
use of org.gradle.language.nativeplatform.internal.Expression in project gradle by gradle.
the class RegexBackedCSourceParser method consumeArgumentList.
/**
* Parses a macro function argument list. Stops when unable to recognize any further arguments.
*/
private static void consumeArgumentList(Buffer buffer, List<Expression> expressions) {
Expression expression = readArgument(buffer);
if (expression == null) {
if (!buffer.has(',')) {
// No args
return;
}
expression = SimpleExpression.EMPTY_EXPRESSIONS;
}
expressions.add(expression);
while (true) {
buffer.consumeWhitespace();
if (!buffer.consume(',')) {
return;
}
expression = readArgument(buffer);
if (expression == null) {
expression = SimpleExpression.EMPTY_EXPRESSIONS;
}
expressions.add(expression);
}
}
Aggregations