progress #369
This commit is contained in:
parent
d9fdf80db6
commit
d78f31a8ed
|
@ -398,7 +398,7 @@ public abstract class AbstractEvaluator<T> {
|
|||
stackRPN.push(s);
|
||||
}
|
||||
|
||||
public String getRusEfi() {
|
||||
public String getPosftfixExpression() {
|
||||
List<String> list = new ArrayList<>(stackRPN);
|
||||
ListIterator<String> li = list.listIterator(list.size());
|
||||
// List<String> reverse = new ArrayList<>();
|
||||
|
|
|
@ -10,6 +10,12 @@ import java.util.Stack;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class ParserTest {
|
||||
@Test
|
||||
public void testFunctionParameters() {
|
||||
// todo: parameter order needs to be in postfix form
|
||||
// assertParseB("fsio_setting 0", "fsio_setting 0");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBooleanConversion() throws ParseException {
|
||||
assertParseB("2 1 >", "2 > 1");
|
||||
|
@ -41,7 +47,7 @@ public class ParserTest {
|
|||
DoubleEvaluator evaluator = new DoubleEvaluator();
|
||||
evaluator.evaluate(expression.toLowerCase());
|
||||
|
||||
assertEquals(rpn, evaluator.getRusEfi());
|
||||
assertEquals(rpn, evaluator.getPosftfixExpression());
|
||||
}
|
||||
|
||||
private String getInfix(String rpn) {
|
||||
|
|
|
@ -65,7 +65,7 @@ public class CompileTool {
|
|||
|
||||
String expression = line.substring(indexOfEquals + 1).trim();
|
||||
|
||||
String rpn = DoubleEvaluator.process(expression).getRusEfi();
|
||||
String rpn = DoubleEvaluator.process(expression).getPosftfixExpression();
|
||||
|
||||
bw.write("\n// Human-readable: " + expression + "\r\n");
|
||||
bw.write("#define " + name + " \"" + rpn + "\"\r\n");
|
||||
|
|
|
@ -40,7 +40,7 @@ public class FlexibleControls {
|
|||
}
|
||||
|
||||
private void process(String text) {
|
||||
rpnForm.setText(DoubleEvaluator.process(text).getRusEfi());
|
||||
rpnForm.setText(DoubleEvaluator.process(text).getPosftfixExpression());
|
||||
}
|
||||
|
||||
public JPanel getPanel() {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.rusefi.ui.widgets;
|
||||
|
||||
import com.fathzer.soft.javaluator.DoubleEvaluator;
|
||||
import com.rusefi.io.CommandQueue;
|
||||
import com.rusefi.ui.RecentCommands;
|
||||
import com.rusefi.ui.storage.Node;
|
||||
|
@ -97,14 +98,16 @@ public class AnyCommand {
|
|||
}
|
||||
|
||||
private void send() {
|
||||
String cmd = text.getText();
|
||||
for (String s : cmd.split("\n"))
|
||||
doSend(s);
|
||||
String multiLine = text.getText();
|
||||
for (String line : multiLine.split("\n")) {
|
||||
sendCommand(line);
|
||||
}
|
||||
}
|
||||
|
||||
private void doSend(String cmd) {
|
||||
if (!isValidInput(cmd))
|
||||
private void sendCommand(String rawCommand) {
|
||||
if (!isValidInput(rawCommand))
|
||||
return;
|
||||
String cmd = prepareCommand(rawCommand);
|
||||
if (listener != null)
|
||||
listener.onSend();
|
||||
int timeout = CommandQueue.getTimeout(cmd);
|
||||
|
@ -113,6 +116,46 @@ public class AnyCommand {
|
|||
reentrant = false;
|
||||
}
|
||||
|
||||
public static String prepareCommand(String rawCommand) {
|
||||
if (rawCommand.startsWith("eval ")) {
|
||||
return prepareEvalCommand(rawCommand);
|
||||
} else if (rawCommand.startsWith("set_fsio_expression ")) {
|
||||
return prepareSetFsioCommand(rawCommand);
|
||||
} else {
|
||||
return rawCommand;
|
||||
}
|
||||
}
|
||||
|
||||
private static String prepareSetFsioCommand(String rawCommand) {
|
||||
String[] parts = rawCommand.split(" ", 3);
|
||||
if (parts.length != 3)
|
||||
return rawCommand; // let's ignore invalid command
|
||||
return "set_rpn_expression " + parts[1] + " " + quote(infix2postfix(unquote(parts[2])));
|
||||
}
|
||||
|
||||
private static String prepareEvalCommand(String rawCommand) {
|
||||
String[] parts = rawCommand.split(" ", 2);
|
||||
if (parts.length != 2)
|
||||
return rawCommand; // let's ignore invalid command
|
||||
|
||||
return "rpn_eval " + quote(infix2postfix(unquote(parts[1])));
|
||||
}
|
||||
|
||||
private static String quote(String s) {
|
||||
return "\"" + s + "\"";
|
||||
}
|
||||
|
||||
private static String infix2postfix(String infixExpression) {
|
||||
return DoubleEvaluator.process(infixExpression).getPosftfixExpression();
|
||||
}
|
||||
|
||||
public static String unquote(String quoted) {
|
||||
quoted = quoted.trim();
|
||||
if (quoted.charAt(0) == '"')
|
||||
return quoted.substring(1, quoted.length() - 1);
|
||||
return quoted; // ignoring invalid input
|
||||
}
|
||||
|
||||
private static boolean isValidInput(String text) {
|
||||
boolean isOk = true;
|
||||
for (char c : text.toCharArray()) {
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package com.rusefi.ui.widgets.test;
|
||||
|
||||
import com.rusefi.ui.widgets.AnyCommand;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* (c) Andrey Belomutskiy
|
||||
* 3/9/2017.
|
||||
*/
|
||||
public class AnyCommandTest {
|
||||
@Test
|
||||
public void testUnquote() {
|
||||
assertEquals("1 2 3", AnyCommand.unquote(" \"1 2 3\" "));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrepareEvalCommand() {
|
||||
assertEquals("rpn_eval \"2 3 +\"", AnyCommand.prepareCommand("eval \"2 + 3\" "));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetFSIOexpression() {
|
||||
// todo: parameter order needs to be in postfix form
|
||||
assertEquals("set_rpn_expression 1 \"rpm fsio_setting 0 >\"", AnyCommand.prepareCommand("set_fsio_expression 1 \"rpm > fsio_setting 0\""));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue