mirror of
https://github.com/octoleo/plantuml.git
synced 2024-12-22 19:09:03 +00:00
Use RegexConcat in CommandReferenceMultilinesOverSeveral
This commit is contained in:
parent
410f1caf71
commit
51f90138b7
@ -45,6 +45,10 @@ import net.sourceforge.plantuml.UrlMode;
|
|||||||
import net.sourceforge.plantuml.command.BlocLines;
|
import net.sourceforge.plantuml.command.BlocLines;
|
||||||
import net.sourceforge.plantuml.command.CommandExecutionResult;
|
import net.sourceforge.plantuml.command.CommandExecutionResult;
|
||||||
import net.sourceforge.plantuml.command.CommandMultilines;
|
import net.sourceforge.plantuml.command.CommandMultilines;
|
||||||
|
import net.sourceforge.plantuml.command.regex.RegexConcat;
|
||||||
|
import net.sourceforge.plantuml.command.regex.RegexLeaf;
|
||||||
|
import net.sourceforge.plantuml.command.regex.RegexOptional;
|
||||||
|
import net.sourceforge.plantuml.command.regex.RegexResult;
|
||||||
import net.sourceforge.plantuml.cucadiagram.Display;
|
import net.sourceforge.plantuml.cucadiagram.Display;
|
||||||
import net.sourceforge.plantuml.sequencediagram.Participant;
|
import net.sourceforge.plantuml.sequencediagram.Participant;
|
||||||
import net.sourceforge.plantuml.sequencediagram.Reference;
|
import net.sourceforge.plantuml.sequencediagram.Reference;
|
||||||
@ -55,24 +59,41 @@ import net.sourceforge.plantuml.ugraphic.color.NoSuchColorException;
|
|||||||
public class CommandReferenceMultilinesOverSeveral extends CommandMultilines<SequenceDiagram> {
|
public class CommandReferenceMultilinesOverSeveral extends CommandMultilines<SequenceDiagram> {
|
||||||
|
|
||||||
public CommandReferenceMultilinesOverSeveral() {
|
public CommandReferenceMultilinesOverSeveral() {
|
||||||
super("^ref(#\\w+)?[%s]+over[%s]+((?:[%pLN_.@]+|[%g][^%g]+[%g])(?:[%s]*,[%s]*(?:[%pLN_.@]+|[%g][^%g]+[%g]))*)$");
|
super(getConcat().getPattern());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static RegexConcat getConcat() {
|
||||||
|
return RegexConcat.build(CommandReferenceMultilinesOverSeveral.class.getName(),
|
||||||
|
RegexLeaf.start(), //
|
||||||
|
new RegexLeaf("ref"), //
|
||||||
|
new RegexLeaf("REF", "(#\\w+)?"), //
|
||||||
|
RegexLeaf.spaceOneOrMore(), //
|
||||||
|
new RegexLeaf("over"), //
|
||||||
|
RegexLeaf.spaceOneOrMore(), //
|
||||||
|
new RegexLeaf("PARTS", "((?:[%pLN_.@]+|[%g][^%g]+[%g])(?:[%s]*,[%s]*(?:[%pLN_.@]+|[%g][^%g]+[%g]))*)"), //
|
||||||
|
RegexLeaf.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPatternEnd() {
|
public String getPatternEnd() {
|
||||||
return "^end[%s]?(ref)?$";
|
return "^end[%s]?(ref)?$";
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommandExecutionResult execute(final SequenceDiagram diagram, BlocLines lines) throws NoSuchColorException {
|
public CommandExecutionResult execute(final SequenceDiagram diagram, BlocLines lines) throws NoSuchColorException {
|
||||||
final List<String> line0 = StringUtils.getSplit(getStartingPattern(),
|
String firstLine = lines.getFirst().getTrimmed().getString();
|
||||||
lines.getFirst().getTrimmed().getString());
|
RegexResult arg = getConcat().matcher(firstLine);
|
||||||
final String s1 = line0.get(0);
|
if (arg == null) {
|
||||||
|
return CommandExecutionResult.error("Cannot parse line " + firstLine);
|
||||||
|
}
|
||||||
|
|
||||||
|
String s1 = arg.get("REF", 0);
|
||||||
final HColor backColorElement = s1 == null ? null
|
final HColor backColorElement = s1 == null ? null
|
||||||
: diagram.getSkinParam().getIHtmlColorSet().getColor(diagram.getSkinParam().getThemeStyle(), s1);
|
: diagram.getSkinParam().getIHtmlColorSet().getColor(diagram.getSkinParam().getThemeStyle(), s1);
|
||||||
// final HtmlColor backColorGeneral =
|
// final HtmlColor backColorGeneral =
|
||||||
// HtmlColorSetSimple.instance().getColorIfValid(line0.get(1));
|
// HtmlColorSetSimple.instance().getColorIfValid(line0.get(1));
|
||||||
|
|
||||||
final List<String> participants = StringUtils.splitComma(line0.get(1));
|
final List<String> participants = StringUtils.splitComma(arg.get("PARTS", 0));
|
||||||
final List<Participant> p = new ArrayList<>();
|
final List<Participant> p = new ArrayList<>();
|
||||||
for (String s : participants) {
|
for (String s : participants) {
|
||||||
p.add(diagram.getOrCreateParticipant(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(s)));
|
p.add(diagram.getOrCreateParticipant(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(s)));
|
||||||
@ -84,7 +105,7 @@ public class CommandReferenceMultilinesOverSeveral extends CommandMultilines<Seq
|
|||||||
|
|
||||||
Url u = null;
|
Url u = null;
|
||||||
if (strings.size() > 0) {
|
if (strings.size() > 0) {
|
||||||
final UrlBuilder urlBuilder = new UrlBuilder(diagram.getSkinParam().getValue("topurl"), UrlMode.STRICT);
|
final UrlBuilder urlBuilder = new UrlBuilder(diagram.getSkinParam().getValue("topurl"), UrlMode.STRICT);
|
||||||
u = urlBuilder.getUrl(strings.get(0).toString());
|
u = urlBuilder.getUrl(strings.get(0).toString());
|
||||||
}
|
}
|
||||||
if (u != null) {
|
if (u != null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user