Browse Source

Merge branch 'new-value-input' of LInE/iVProg into master

GitAdmin 4 years ago
parent
commit
c7f822a35a

+ 9 - 5
css/ivprog-term.css

@@ -11,18 +11,22 @@
 
 .ivprog-term-userText {
   white-space: pre;
+  height: 1.6rem;
 }
 
 .ivprog-term-userText, .ivprog-term-userInput {
   color: #f2d6d6;
+  height: 1.6rem;
 }
 
 .ivprog-term-info {
   color: #28a628;
+  height: 1.6rem;
 }
 
 .ivprog-term-error {
   color: #df4242;
+  height: 1.6rem;
 }
 
 .ivprog-term-input {
@@ -65,18 +69,18 @@
 .ivprog-term-div::-webkit-scrollbar {
     width: 12px;
 }
- 
+
 .ivprog-term-div::-webkit-scrollbar-track {
-    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); 
+    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
     -webkit-border-radius: 10px;
     border-radius: 10px;
 }
- 
+
 .ivprog-term-div::-webkit-scrollbar-thumb {
     -webkit-border-radius: 10px;
     border-radius: 10px;
     background: green;
-    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5); 
+    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5);
 }
 
 /**novas regras bash*/
@@ -116,7 +120,7 @@
   background: #111010;
   /* list-style: none; */
   color: #F8F8FF;
-  
+
   font: 14px 'Andale Mono', Consolas, 'Courier New';
   line-height: 1.6em;
   border: 1px solid #CCCCCC;

+ 13 - 11
js/io/domConsole.js

