1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-10 12:12:27 +00:00
plantuml/src/net/sourceforge/plantuml/tim/EaterFunctionCall.java

141 lines
4.4 KiB
Java
Raw Normal View History

2019-03-29 22:14:07 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2023-02-22 18:43:48 +00:00
* (C) Copyright 2009-2024, Arnaud Roques
2019-03-29 22:14:07 +00:00
*
2023-02-22 18:43:48 +00:00
* Project Info: https://plantuml.com
2019-03-29 22:14:07 +00:00
*
* If you like this project or if you find it useful, you can support us at:
*
2023-02-22 18:43:48 +00:00
* https://plantuml.com/patreon (only 1$ per month!)
* https://plantuml.com/paypal
2019-03-29 22:14:07 +00:00
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*
* Original Author: Arnaud Roques
*
*/
package net.sourceforge.plantuml.tim;
import java.util.ArrayList;
import java.util.Collections;
2020-05-17 21:15:50 +00:00
import java.util.HashMap;
2019-03-29 22:14:07 +00:00
import java.util.List;
2020-05-17 21:15:50 +00:00
import java.util.Map;
2019-03-29 22:14:07 +00:00
2023-02-02 17:59:43 +00:00
import net.sourceforge.plantuml.text.StringLocated;
2019-03-29 22:14:07 +00:00
import net.sourceforge.plantuml.tim.expression.TValue;
import net.sourceforge.plantuml.tim.expression.TokenStack;
public class EaterFunctionCall extends Eater {
2021-05-14 08:42:57 +00:00
private final List<TValue> values = new ArrayList<>();
2020-05-17 21:15:50 +00:00
private final Map<String, TValue> namedArguments = new HashMap<String, TValue>();
2019-03-29 22:14:07 +00:00
private final boolean isLegacyDefine;
private final boolean unquoted;
2020-03-03 22:29:34 +00:00
public EaterFunctionCall(StringLocated s, boolean isLegacyDefine, boolean unquoted) {
2019-03-29 22:14:07 +00:00
super(s);
this.isLegacyDefine = isLegacyDefine;
this.unquoted = unquoted;
}
@Override
2020-03-03 22:29:34 +00:00
public void analyze(TContext context, TMemory memory) throws EaterException, EaterExceptionLocated {
2019-03-29 22:14:07 +00:00
skipUntilChar('(');
checkAndEatChar('(');
skipSpaces();
if (peekChar() == ')') {
2019-04-21 20:40:01 +00:00
checkAndEatChar(')');
2019-03-29 22:14:07 +00:00
return;
}
while (true) {
skipSpaces();
2020-05-17 21:15:50 +00:00
if (isLegacyDefine) {
final String read = eatAndGetOptionalQuotedString();
final String value = context.applyFunctionsAndVariables(memory,
new StringLocated(read, getLineLocation()));
2020-05-17 21:15:50 +00:00
final TValue result = TValue.fromString(value);
2019-03-29 22:14:07 +00:00
values.add(result);
2020-05-17 21:15:50 +00:00
} else if (unquoted) {
2021-01-10 20:52:19 +00:00
if (matchAffectation()) {
final String varname = eatAndGetVarname();
skipSpaces();
checkAndEatChar('=');
skipSpaces();
final String read = eatAndGetOptionalQuotedString();
final String value = context.applyFunctionsAndVariables(memory,
new StringLocated(read, getLineLocation()));
2021-01-10 20:52:19 +00:00
final TValue result = TValue.fromString(value);
namedArguments.put(varname, result);
2020-05-17 21:15:50 +00:00
} else {
2021-01-10 20:52:19 +00:00
final String read = eatAndGetOptionalQuotedString();
final String value = context.applyFunctionsAndVariables(memory,
new StringLocated(read, getLineLocation()));
2020-05-17 21:15:50 +00:00
final TValue result = TValue.fromString(value);
values.add(result);
}
2021-01-10 20:52:19 +00:00
// }
2019-03-29 22:14:07 +00:00
} else {
2021-01-10 20:52:19 +00:00
if (matchAffectation()) {
final String varname = eatAndGetVarname();
skipSpaces();
checkAndEatChar('=');
skipSpaces();
final TokenStack tokens = TokenStack.eatUntilCloseParenthesisOrComma(this).withoutSpace();
tokens.guessFunctions();
final TValue result = tokens.getResult(getStringLocated(), context, memory);
2021-01-10 20:52:19 +00:00
namedArguments.put(varname, result);
2020-05-17 21:15:50 +00:00
} else {
2021-01-10 20:52:19 +00:00
final TokenStack tokens = TokenStack.eatUntilCloseParenthesisOrComma(this).withoutSpace();
2020-05-17 21:15:50 +00:00
tokens.guessFunctions();
final TValue result = tokens.getResult(getStringLocated(), context, memory);
2020-05-17 21:15:50 +00:00
values.add(result);
}
2019-03-29 22:14:07 +00:00
}
skipSpaces();
final char ch = eatOneChar();
if (ch == ',') {
continue;
}
if (ch == ')') {
break;
}
2020-12-01 21:39:27 +00:00
if (unquoted) {
throw EaterException.located("unquoted function/procedure cannot use expression.");
}
2020-05-17 21:15:50 +00:00
throw EaterException.located("call001");
2019-03-29 22:14:07 +00:00
}
}
2019-05-24 19:59:31 +00:00
public final List<TValue> getValues() {
2019-03-29 22:14:07 +00:00
return Collections.unmodifiableList(values);
}
2020-05-17 21:15:50 +00:00
public final Map<String, TValue> getNamedArguments() {
return Collections.unmodifiableMap(namedArguments);
}
2019-09-14 18:12:04 +00:00
public final String getEndOfLine() throws EaterException {
return this.eatAllToEnd();
}
2019-03-29 22:14:07 +00:00
}