1
0
mirror of https://github.com/octoleo/plantuml.git synced 2025-01-08 17:24:15 +00:00
This commit is contained in:
Arnaud Roques 2022-11-08 19:45:10 +01:00
parent fce894d4e1
commit ac0ccd1af2
22 changed files with 196 additions and 207 deletions

View File

@ -139,6 +139,10 @@ public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy,
this.stacks2.add(Ident.empty()); this.stacks2.add(Ident.empty());
} }
final public String getPortFor(String ent1String, Ident ident1) {
return null;
}
private Ident getLastID() { private Ident getLastID() {
if (stacks2.size() == 0) { if (stacks2.size() == 0) {
// Thread.dumpStack(); // Thread.dumpStack();

View File

@ -179,8 +179,8 @@ final public class CommandLinkClass extends SingleLineCommand2<AbstractClassOrOb
return executePackageLink(diagram, arg); return executePackageLink(diagram, arg);
} }
String port1 = null; String port1 = diagram.getPortFor(ent1String, ident1);
String port2 = null; String port2 = diagram.getPortFor(ent2String, ident2);
if (diagram.V1972()) { if (diagram.V1972()) {
if ("::".equals(diagram.getNamespaceSeparator())) { if ("::".equals(diagram.getNamespaceSeparator())) {
@ -207,12 +207,12 @@ final public class CommandLinkClass extends SingleLineCommand2<AbstractClassOrOb
} }
} }
} else { } else {
if (removeMemberPartLegacy1972(diagram, ident1) != null) { if (port1 == null && removeMemberPartLegacy1972(diagram, ident1) != null) {
port1 = ident1.getPortMember(); port1 = ident1.getPortMember();
code1 = removeMemberPartLegacy1972(diagram, ident1); code1 = removeMemberPartLegacy1972(diagram, ident1);
ident1 = ident1.removeMemberPart(); ident1 = ident1.removeMemberPart();
} }
if (removeMemberPartLegacy1972(diagram, ident2) != null) { if (port2 == null && removeMemberPartLegacy1972(diagram, ident2) != null) {
port2 = ident2.getPortMember(); port2 = ident2.getPortMember();
code2 = removeMemberPartLegacy1972(diagram, ident2); code2 = removeMemberPartLegacy1972(diagram, ident2);
ident2 = ident2.removeMemberPart(); ident2 = ident2.removeMemberPart();

View File

@ -65,18 +65,17 @@ public class DedicationCrypted implements Dedication {
public synchronized BufferedImage getImage(final TinyHashableString sentence) { public synchronized BufferedImage getImage(final TinyHashableString sentence) {
final String line = sentence.getSentence(); final String line = sentence.getSentence();
if (line.length() < 40) { if (line.length() < 40)
return null; return null;
}
try { try {
if (solution == null || line.equals(this.solution) == false) { if (solution == null || line.equals(this.solution) == false) {
if (System.currentTimeMillis() < next) { if (System.currentTimeMillis() < next)
return null; return null;
}
if (this.tinyHash != sentence.tinyHash()) { if (this.tinyHash != sentence.tinyHash())
return null; return null;
}
this.next = System.currentTimeMillis() + 5000L; this.next = System.currentTimeMillis() + 5000L;
} }
@ -105,9 +104,9 @@ public class DedicationCrypted implements Dedication {
final String argon = Noise.computeArgon2String(current, (pq.toString(34) + line).getBytes(UTF_8)); final String argon = Noise.computeArgon2String(current, (pq.toString(34) + line).getBytes(UTF_8));
if (this.argon2.equals(argon) == false) { if (this.argon2.equals(argon) == false)
return null; return null;
}
Noise.shuffle(current, rndMT); Noise.shuffle(current, rndMT);
current = Noise.reverse(current, rndMT.nextInt()); current = Noise.reverse(current, rndMT.nextInt());

View File

@ -52,9 +52,8 @@ public class DedicationSimple implements Dedication {
} }
public synchronized BufferedImage getImage(TinyHashableString sentence) { public synchronized BufferedImage getImage(TinyHashableString sentence) {
if (same(this.sentence, sentence.getSentence()) == false) { if (same(this.sentence, sentence.getSentence()) == false)
return null; return null;
}
try { try {
byte[] current = crypted.clone(); byte[] current = crypted.clone();

View File

@ -58,6 +58,7 @@ public class Dedications {
all.add(new DedicationSimple(load("boundaries"), "Boundaries allow discipline to create true strength")); all.add(new DedicationSimple(load("boundaries"), "Boundaries allow discipline to create true strength"));
all.add(new DedicationSimple(load("dr_chet"), "Thank you, Dr. Chet. I wouldn't be where I am without you")); all.add(new DedicationSimple(load("dr_chet"), "Thank you, Dr. Chet. I wouldn't be where I am without you"));
all.add(new DedicationSimple(load("ben"), "Ben and Jen 2020")); all.add(new DedicationSimple(load("ben"), "Ben and Jen 2020"));
all.add(new DedicationSimple(load("baraye"), "baraye"));
all.add(secret(5, "835ff5d643b58cd35a20db6480071d05751aa6a0e01da78662ceafd0161f3f5e", new BigInteger( all.add(secret(5, "835ff5d643b58cd35a20db6480071d05751aa6a0e01da78662ceafd0161f3f5e", new BigInteger(
"1182423723677118831606503500858825217076578422970565964857326298418401529955036896808663335300684244453386039908536275400945824932191521017102701344437753036730900076162922741167523337650578479960119614237031234925702200473053235777"))); "1182423723677118831606503500858825217076578422970565964857326298418401529955036896808663335300684244453386039908536275400945824932191521017102701344437753036730900076162922741167523337650578479960119614237031234925702200473053235777")));
all.add(secret(3, "514816d583044efbd336882227deb822194ff63e3bdc3cf707a01f17770d5a6a", new BigInteger( all.add(secret(3, "514816d583044efbd336882227deb822194ff63e3bdc3cf707a01f17770d5a6a", new BigInteger(
@ -87,9 +88,8 @@ public class Dedications {
final TinyHashableString sentence = new TinyHashableString(line); final TinyHashableString sentence = new TinyHashableString(line);
for (Dedication dedication : all) { for (Dedication dedication : all) {
final BufferedImage image = dedication.getImage(sentence); final BufferedImage image = dedication.getImage(sentence);
if (image != null) { if (image != null)
return image; return image;
}
} }
return null; return null;
} }

View File

@ -85,9 +85,9 @@ public class Noise {
} }
public static void xor(byte[] buffer, byte[] xor) { public static void xor(byte[] buffer, byte[] xor) {
for (int i = 0; i < buffer.length; i++) { for (int i = 0; i < buffer.length; i++)
buffer[i] ^= xor[i % xor.length]; buffer[i] ^= xor[i % xor.length];
}
} }
public static void xor(byte[] buffer, BlumBlumShub rnd) { public static void xor(byte[] buffer, BlumBlumShub rnd) {
@ -105,10 +105,4 @@ public class Noise {
return result; return result;
} }
} }

View File

@ -46,9 +46,9 @@ public class PSystemDedicationFactory extends PSystemSingleLineFactory {
@Override @Override
protected AbstractPSystem executeLine(UmlSource source, String line) { protected AbstractPSystem executeLine(UmlSource source, String line) {
final BufferedImage dedication = Dedications.get(line); final BufferedImage dedication = Dedications.get(line);
if (dedication != null) { if (dedication != null)
return new PSystemDedication(source, dedication); return new PSystemDedication(source, dedication);
}
return null; return null;
} }

View File

@ -49,9 +49,9 @@ public class QBlock {
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
final int read = source.read(); final int read = source.read();
if (read == -1) { if (read == -1) {
if (i == 0) { if (i == 0)
return null; return null;
}
break; break;
} }
block[i + 1] = (byte) read; block[i + 1] = (byte) read;
@ -77,15 +77,15 @@ public class QBlock {
public byte[] getData512() { public byte[] getData512() {
final byte[] nb = big.toByteArray(); final byte[] nb = big.toByteArray();
if (nb.length == 512) { if (nb.length == 512)
return nb; return nb;
}
final byte[] result = new byte[512]; final byte[] result = new byte[512];
if (nb.length < 512) { if (nb.length < 512)
System.arraycopy(nb, 0, result, 512 - nb.length, nb.length); System.arraycopy(nb, 0, result, 512 - nb.length, nb.length);
} else { else
System.arraycopy(nb, nb.length - 512, result, 0, 512); System.arraycopy(nb, nb.length - 512, result, 0, 512);
}
return result; return result;
} }
@ -101,11 +101,10 @@ public class QBlock {
public void write(OutputStream os, int size) throws IOException { public void write(OutputStream os, int size) throws IOException {
final byte[] data = big.toByteArray(); final byte[] data = big.toByteArray();
final int start = data.length - size; final int start = data.length - size;
if (start < 0) { if (start < 0)
for (int i = 0; i < -start; i++) { for (int i = 0; i < -start; i++)
os.write(0); os.write(0);
}
}
for (int i = Math.max(start, 0); i < data.length; i++) { for (int i = Math.max(start, 0); i < data.length; i++) {
int b = data[i]; int b = data[i];
os.write(b); os.write(b);

View File

@ -54,18 +54,18 @@ public class QBlocks {
final QBlocks result = new QBlocks(); final QBlocks result = new QBlocks();
while (true) { while (true) {
final QBlock block = QBlock.read(source, size); final QBlock block = QBlock.read(source, size);
if (block == null) { if (block == null)
return result; return result;
}
result.all.add(block); result.all.add(block);
} }
} }
public QBlocks change(BigInteger E, BigInteger N) { public QBlocks change(BigInteger E, BigInteger N) {
final QBlocks result = new QBlocks(); final QBlocks result = new QBlocks();
for (QBlock rsa : all) { for (QBlock rsa : all)
result.all.add(rsa.change(E, N)); result.all.add(rsa.change(E, N));
}
return result; return result;
} }

View File

@ -61,9 +61,9 @@ public class RBlock {
} }
public byte[] getData(int size) { public byte[] getData(int size) {
if (buffer.length == size) { if (buffer.length == size)
return buffer; return buffer;
}
final byte[] result = new byte[size]; final byte[] result = new byte[size];
System.arraycopy(buffer, buffer.length - size, result, 0, size); System.arraycopy(buffer, buffer.length - size, result, 0, size);
return result; return result;

View File

@ -75,9 +75,9 @@ public class RBlocks {
public RBlocks change(BigInteger E, BigInteger N) { public RBlocks change(BigInteger E, BigInteger N) {
final RBlocks result = new RBlocks(); final RBlocks result = new RBlocks();
for (RBlock rsa : all) { for (RBlock rsa : all)
result.all.add(rsa.change(E, N)); result.all.add(rsa.change(E, N));
}
return result; return result;
} }

View File

@ -51,9 +51,9 @@ public final class TinyHashableString {
} }
public synchronized int tinyHash() { public synchronized int tinyHash() {
if (cachedTinyHash == -1) { if (cachedTinyHash == -1)
cachedTinyHash = Noise.shortHash(sentence.getBytes(UTF_8), Dedication.N.toByteArray()); cachedTinyHash = Noise.shortHash(sentence.getBytes(UTF_8), Dedication.N.toByteArray());
}
return cachedTinyHash; return cachedTinyHash;
} }

View File

@ -45,14 +45,14 @@ public class TurningBytes {
} }
public byte nextByte() { public byte nextByte() {
if (key.length == 0) { if (key.length == 0)
return 0; return 0;
}
final byte result = key[idx]; final byte result = key[idx];
idx++; idx++;
if (idx >= key.length) { if (idx >= key.length)
idx = 0; idx = 0;
}
return result; return result;
} }

Binary file not shown.

View File

@ -92,15 +92,15 @@ public class CommandCreateEntityObjectMultilines extends CommandMultilines2<Abst
lines = lines.trim().removeEmptyLines(); lines = lines.trim().removeEmptyLines();
final RegexResult line0 = getStartingPattern().matcher(lines.getFirst().getTrimmed().getString()); final RegexResult line0 = getStartingPattern().matcher(lines.getFirst().getTrimmed().getString());
final IEntity entity = executeArg0(diagram, line0); final IEntity entity = executeArg0(diagram, line0);
if (entity == null) { if (entity == null)
return CommandExecutionResult.error("No such entity"); return CommandExecutionResult.error("No such entity");
}
lines = lines.subExtract(1, 1); lines = lines.subExtract(1, 1);
for (StringLocated s : lines) { for (StringLocated s : lines) {
assert s.getString().length() > 0; assert s.getString().length() > 0;
if (VisibilityModifier.isVisibilityCharacter(s.getString())) { if (VisibilityModifier.isVisibilityCharacter(s.getString()))
diagram.setVisibilityModifierPresent(true); diagram.setVisibilityModifierPresent(true);
}
entity.getBodier().addFieldOrMethod(s.getString()); entity.getBodier().addFieldOrMethod(s.getString());
} }
return CommandExecutionResult.ok(); return CommandExecutionResult.ok();
@ -113,9 +113,9 @@ public class CommandCreateEntityObjectMultilines extends CommandMultilines2<Abst
final String display = line0.get("NAME", 0); final String display = line0.get("NAME", 0);
final String stereotype = line0.get("STEREO", 0); final String stereotype = line0.get("STEREO", 0);
final boolean leafExist = diagram.V1972() ? diagram.leafExistSmart(ident) : diagram.leafExist(code); final boolean leafExist = diagram.V1972() ? diagram.leafExistSmart(ident) : diagram.leafExist(code);
if (leafExist) { if (leafExist)
return diagram.getOrCreateLeaf(diagram.buildLeafIdent(name), code, LeafType.OBJECT, null); return diagram.getOrCreateLeaf(diagram.buildLeafIdent(name), code, LeafType.OBJECT, null);
}
final IEntity entity = diagram.createLeaf(ident, code, Display.getWithNewlines(display), LeafType.OBJECT, null); final IEntity entity = diagram.createLeaf(ident, code, Display.getWithNewlines(display), LeafType.OBJECT, null);
if (stereotype != null) { if (stereotype != null) {
entity.setStereotype(Stereotype.build(stereotype, diagram.getSkinParam().getCircledCharacterRadius(), entity.setStereotype(Stereotype.build(stereotype, diagram.getSkinParam().getCircledCharacterRadius(),
@ -123,8 +123,8 @@ public class CommandCreateEntityObjectMultilines extends CommandMultilines2<Abst
diagram.getSkinParam().getIHtmlColorSet())); diagram.getSkinParam().getIHtmlColorSet()));
} }
final String s = line0.get("COLOR", 0); final String s = line0.get("COLOR", 0);
entity.setSpecificColorTOBEREMOVED(ColorType.BACK, s == null ? null entity.setSpecificColorTOBEREMOVED(ColorType.BACK,
: diagram.getSkinParam().getIHtmlColorSet().getColor(s)); s == null ? null : diagram.getSkinParam().getIHtmlColorSet().getColor(s));
return entity; return entity;
} }

View File

@ -79,7 +79,7 @@ public abstract class Eater {
final public TValue eatExpression(TContext context, TMemory memory) throws EaterException, EaterExceptionLocated { final public TValue eatExpression(TContext context, TMemory memory) throws EaterException, EaterExceptionLocated {
if (peekChar() == '{') { if (peekChar() == '{') {
String data = eatAllToEnd(); final String data = eatAllToEnd();
// System.err.println("data=" + data); // System.err.println("data=" + data);
final JsonValue json = Json.parse(data); final JsonValue json = Json.parse(data);
// System.err.println("json=" + json); // System.err.println("json=" + json);
@ -92,9 +92,9 @@ public abstract class Eater {
final protected TokenStack eatTokenStack() throws EaterException { final protected TokenStack eatTokenStack() throws EaterException {
final TokenStack tokenStack = new TokenStack(); final TokenStack tokenStack = new TokenStack();
addIntoTokenStack(tokenStack, false); addIntoTokenStack(tokenStack, false);
if (tokenStack.size() == 0) { if (tokenStack.size() == 0)
throw EaterException.located("Missing expression"); throw EaterException.located("Missing expression");
}
return tokenStack; return tokenStack;
} }
@ -106,21 +106,23 @@ public abstract class Eater {
} }
final protected void addIntoTokenStack(TokenStack tokenStack, boolean stopAtColon) throws EaterException { final protected void addIntoTokenStack(TokenStack tokenStack, boolean stopAtColon) throws EaterException {
Token lastToken = null;
while (true) { while (true) {
final Token token = TokenType.eatOneToken(this, stopAtColon); final Token token = TokenType.eatOneToken(lastToken, this, stopAtColon);
// System.err.println("token=" + token); if (token == null)
if (token == null) {
return; return;
}
tokenStack.add(token); tokenStack.add(token);
if (token.getTokenType() != TokenType.SPACES)
lastToken = token;
} }
} }
final public String eatAndGetQuotedString() throws EaterException { final public String eatAndGetQuotedString() throws EaterException {
final char separator = peekChar(); final char separator = peekChar();
if (TLineType.isQuote(separator) == false) { if (TLineType.isQuote(separator) == false)
throw EaterException.located("quote10"); throw EaterException.located("quote10");
}
checkAndEatChar(separator); checkAndEatChar(separator);
final StringBuilder value = new StringBuilder(); final StringBuilder value = new StringBuilder();
addUpTo(separator, value); addUpTo(separator, value);
@ -130,27 +132,27 @@ public abstract class Eater {
final protected String eatAndGetOptionalQuotedString() throws EaterException { final protected String eatAndGetOptionalQuotedString() throws EaterException {
final char quote = peekChar(); final char quote = peekChar();
if (TLineType.isQuote(quote)) { if (TLineType.isQuote(quote))
return eatAndGetQuotedString(); return eatAndGetQuotedString();
}
final StringBuilder value = new StringBuilder(); final StringBuilder value = new StringBuilder();
// DEPLICATE eatUntilCloseParenthesisOrComma // DEPLICATE eatUntilCloseParenthesisOrComma
int level = 0; int level = 0;
while (true) { while (true) {
char ch = peekChar(); char ch = peekChar();
if (ch == 0) { if (ch == 0)
throw EaterException.located("until001"); throw EaterException.located("until001");
}
if (level == 0 && (ch == ',' || ch == ')')) { if (level == 0 && (ch == ',' || ch == ')'))
return value.toString().trim(); return value.toString().trim();
}
ch = eatOneChar(); ch = eatOneChar();
if (ch == '(') { if (ch == '(')
level++; level++;
} else if (ch == ')') { else if (ch == ')')
level--; level--;
}
value.append(ch); value.append(ch);
} }
@ -162,9 +164,14 @@ public abstract class Eater {
final StringBuilder result = new StringBuilder(); final StringBuilder result = new StringBuilder();
while (true) { while (true) {
final char ch = peekChar(); final char ch = peekChar();
if (ch == 0 || TLineType.isLatinDigit(ch) == false) { if (result.length() == 0 && ch == '-') {
return result.toString(); result.append(eatOneChar());
continue;
} }
if (ch == 0 || TLineType.isLatinDigit(ch) == false)
return result.toString();
result.append(eatOneChar()); result.append(eatOneChar());
} }
} }
@ -173,47 +180,47 @@ public abstract class Eater {
final StringBuilder result = new StringBuilder(); final StringBuilder result = new StringBuilder();
while (true) { while (true) {
final char ch = peekChar(); final char ch = peekChar();
if (ch == 0 || TLineType.isSpaceChar(ch) == false) { if (ch == 0 || TLineType.isSpaceChar(ch) == false)
return result.toString(); return result.toString();
}
result.append(eatOneChar()); result.append(eatOneChar());
} }
} }
final protected String eatAndGetVarname() throws EaterException { final protected String eatAndGetVarname() throws EaterException {
final StringBuilder varname = new StringBuilder("" + eatOneChar()); final StringBuilder varname = new StringBuilder("" + eatOneChar());
if (TLineType.isLetterOrUnderscoreOrDollar(varname.charAt(0)) == false) { if (TLineType.isLetterOrUnderscoreOrDollar(varname.charAt(0)) == false)
throw EaterException.located("a002"); throw EaterException.located("a002");
}
addUpToLastLetterOrUnderscoreOrDigit(varname); addUpToLastLetterOrUnderscoreOrDigit(varname);
return varname.toString(); return varname.toString();
} }
final protected String eatAndGetFunctionName() throws EaterException { final protected String eatAndGetFunctionName() throws EaterException {
final StringBuilder varname = new StringBuilder("" + eatOneChar()); final StringBuilder varname = new StringBuilder("" + eatOneChar());
if (TLineType.isLetterOrUnderscoreOrDollar(varname.charAt(0)) == false) { if (TLineType.isLetterOrUnderscoreOrDollar(varname.charAt(0)) == false)
throw EaterException.located("a003"); throw EaterException.located("a003");
}
addUpToLastLetterOrUnderscoreOrDigit(varname); addUpToLastLetterOrUnderscoreOrDigit(varname);
return varname.toString(); return varname.toString();
} }
final public void skipSpaces() { final public void skipSpaces() {
while (i < s.length() && Character.isWhitespace(s.charAt(i))) { while (i < s.length() && Character.isWhitespace(s.charAt(i)))
i++; i++;
}
} }
final protected void skipUntilChar(char ch) { final protected void skipUntilChar(char ch) {
while (i < s.length() && s.charAt(i) != ch) { while (i < s.length() && s.charAt(i) != ch)
i++; i++;
}
} }
final public char peekChar() { final public char peekChar() {
if (i >= s.length()) { if (i >= s.length())
return 0; return 0;
}
return s.charAt(i); return s.charAt(i);
} }
@ -224,9 +231,9 @@ public abstract class Eater {
} }
final public char peekCharN2() { final public char peekCharN2() {
if (i + 1 >= s.length()) { if (i + 1 >= s.length())
return 0; return 0;
}
return s.charAt(i + 1); return s.charAt(i + 1);
} }
@ -241,40 +248,40 @@ public abstract class Eater {
} }
final protected void checkAndEatChar(char ch) throws EaterException { final protected void checkAndEatChar(char ch) throws EaterException {
if (i >= s.length() || s.charAt(i) != ch) { if (i >= s.length() || s.charAt(i) != ch)
throw EaterException.located("a001"); throw EaterException.located("a001");
}
i++; i++;
} }
final protected boolean safeCheckAndEatChar(char ch) throws EaterException { final protected boolean safeCheckAndEatChar(char ch) throws EaterException {
if (i >= s.length() || s.charAt(i) != ch) { if (i >= s.length() || s.charAt(i) != ch)
return false; return false;
}
i++; i++;
return true; return true;
} }
final protected void optionallyEatChar(char ch) throws EaterException { final protected void optionallyEatChar(char ch) throws EaterException {
if (i >= s.length() || s.charAt(i) != ch) { if (i >= s.length() || s.charAt(i) != ch)
return; return;
}
assert s.charAt(i) == ch; assert s.charAt(i) == ch;
i++; i++;
} }
final protected void checkAndEatChar(String s) throws EaterException { final protected void checkAndEatChar(String s) throws EaterException {
for (int j = 0; j < s.length(); j++) { for (int j = 0; j < s.length(); j++)
checkAndEatChar(s.charAt(j)); checkAndEatChar(s.charAt(j));
}
} }
final protected void addUpToLastLetterOrUnderscoreOrDigit(StringBuilder sb) { final protected void addUpToLastLetterOrUnderscoreOrDigit(StringBuilder sb) {
while (i < s.length()) { while (i < s.length()) {
final char ch = s.charAt(i); final char ch = s.charAt(i);
if (TLineType.isLetterOrUnderscoreOrDigit(ch) == false) { if (TLineType.isLetterOrUnderscoreOrDigit(ch) == false)
return; return;
}
i++; i++;
sb.append(ch); sb.append(ch);
} }
@ -283,26 +290,14 @@ public abstract class Eater {
final protected void addUpTo(char separator, StringBuilder sb) { final protected void addUpTo(char separator, StringBuilder sb) {
while (i < s.length()) { while (i < s.length()) {
final char ch = peekChar(); final char ch = peekChar();
if (ch == separator) { if (ch == separator)
return; return;
}
i++; i++;
sb.append(ch); sb.append(ch);
} }
} }
// final protected void addUpToUnused(char separator1, char separator2,
// StringBuilder sb) {
// while (i < s.length()) {
// final char ch = peekChar();
// if (ch == separator1 || ch == separator2) {
// return;
// }
// i++;
// sb.append(ch);
// }
// }
final protected TFunctionImpl eatDeclareFunction(TContext context, TMemory memory, boolean unquoted, final protected TFunctionImpl eatDeclareFunction(TContext context, TMemory memory, boolean unquoted,
LineLocation location, boolean allowNoParenthesis, TFunctionType type) LineLocation location, boolean allowNoParenthesis, TFunctionType type)
throws EaterException, EaterExceptionLocated { throws EaterException, EaterExceptionLocated {
@ -310,9 +305,9 @@ public abstract class Eater {
final String functionName = eatAndGetFunctionName(); final String functionName = eatAndGetFunctionName();
skipSpaces(); skipSpaces();
if (safeCheckAndEatChar('(') == false) { if (safeCheckAndEatChar('(') == false) {
if (allowNoParenthesis) { if (allowNoParenthesis)
return new TFunctionImpl(functionName, args, unquoted, type); return new TFunctionImpl(functionName, args, unquoted, type);
}
throw EaterException.located("Missing opening parenthesis"); throw EaterException.located("Missing opening parenthesis");
} }
while (true) { while (true) {

View File

@ -58,9 +58,9 @@ public class Token {
} }
public TokenOperator getTokenOperator() { public TokenOperator getTokenOperator() {
if (this.tokenType != TokenType.OPERATOR) { if (this.tokenType != TokenType.OPERATOR)
throw new IllegalStateException(); throw new IllegalStateException();
}
final char ch2 = surface.length() > 1 ? surface.charAt(1) : 0; final char ch2 = surface.length() > 1 ? surface.charAt(1) : 0;
return TokenOperator.getTokenOperator(surface.charAt(0), ch2); return TokenOperator.getTokenOperator(surface.charAt(0), ch2);
} }
@ -74,16 +74,16 @@ public class Token {
} }
public Token muteToFunction() { public Token muteToFunction() {
if (this.tokenType != TokenType.PLAIN_TEXT) { if (this.tokenType != TokenType.PLAIN_TEXT)
throw new IllegalStateException(); throw new IllegalStateException();
}
return new Token(surface, TokenType.FUNCTION_NAME, null); return new Token(surface, TokenType.FUNCTION_NAME, null);
} }
public JsonValue getJson() { public JsonValue getJson() {
if (this.tokenType != TokenType.JSON_DATA) { if (this.tokenType != TokenType.JSON_DATA)
throw new IllegalStateException(); throw new IllegalStateException();
}
return json; return json;
} }

View File

@ -34,7 +34,6 @@
*/ */
package net.sourceforge.plantuml.tim.expression; package net.sourceforge.plantuml.tim.expression;
//https://en.cppreference.com/w/c/language/operator_precedence //https://en.cppreference.com/w/c/language/operator_precedence
public enum TokenOperator { public enum TokenOperator {
@ -53,7 +52,7 @@ public enum TokenOperator {
return v1.add(v2); return v1.add(v2);
} }
}, },
SUBSTRACTION(100 - 4, "-") { SUBSTRACTION(100 - 4, "" + TokenType.COMMERCIAL_MINUS_SIGN) {
public TValue operate(TValue v1, TValue v2) { public TValue operate(TValue v1, TValue v2) {
return v1.minus(v2); return v1.minus(v2);
} }
@ -97,8 +96,7 @@ public enum TokenOperator {
public TValue operate(TValue v1, TValue v2) { public TValue operate(TValue v1, TValue v2) {
return v1.logicalOr(v2); return v1.logicalOr(v2);
} }
}, };
;
private final int precedence; private final int precedence;
private final String display; private final String display;
@ -113,16 +111,14 @@ public enum TokenOperator {
} }
public static TokenOperator getTokenOperator(char ch, char ch2) { public static TokenOperator getTokenOperator(char ch, char ch2) {
for (TokenOperator op : TokenOperator.values()) { for (TokenOperator op : TokenOperator.values())
if (op.display.length() == 2 && op.display.charAt(0) == ch && op.display.charAt(1) == ch2) { if (op.display.length() == 2 && op.display.charAt(0) == ch && op.display.charAt(1) == ch2)
return op; return op;
}
} for (TokenOperator op : TokenOperator.values())
for (TokenOperator op : TokenOperator.values()) { if (op.display.length() == 1 && op.display.charAt(0) == ch)
if (op.display.length() == 1 && op.display.charAt(0) == ch) {
return op; return op;
}
}
return null; return null;
} }

View File

@ -53,33 +53,6 @@ public class TokenStack {
final private List<Token> tokens; final private List<Token> tokens;
// public boolean isSpecialAffectationWhenFunctionCall() {
// if (tokens.size() != 1) {
// return false;
// }
// final Token single = tokens.get(0);
// if (single.getTokenType() != TokenType.PLAIN_TEXT) {
// return false;
// }
// return isSpecialAffectationWhenFunctionCall(single.getSurface());
// }
//
// public static boolean isSpecialAffectationWhenFunctionCall(String surface) {
// final int idx = surface.indexOf('=');
// if (idx <= 0) {
// return false;
// }
// if (TLineType.isLetterOrUnderscoreOrDollar(surface.charAt(0)) == false) {
// return false;
// }
// for (int i = 1; i < idx; i++) {
// if (TLineType.isLetterOrUnderscoreOrDigit(surface.charAt(i)) == false) {
// return false;
// }
// }
// return true;
// }
public TokenStack() { public TokenStack() {
this(new ArrayList<Token>()); this(new ArrayList<Token>());
} }
@ -117,6 +90,7 @@ public class TokenStack {
static public TokenStack eatUntilCloseParenthesisOrComma(Eater eater) throws EaterException { static public TokenStack eatUntilCloseParenthesisOrComma(Eater eater) throws EaterException {
final TokenStack result = new TokenStack(); final TokenStack result = new TokenStack();
int level = 0; int level = 0;
Token lastToken = null;
while (true) { while (true) {
eater.skipSpaces(); eater.skipSpaces();
final char ch = eater.peekChar(); final char ch = eater.peekChar();
@ -126,13 +100,15 @@ public class TokenStack {
if (level == 0 && (ch == ',' || ch == ')')) if (level == 0 && (ch == ',' || ch == ')'))
return result; return result;
final Token token = TokenType.eatOneToken(eater, false); final Token token = TokenType.eatOneToken(lastToken, eater, false);
final TokenType type = token.getTokenType(); final TokenType type = token.getTokenType();
if (type == TokenType.OPEN_PAREN_MATH) if (type == TokenType.OPEN_PAREN_MATH)
level++; level++;
else if (type == TokenType.CLOSE_PAREN_MATH) else if (type == TokenType.CLOSE_PAREN_MATH)
level--; level--;
if (token.getTokenType() != TokenType.SPACES)
lastToken = token;
result.add(token); result.add(token);
} }
} }

View File

@ -39,7 +39,10 @@ import net.sourceforge.plantuml.tim.EaterException;
import net.sourceforge.plantuml.tim.TLineType; import net.sourceforge.plantuml.tim.TLineType;
public enum TokenType { public enum TokenType {
QUOTED_STRING, JSON_DATA, OPERATOR, OPEN_PAREN_MATH, COMMA, CLOSE_PAREN_MATH, NUMBER, PLAIN_TEXT, SPACES, FUNCTION_NAME, OPEN_PAREN_FUNC, CLOSE_PAREN_FUNC; QUOTED_STRING, JSON_DATA, OPERATOR, OPEN_PAREN_MATH, COMMA, CLOSE_PAREN_MATH, NUMBER, PLAIN_TEXT, SPACES,
FUNCTION_NAME, OPEN_PAREN_FUNC, CLOSE_PAREN_FUNC;
public static final char COMMERCIAL_MINUS_SIGN = '\u2052';
private boolean isSingleChar1() { private boolean isSingleChar1() {
return this == OPEN_PAREN_MATH || this == COMMA || this == CLOSE_PAREN_MATH; return this == OPEN_PAREN_MATH || this == COMMA || this == CLOSE_PAREN_MATH;
@ -47,47 +50,52 @@ public enum TokenType {
private static boolean isPlainTextBreak(char ch, char ch2) { private static boolean isPlainTextBreak(char ch, char ch2) {
final TokenType tmp = fromChar(ch, ch2); final TokenType tmp = fromChar(ch, ch2);
if (tmp.isSingleChar1() || tmp == TokenType.OPERATOR || tmp == SPACES) { if (tmp.isSingleChar1() || tmp == TokenType.OPERATOR || tmp == SPACES)
return true; return true;
}
return false; return false;
} }
private static TokenType fromChar(char ch, char ch2) { private static TokenType fromChar(char ch, char ch2) {
TokenType result = PLAIN_TEXT; TokenType result = PLAIN_TEXT;
if (TLineType.isQuote(ch)) { if (TLineType.isQuote(ch))
result = QUOTED_STRING; result = QUOTED_STRING;
} else if (TokenOperator.getTokenOperator(ch, ch2) != null) { else if (TokenOperator.getTokenOperator(ch, ch2) != null)
result = OPERATOR; result = OPERATOR;
} else if (ch == '(') { else if (ch == '(')
result = OPEN_PAREN_MATH; result = OPEN_PAREN_MATH;
} else if (ch == ')') { else if (ch == ')')
result = CLOSE_PAREN_MATH; result = CLOSE_PAREN_MATH;
} else if (ch == ',') { else if (ch == ',')
result = COMMA; result = COMMA;
} else if (TLineType.isLatinDigit(ch)) { else if (TLineType.isLatinDigit(ch))
result = NUMBER; result = NUMBER;
} else if (TLineType.isSpaceChar(ch)) { else if (TLineType.isSpaceChar(ch))
result = SPACES; result = SPACES;
}
return result; return result;
} }
final static public Token eatOneToken(Eater eater, boolean manageColon) throws EaterException { final static public Token eatOneToken(Token lastToken, Eater eater, boolean manageColon) throws EaterException {
final char ch = eater.peekChar(); char ch = eater.peekChar();
if (ch == 0) { if (ch == 0)
return null; return null;
}
if (manageColon && ch == ':') { if (manageColon && ch == ':')
return null; return null;
}
if (ch == '-' && isTheMinusAnOperation(lastToken))
ch = COMMERCIAL_MINUS_SIGN;
final TokenOperator tokenOperator = TokenOperator.getTokenOperator(ch, eater.peekCharN2()); final TokenOperator tokenOperator = TokenOperator.getTokenOperator(ch, eater.peekCharN2());
if (TLineType.isQuote(ch)) { if (TLineType.isQuote(ch)) {
return new Token(eater.eatAndGetQuotedString(), TokenType.QUOTED_STRING, null); return new Token(eater.eatAndGetQuotedString(), TokenType.QUOTED_STRING, null);
} else if (tokenOperator != null) { } else if (tokenOperator != null) {
if (tokenOperator.getDisplay().length() == 1) { if (tokenOperator.getDisplay().length() == 1) {
return new Token(eater.eatOneChar(), TokenType.OPERATOR, null); eater.eatOneChar();
return new Token(ch, TokenType.OPERATOR, null);
} }
return new Token("" + eater.eatOneChar() + eater.eatOneChar(), TokenType.OPERATOR, null); return new Token("" + eater.eatOneChar() + eater.eatOneChar(), TokenType.OPERATOR, null);
} else if (ch == '(') { } else if (ch == '(') {
return new Token(eater.eatOneChar(), TokenType.OPEN_PAREN_MATH, null); return new Token(eater.eatOneChar(), TokenType.OPEN_PAREN_MATH, null);
@ -95,7 +103,7 @@ public enum TokenType {
return new Token(eater.eatOneChar(), TokenType.CLOSE_PAREN_MATH, null); return new Token(eater.eatOneChar(), TokenType.CLOSE_PAREN_MATH, null);
} else if (ch == ',') { } else if (ch == ',') {
return new Token(eater.eatOneChar(), TokenType.COMMA, null); return new Token(eater.eatOneChar(), TokenType.COMMA, null);
} else if (TLineType.isLatinDigit(ch)) { } else if (TLineType.isLatinDigit(ch) || ch == '-') {
return new Token(eater.eatAndGetNumber(), TokenType.NUMBER, null); return new Token(eater.eatAndGetNumber(), TokenType.NUMBER, null);
} else if (TLineType.isSpaceChar(ch)) { } else if (TLineType.isSpaceChar(ch)) {
return new Token(eater.eatAndGetSpaces(), TokenType.SPACES, null); return new Token(eater.eatAndGetSpaces(), TokenType.SPACES, null);
@ -103,13 +111,22 @@ public enum TokenType {
return new Token(eatAndGetTokenPlainText(eater), TokenType.PLAIN_TEXT, null); return new Token(eatAndGetTokenPlainText(eater), TokenType.PLAIN_TEXT, null);
} }
private static boolean isTheMinusAnOperation(Token lastToken) {
if (lastToken == null)
return false;
final TokenType type = lastToken.getTokenType();
if (type == TokenType.OPERATOR)
return false;
return true;
}
static private String eatAndGetTokenPlainText(Eater eater) throws EaterException { static private String eatAndGetTokenPlainText(Eater eater) throws EaterException {
final StringBuilder result = new StringBuilder(); final StringBuilder result = new StringBuilder();
while (true) { while (true) {
final char ch = eater.peekChar(); final char ch = eater.peekChar();
if (ch == 0 || TokenType.isPlainTextBreak(ch, eater.peekCharN2())) { if (ch == 0 || TokenType.isPlainTextBreak(ch, eater.peekCharN2()))
return result.toString(); return result.toString();
}
result.append(eater.eatOneChar()); result.append(eater.eatOneChar());
} }
} }

View File

@ -61,6 +61,7 @@ import net.sourceforge.plantuml.timingdiagram.TimingNote;
import net.sourceforge.plantuml.timingdiagram.TimingRuler; import net.sourceforge.plantuml.timingdiagram.TimingRuler;
import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.ULine; import net.sourceforge.plantuml.ugraphic.ULine;
import net.sourceforge.plantuml.ugraphic.URectangle;
import net.sourceforge.plantuml.ugraphic.UTranslate; import net.sourceforge.plantuml.ugraphic.UTranslate;
import net.sourceforge.plantuml.ugraphic.color.HColor; import net.sourceforge.plantuml.ugraphic.color.HColor;
@ -184,20 +185,13 @@ public class Ribbon implements PDrawing {
} }
private void drawPentaA(UGraphic ug, double len, ChangeState change) { private void drawPentaA(UGraphic ug, double len, ChangeState change) {
SymbolContext context; SymbolContext context = change.getContext(skinParam, style);
if (change == null) { final HColor back = initialColors.getColor(ColorType.BACK);
final HColor back = style.value(PName.BackGroundColor).asColor(skinParam.getIHtmlColorSet()); final HColor line = initialColors.getColor(ColorType.LINE);
final HColor line = style.value(PName.LineColor).asColor(skinParam.getIHtmlColorSet()); if (back != null)
context = new SymbolContext(back, line).withStroke(style.getStroke()); context = context.withBackColor(back);
} else { if (line != null)
context = change.getContext(skinParam, style); context = context.withForeColor(line);
final HColor back = initialColors.getColor(ColorType.BACK);
final HColor line = initialColors.getColor(ColorType.LINE);
if (back != null)
context = context.withBackColor(back);
if (line != null)
context = context.withForeColor(line);
}
final PentaAShape shape = PentaAShape.create(len, getRibbonHeight(), context); final PentaAShape shape = PentaAShape.create(len, getRibbonHeight(), context);
shape.drawU(ug); shape.drawU(ug);
@ -262,9 +256,8 @@ public class Ribbon implements PDrawing {
return; return;
final StringBounder stringBounder = ug.getStringBounder(); final StringBounder stringBounder = ug.getStringBounder();
if (changes.size() == 0) { if (changes.size() == 0) {
final double a = 0; drawSingle(ug.apply(UTranslate.dx(-getInitialWidth(stringBounder))),
drawPentaA(ug.apply(UTranslate.dx(-getInitialWidth(stringBounder))), getInitialWidth(stringBounder) + a, getInitialWidth(stringBounder) + ruler.getWidth());
null);
} else { } else {
final double a = getPosInPixel(changes.get(0)); final double a = getPosInPixel(changes.get(0));
drawPentaA(ug.apply(UTranslate.dx(-getInitialWidth(stringBounder))), getInitialWidth(stringBounder) + a, drawPentaA(ug.apply(UTranslate.dx(-getInitialWidth(stringBounder))), getInitialWidth(stringBounder) + a,
@ -281,6 +274,23 @@ public class Ribbon implements PDrawing {
} }
} }
private void drawSingle(UGraphic ug, double len) {
final HColor back = style.value(PName.BackGroundColor).asColor(skinParam.getIHtmlColorSet());
final HColor line = style.value(PName.LineColor).asColor(skinParam.getIHtmlColorSet());
SymbolContext context = new SymbolContext(back, back).withStroke(style.getStroke());
ug = context.apply(ug);
final double height = getRibbonHeight();
final URectangle rect = new URectangle(len, height);
ug.draw(rect);
final ULine border = ULine.hline(len);
ug = ug.apply(line);
ug.draw(border);
ug.apply(UTranslate.dy(height)).draw(border);
}
private void drawStates(UGraphic ug) { private void drawStates(UGraphic ug) {
for (int i = 0; i < changes.size() - 1; i++) { for (int i = 0; i < changes.size() - 1; i++) {
final double a = getPosInPixel(changes.get(i)); final double a = getPosInPixel(changes.get(i));

View File

@ -81,7 +81,7 @@ public class Version {
} }
public static int beta() { public static int beta() {
final int beta = 5; final int beta = 7;
return beta; return beta;
} }