@@ -191,7 +191,7 @@ export class DOMConsole {
   }
 
   async _appendText (text, type, newLine = false) {
-    console.debug("Caling appendText");
+    // console.debug("Caling appendText");
     const write_time = Date.now();
     this.pending_writes.push(0);
     await Utils.sleep(5);
@@ -209,7 +209,7 @@ export class DOMConsole {
     }
     this.currentLine.innerHTML += this.getOutputText(text);
     if (newLine) {
-      console.debug("append newline");
+      // console.debug("append newline");
       this.currentLine = null;
     }
     this.scrollTerm();
@@ -228,6 +228,9 @@ export class DOMConsole {
     textDiv.classList.add(divClass);
     if (filter) textDiv.innerHTML = this.getOutputText(text);
     else textDiv.innerHTML = `<span>${text}</span>`;
+    if (this.currentLine != null && this.currentLine.innerHTML.length === 0) {
+      this.termDiv.removeChild(this.currentLine);
+    }
     this.termDiv.insertBefore(textDiv, this.inputDiv);
     this.currentLine = null;
     this.scrollTerm();
@@ -365,22 +368,21 @@ export class DOMConsole {
   }
 
   sendOutput (text) {
-    // console.debug(text);
+    //console.debug(text);
     let output = "" + text;
     if (output.indexOf("\n") !== -1) {
-      // console.debug("newline");
+      //console.debug("newline");
       const outputList = output.split("\n");
       let i = 0;
       for (; i < outputList.length - 1; i += 1) {
-        // console.debug("newline write");
+        //console.debug("newline write");
         let t = outputList[i];
         t = t.replace(/\t/g, "&#x0020;&#x0020;");
         t = t.replace(/\s/g, "&#x0020;");
-        if (t.length == 0) {
-          // t = "&nbsp;";
-          // console.debug('Empty string');
-          this.currentLine = null;
-        } else this.write(t, true);
+        if (t.length !== 0) {
+          this.write(t);
+        }
+        this.write("", true);
       }
       let t = outputList[i];
       t = t.replace(/\t/g, "&#x0020;&#x0020;");
@@ -390,7 +392,7 @@ export class DOMConsole {
       // console.debug("no newline");
       output = output.replace(/\t/g, "&#x0020;&#x0020;");
       output = output.replace(/\s/g, "&#x0020;");
-      this.write(output);
+      if (output.length != 0) this.write(output);
     }
   }
 

+ 58 - 31
js/processor/lib/io.js

@@ -1,74 +1,101 @@
-import * as Commands from './../../ast/commands';
-import { Modes } from '../modes';
-import {toInt, toString, toBool, toReal, convertToString} from './../../typeSystem/parsers';
-import { Types } from './../../typeSystem/types';
+import * as Commands from "./../../ast/commands";
+import { Modes } from "../modes";
+import * as Parsers from "./../../typeSystem/parsers";
+import { Types } from "./../../typeSystem/types";
 import { ProcessorErrorFactory } from "./../error/processorErrorFactory";
-import { StoreValue } from '../store/value/store_value';
+import { StoreValue } from "../store/value/store_value";
 
 export function createOutputFun () {
   const writeFunction = async function (store, _) {
-    const totalSV = store.applyStore('p1.0');
+    const totalSV = store.applyStore("p1.0");
     const total = totalSV.get();
     for (let i = 1; i < total; i += 1) {
       const val = store.applyStore(`p1.${i}`);
-      this.output.sendOutput(convertToString(val.get(), val.type));
+      this.output.sendOutput(Parsers.convertToString(val.get(), val.type));
     }
     store.mode = Modes.RETURN;
     return store;
-  }
-  const block = new Commands.CommandBlock([], [new Commands.SysCall(writeFunction)]);
-  const func = new Commands.Function('$write', Types.VOID,
-    [new Commands.FormalParameter(Types.ALL, 'p1', false, true)],
-    block);
+  };
+  const block = new Commands.CommandBlock(
+    [],
+    [new Commands.SysCall(writeFunction)]
+  );
+  const func = new Commands.Function(
+    "$write",
+    Types.VOID,
+    [new Commands.FormalParameter(Types.ALL, "p1", false, true)],
+    block
+  );
   return func;
 }
 
 export function createInputFun () {
   const readFunction = async function (store, _) {
     const text = await this.input.requestInput();
-    const typeToConvert = store.applyStore('p1').type;
-    let type = null
+    const typeToConvert = store.applyStore("p1").type;
+    let type = null;
     let result = null;
     try {
       if (typeToConvert.isCompatible(Types.INTEGER)) {
-        result = toInt(text.trim()).trunc();
+        result = Parsers.toInt(text.trim()).trunc();
         type = Types.INTEGER;
       } else if (typeToConvert.isCompatible(Types.REAL)) {
-        result = toReal(text.trim())
+        result = Parsers.toReal(text.trim());
         type = Types.REAL;
       } else if (typeToConvert.isCompatible(Types.BOOLEAN)) {
-        result = toBool(text.trim())
+        result = Parsers.toBool(text.trim());
         type = Types.BOOLEAN;
       } else if (typeToConvert.isCompatible(Types.STRING)) {
-        result = toString(text)
-        type  = Types.STRING;
+        result = Parsers.toString(text);
+        type = Types.STRING;
+      } else if (typeToConvert.isCompatible(Types.CHAR)) {
+        result = Parsers.toChar(text);
+        type = Types.CHAR;
       } else {
         throw new Error("!!!!Critical error: Unknown type in readFunction!!!!");
       }
     } catch (_) {
-      if(this.mode == Modes.ABORT) {
+      if (this.mode == Modes.ABORT) {
         store.mode = Modes.RETURN;
         return store;
       }
-      const stringInfo = typeToConvert.stringInfo()[0]
+      const stringInfo = typeToConvert.stringInfo()[0];
       const realObject = store.getStoreObject("p1");
       if (realObject.getReferenceDimension() > 0) {
         const arrayInfo = realObject.type.stringInfo()[0];
         const dim = realObject.getReferenceDimension();
-        throw ProcessorErrorFactory.invalid_read_type_array(text, stringInfo.type, stringInfo.dim,
-          realObject.getRefObj(), arrayInfo.type, dim, this.function_call_stack.pop());
+        throw ProcessorErrorFactory.invalid_read_type_array(
+          text,
+          stringInfo.type,
+          stringInfo.dim,
+          realObject.getRefObj(),
+          arrayInfo.type,
+          dim,
+          this.function_call_stack.pop()
+        );
       }
-      throw ProcessorErrorFactory.invalid_read_type(text, stringInfo.type, stringInfo.dim,
-        realObject.getRefObj(), this.function_call_stack.pop());
+      throw ProcessorErrorFactory.invalid_read_type(
+        text,
+        stringInfo.type,
+        stringInfo.dim,
+        realObject.getRefObj(),
+        this.function_call_stack.pop()
+      );
     }
     const stoValue = new StoreValue(type, result);
-    store.updateStore('p1', stoValue);
+    store.updateStore("p1", stoValue);
     store.mode = Modes.RETURN;
     return store;
-  }
-  const block = new Commands.CommandBlock([],  [new Commands.SysCall(readFunction)]);
-  const func = new Commands.Function('$read', Types.VOID,
-    [new Commands.FormalParameter(Types.ALL, 'p1', true)],
-    block);
+  };
+  const block = new Commands.CommandBlock(
+    [],
+    [new Commands.SysCall(readFunction)]
+  );
+  const func = new Commands.Function(
+    "$read",
+    Types.VOID,
+    [new Commands.FormalParameter(Types.ALL, "p1", true)],
+    block
+  );
   return func;
 }

+ 19 - 10
js/typeSystem/parsers.js

@@ -8,21 +8,29 @@ export function toInt (str) {
 }
 
 export function toString (str) {
-  let value = str.replace(/^"/, '');
-  value = value.replace(/"$/, '');
+  let value = str.replace(/^"/, "");
+  value = value.replace(/"$/, "");
   value = value.replace(/\\b/g, "\b");
   value = value.replace(/\\t/g, "\t");
   value = value.replace(/\\n/g, "\n");
   value = value.replace(/\\r/g, "\r");
-  value = value.replace(/\\"/g, "\"");
-  value = value.replace(/\\'/g, '\'');
+  value = value.replace(/\\"/g, '"');
+  value = value.replace(/\\'/g, "'");
   value = value.replace(/\\\\/g, "\\");
   return value;
 }
 
 export function toChar (str) {
-  let value = str.replace(/^'/, '');
-  value = value.replace(/'$/, '');
+  console.debug(str, str.length);
+  let value = str.replace(/^'/, "");
+  value = value.replace(/'$/, "");
+  value = value.replace(/\\b/g, "\b");
+  value = value.replace(/\\t/g, "\t");
+  value = value.replace(/\\n/g, "\n");
+  value = value.replace(/\\r/g, "\r");
+  value = value.replace(/\\"/g, '"');
+  value = value.replace(/\\'/g, "'");
+  value = value[0];
   return value;
 }
 
@@ -53,16 +61,16 @@ export function convertBoolToString (bool) {
   } else {
     result = instance.literalNames[lexer.RK_FALSE];
   }
-  return result.replace(/'/g,"");
+  return result.replace(/'/g, "");
 }
 
-export function convertToString(value, type) {
+export function convertToString (value, type) {
   switch (type.ord) {
     case Types.INTEGER.ord:
       return value.toString();
     case Types.REAL.ord: {
       if (value.dp() <= 0) {
-        return value.toFixed(1);  
+        return value.toFixed(1);
       } else {
         return value.toFixed(Config.decimalPlaces);
       }
@@ -72,4 +80,5 @@ export function convertToString(value, type) {
     default:
       return value;
   }
-}
+}
+

+ 11 - 3
js/visualUI/code_generator.js

@@ -69,7 +69,7 @@ function functionsCode (function_obj) {
     ret += "[][] ";
   }
   if (function_obj.is_main) {
-    ret += LocalizedStrings.getUI('start');
+    ret += LocalizedStrings.getUI("start");
   } else {
     ret += function_obj.name;
   }
@@ -720,8 +720,16 @@ function variableValueMenuCode (variable_obj, is_return = false) {
         ret += " [ " + variableValueMenuCode(variable_obj.column) + " ] ";
       }
     } else {
-      if (isNaN(variable_obj.content)) {
-        ret += '"' + variable_obj.content + '"';
+      const content = String(variable_obj.content);
+      if (isNaN(content)) {
+        // console.debug("Content length: ", content.length);
+        // console.debug("Char code at 0", content.charCodeAt(0));
+        const isBackslash = content.charCodeAt(0) === 92;
+        if (content.length === 1 || (content.length === 2 && isBackslash)) {
+          ret += `'${content}'`;
+        } else {
+          ret += '"' + variable_obj.content + '"';
+        }
       } else {
         ret += variable_obj.content;
       }

File diff suppressed because it is too large
+ 1812 - 1139
js/visualUI/commands/variable_value_menu.js