private BlocLines addOneSingleLineManageEmbedded2(IteratorCounter2 it, BlocLines lines) { final CharSequence linetoBeAdded = it.next(); lines = lines.add2(linetoBeAdded); if (StringUtils.trimNoTrace(linetoBeAdded).equals("{{")) { while (it.hasNext()) { final CharSequence s = it.next(); lines = lines.add2(s); if (StringUtils.trimNoTrace(s).equals("}}")) { return lines; } } } return lines; }
public final CommandControl isValid(BlocLines lines) { if (lines.size() != 1) { return CommandControl.NOT_OK; } lines = lines.removeInnerComments(); if (isCommandForbidden()) { return CommandControl.NOT_OK; } final String line = StringUtils.trin(lines.getFirst499()); final boolean result = pattern.match(line); if (result) { actionIfCommandValid(); } return result ? CommandControl.OK : CommandControl.NOT_OK; }
public final CommandExecutionResult execute(S system, BlocLines lines) { if (lines.size() != 1) { throw new IllegalArgumentException(); } lines = lines.removeInnerComments(); final String line = StringUtils.trin(lines.getFirst499()); if (isForbidden(line)) { return CommandExecutionResult.error("Forbidden line " + line); } final RegexResult arg = pattern.matcher(line); if (arg == null) { return CommandExecutionResult.error("Cannot parse line " + line); } if (system instanceof PSystemError) { return CommandExecutionResult.error("PSystemError cannot be cast"); } // System.err.println("lines="+lines); // System.err.println("pattern="+pattern.getPattern()); return executeArg(system, arg); }
private AbstractPSystem executeOneLine( AbstractPSystem sys, UmlSource source, final IteratorCounter2 it) { final CommandControl commandControl = isValid2(it); if (commandControl == CommandControl.NOT_OK) { final ErrorUml err = new ErrorUml( ErrorUmlType.SYNTAX_ERROR, "Syntax Error?", it.currentNum(), it.peek().getLocation()); if (OptionFlags.getInstance().isUseSuggestEngine()) { final SuggestEngine engine = new SuggestEngine(source, this); final SuggestEngineResult result = engine.tryToSuggest(sys); if (result.getStatus() == SuggestEngineStatus.ONE_SUGGESTION) { err.setSuggest(result); } } sys = new PSystemError(source, err, null); } else if (commandControl == CommandControl.OK_PARTIAL) { final IteratorCounter2 saved = it.cloneMe(); final CommandExecutionResult result = manageMultiline2(it, sys); if (result.isOk() == false) { sys = new PSystemError( source, new ErrorUml( ErrorUmlType.EXECUTION_ERROR, result.getError(), it.currentNum() - 1, saved.next().getLocation()), null); } } else if (commandControl == CommandControl.OK) { final CharSequence line = it.next(); final BlocLines lines = BlocLines.single(line); Command cmd = getFirstCommandOkForLines(lines); final CommandExecutionResult result = sys.executeCommand(cmd, lines); if (result.isOk() == false) { sys = new PSystemError( source, new ErrorUml( ErrorUmlType.EXECUTION_ERROR, result.getError(), it.currentNum() - 1, ((CharSequence2) line).getLocation()), result.getDebugLines()); } if (result.getNewDiagram() != null) { sys = result.getNewDiagram(); } } else { assert false; } return sys; }
public CommandControl isValid2(final IteratorCounter2 it) { final BlocLines lines = BlocLines.single(it.peek()); for (Command cmd : cmds) { final CommandControl result = cmd.isValid(lines); if (result == CommandControl.OK) { return result; } if (result == CommandControl.OK_PARTIAL && isMultilineCommandOk(it.cloneMe(), cmd) != null) { return result; } } return CommandControl.NOT_OK; }
public CommandControl goForwardMultiline(final IteratorCounter2 it) { final BlocLines lines = BlocLines.single(it.peek()); for (Command cmd : cmds) { final CommandControl result = cmd.isValid(lines); if (result == CommandControl.OK) { throw new IllegalStateException(); } if (result == CommandControl.OK_PARTIAL && isMultilineCommandOk(it, cmd) != null) { return result; } } return CommandControl.NOT_OK; // throw new IllegalStateException(); }
public final CommandControl isValid(BlocLines lines) { if (isCommandForbidden()) { return CommandControl.NOT_OK; } final Matcher2 m1 = starting.matcher(StringUtils.trim(lines.getFirst499())); if (m1.matches() == false) { return CommandControl.NOT_OK; } if (lines.size() == 1) { return CommandControl.OK_PARTIAL; } int level = 1; for (CharSequence cs : lines.subExtract(1, 0)) { final String s = StringUtils.trim(cs); if (isLineConsistent(s, level) == false) { return CommandControl.NOT_OK; } if (s.endsWith("{")) { level++; } if (s.endsWith("}")) { level--; } if (level < 0) { return CommandControl.NOT_OK; } } if (level != 0) { return CommandControl.OK_PARTIAL; } actionIfCommandValid(); return CommandControl.OK; }