diff --git a/language/buildNumber.properties b/language/buildNumber.properties index 9348490a4..55c1d7483 100644 --- a/language/buildNumber.properties +++ b/language/buildNumber.properties @@ -1,3 +1,3 @@ #maven.buildNumber.plugin properties file -#Wed Mar 27 14:15:30 CDT 2024 -buildNumber\\d*=12888 +#Wed Apr 24 08:17:20 CDT 2024 +buildNumber\\d*=12894 diff --git a/language/src/main/java/edu/uiuc/ncsa/qdl/evaluate/StemEvaluator.java b/language/src/main/java/edu/uiuc/ncsa/qdl/evaluate/StemEvaluator.java index 8867bb0d8..a68c6ad87 100644 --- a/language/src/main/java/edu/uiuc/ncsa/qdl/evaluate/StemEvaluator.java +++ b/language/src/main/java/edu/uiuc/ncsa/qdl/evaluate/StemEvaluator.java @@ -764,22 +764,31 @@ private void doStar(Polyad polyad, State state) { private void doRemap(Polyad polyad, State state) { if (polyad.isSizeQuery()) { - polyad.setResult(new int[]{2, 3}); + polyad.setResult(new int[]{1, 2, 3}); polyad.setEvaluated(true); return; } - if (polyad.getArgCount() < 2) { + /* if (polyad.getArgCount() < 2) { throw new MissingArgException(REMAP + " requires at least two arguments", polyad.getArgCount() == 1 ? polyad.getArgAt(0) : polyad); } if (3 < polyad.getArgCount()) { throw new ExtraArgException(REMAP + " takes at most 3 arguments", polyad.getArgAt(3)); - } + }*/ Object arg1 = polyad.evalArg(0, state); checkNull(arg1, polyad.getArgAt(0)); if (!isStem(arg1)) { throw new BadArgException(REMAP + " requires stem as its first argument", polyad.getArgAt(0)); } QDLStem stem = (QDLStem) arg1; + if (polyad.getArgCount() == 1) { + // reverse keys and values + QDLStem out = reverseKeysAndValues(stem); + polyad.setResult(out); + polyad.setEvaluated(true); + polyad.setResultType(STEM_TYPE); + return; + } + Object arg2 = polyad.evalArg(1, state); checkNull(arg2, polyad.getArgAt(1)); @@ -808,6 +817,19 @@ private void doRemap(Polyad polyad, State state) { } + protected QDLStem reverseKeysAndValues(QDLStem inStem) { + QDLStem out = new QDLStem(); + for (Object kk : inStem.keySet()) { + Object v = inStem.get(kk); + if (isLong(v) || isString(v)) { + out.putLongOrString(v, kk); + } + if (isStem(v)) { + out.putLongOrString(kk, reverseKeysAndValues((QDLStem) v)); + } + } + return out; + } protected void doIndices(Polyad polyad, State state) { if (polyad.isSizeQuery()) { polyad.setResult(new int[]{1, 2}); diff --git a/language/src/main/java/edu/uiuc/ncsa/qdl/gui/editor/EditorKeyPressedAdapter.java b/language/src/main/java/edu/uiuc/ncsa/qdl/gui/editor/EditorKeyPressedAdapter.java index 8f7b3f1ff..9f10ea6c8 100644 --- a/language/src/main/java/edu/uiuc/ncsa/qdl/gui/editor/EditorKeyPressedAdapter.java +++ b/language/src/main/java/edu/uiuc/ncsa/qdl/gui/editor/EditorKeyPressedAdapter.java @@ -4,6 +4,7 @@ import edu.uiuc.ncsa.qdl.parsing.QDLParserDriver; import edu.uiuc.ncsa.qdl.parsing.QDLRunner; import edu.uiuc.ncsa.qdl.state.State; +import edu.uiuc.ncsa.qdl.util.QDLFileUtil; import edu.uiuc.ncsa.qdl.workspace.WorkspaceCommands; import edu.uiuc.ncsa.security.core.configuration.XProperties; import edu.uiuc.ncsa.security.core.util.DebugUtil; @@ -101,23 +102,14 @@ protected String getGUIHelp() { InputStream helpStream = getClass().getResourceAsStream("/editor_help.txt"); if (helpStream != null) { - InputStreamReader isr = new InputStreamReader(helpStream); - BufferedReader bufferedReader = new BufferedReader(isr); - StringBuilder stringBuilder = new StringBuilder(); try { - String lineIn = bufferedReader.readLine(); - while (lineIn != null) { - stringBuilder.append(lineIn + "\n"); - lineIn = bufferedReader.readLine(); - } - guiHelp = stringBuilder.toString(); - bufferedReader.close(); + guiHelp = QDLFileUtil.isToString(helpStream); + helpStream.close(); } catch (IOException e) { if (DebugUtil.isEnabled()) { e.printStackTrace(); } } - } } return guiHelp; @@ -173,28 +165,28 @@ public void keyPressed(KeyEvent e) { case KeyEvent.VK_I: // Insert in input form if (e.isControlDown()) { - try { - String out = (String) getClipboard().getData(DataFlavor.stringFlavor); - out = LineUtil.toInputForm(out, e.isShiftDown()); - String content = input.getText(); - int position = input.getCaretPosition(); - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append(content.substring(0, position)); - stringBuilder.append(out); - if (position + 1 < content.length()) { - stringBuilder.append(content.substring(position + 1)); - } - input.setText(null); - input.setText(stringBuilder.toString()); - input.repaint(); - input.setCaretPosition(position); - - } catch (UnsupportedFlavorException | IOException ex) { - if (DebugUtil.isEnabled()) { - ex.printStackTrace(); - } - break; + try { + String out = (String) getClipboard().getData(DataFlavor.stringFlavor); + out = LineUtil.toInputForm(out, e.isShiftDown()); + String content = input.getText(); + int position = input.getCaretPosition(); + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(content.substring(0, position)); + stringBuilder.append(out); + if (position + 1 < content.length()) { + stringBuilder.append(content.substring(position + 1)); + } + input.setText(null); + input.setText(stringBuilder.toString()); + input.repaint(); + input.setCaretPosition(position); + + } catch (UnsupportedFlavorException | IOException ex) { + if (DebugUtil.isEnabled()) { + ex.printStackTrace(); } + break; + } } break; case KeyEvent.VK_H: @@ -285,10 +277,10 @@ public void keyPressed(KeyEvent e) { case KeyEvent.VK_F1: // If no selected text, put up a generic help message. Otherwise, // search online help. - if(e.isControlDown()&& !e.isAltDown()){ + if (e.isControlDown() && !e.isAltDown()) { String x = getHelp("keyboard"); if (x != null) { - String helpMessage = x; + String helpMessage = x; } showHelp("QDL keyboard layout", x); break; @@ -364,7 +356,6 @@ public void keyPressed(KeyEvent e) { } - protected void doQuit(boolean forceQuit) { if (forceQuit) { System.exit(0); diff --git a/language/src/main/java/edu/uiuc/ncsa/qdl/util/QDLFileUtil.java b/language/src/main/java/edu/uiuc/ncsa/qdl/util/QDLFileUtil.java index 04a22fa6f..29c5f87ef 100644 --- a/language/src/main/java/edu/uiuc/ncsa/qdl/util/QDLFileUtil.java +++ b/language/src/main/java/edu/uiuc/ncsa/qdl/util/QDLFileUtil.java @@ -37,13 +37,44 @@ *
Created by Jeff Gaynor
* on 1/29/20 at 9:52 AM
*/
public class QDLFileUtil extends FileUtil {
+ /**
+ * Reads an {@link InputStream} as a string, does not close it when done!
+ *
+ * @param inputStream
+ * @return
+ * @throws Throwable
+ */
+ public static String isToString(InputStream inputStream) throws IOException {
+ InputStreamReader isr = new InputStreamReader(inputStream);
+ return readerToString(isr);
+ }
+
+ public static String readerToString(Reader reader) throws IOException {
+ if(reader == null){
+ return "";
+ }
+ BufferedReader bufferedReader;
+
+ if(reader instanceof BufferedReader){
+ bufferedReader = (BufferedReader) reader;
+ }else{
+ bufferedReader = new BufferedReader(reader);
+ }
+ StringBuilder stringBuilder = new StringBuilder();
+ String lineIn = bufferedReader.readLine();
+ while (lineIn != null) {
+ stringBuilder.append(lineIn + "\n");
+ lineIn = bufferedReader.readLine();
+ }
+ return stringBuilder.toString();
+ }
public static QDLStem readFileAsStem(String fileName) throws Throwable {
checkFile(fileName);
@@ -71,10 +102,10 @@ public static QDLStem readFileAsStem(String fileName) throws Throwable {
public static List