Browse Source

EditorMode with auto indent

Lucas de Souza 5 years ago
parent
commit
40747f7ff8

+ 1 - 0
js/ast/ivprogParser.js

@@ -95,6 +95,7 @@ export class IVProgParser {
   }
   }
 
 
   parseProgram () {
   parseProgram () {
+    this.consumeNewLines();
     const token = this.getToken();
     const token = this.getToken();
     let globalVars = [];
     let globalVars = [];
     let functions = [];
     let functions = [];

+ 3 - 1
js/processor/semantic/semanticAnalyser.js

@@ -467,8 +467,10 @@ export class SemanticAnalyser {
       }
       }
       if(cmd.ifFalse instanceof IfThenElse) {
       if(cmd.ifFalse instanceof IfThenElse) {
         return this.checkCommands(type, cmd.ifTrue.commands, optional) && this.checkCommand(type, cmd.ifFalse, optional);
         return this.checkCommands(type, cmd.ifTrue.commands, optional) && this.checkCommand(type, cmd.ifFalse, optional);
-      } else {
+      } else if(cmd.ifFalse != null) {
         return this.checkCommands(type, cmd.ifTrue.commands, optional) && this.checkCommands(type, cmd.ifFalse.commands,optional);
         return this.checkCommands(type, cmd.ifTrue.commands, optional) && this.checkCommands(type, cmd.ifFalse.commands,optional);
+      } else {
+        return this.checkCommands(type, cmd.ifTrue.commands, optional);
       }
       }
 
 
     } else if (cmd instanceof FunctionCall) {
     } else if (cmd instanceof FunctionCall) {

+ 5 - 1
js/visualUI/text_editor.js

@@ -1,8 +1,10 @@
 import * as CodeMirror from "codemirror";
 import * as CodeMirror from "codemirror";
 import "codemirror/addon/edit/closebrackets";
 import "codemirror/addon/edit/closebrackets";
 import "codemirror/addon/edit/matchbrackets";
 import "codemirror/addon/edit/matchbrackets";
-import "codemirror/addon/edit/matchbrackets";
+// import "codemirror/addon/hint/show-hint";
+// import "codemirror/addon/hint/anyword-hint";
 import "codemirror/addon/selection/active-line";
 import "codemirror/addon/selection/active-line";
+import "./../util/editorMode2"
 
 
 let codeEditor = null;
 let codeEditor = null;
 
 
@@ -13,6 +15,8 @@ export function initTextEditor (element) {
   }
   }
   codeEditor = CodeMirror.fromTextArea(document.getElementById(id), {
   codeEditor = CodeMirror.fromTextArea(document.getElementById(id), {
     value: "",
     value: "",
+    mode: "text/x-ivprog",
+    indentUnit: 4,
     lineNumbers: true,
     lineNumbers: true,
     matchBrackets: true,
     matchBrackets: true,
     autoCloseBrackets: true,
     autoCloseBrackets: true,

+ 9 - 2
templates/index.html

@@ -8,6 +8,7 @@
     <link rel="stylesheet" type="text/css" href="css/ivprog-visual-1.0.css">
     <link rel="stylesheet" type="text/css" href="css/ivprog-visual-1.0.css">
     <link rel="stylesheet" type="text/css" href="css/ivprog-term.css">
     <link rel="stylesheet" type="text/css" href="css/ivprog-term.css">
     <link rel="stylesheet" type="text/css" href="css/codemirror.css">
     <link rel="stylesheet" type="text/css" href="css/codemirror.css">
+    <link rel="stylesheet" type="text/css" href="css/show-hint.css">
     <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
     <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
     <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"
     <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"
       integrity="sha256-KM512VNnjElC30ehFwehXjx1YCHPiQkOPmqnrWtpccM="
       integrity="sha256-KM512VNnjElC30ehFwehXjx1YCHPiQkOPmqnrWtpccM="
@@ -15,6 +16,11 @@
     <script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.0/semantic.min.js" integrity="sha256-x1fC6BXl6BwnUhfQqqqC0Fd/n12wH+u8u9va6+E7xaA=" crossorigin="anonymous"></script>
     <script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.0/semantic.min.js" integrity="sha256-x1fC6BXl6BwnUhfQqqqC0Fd/n12wH+u8u9va6+E7xaA=" crossorigin="anonymous"></script>
     <script src="js/Sortable.js"></script>
     <script src="js/Sortable.js"></script>
     <script src="js/iassign-integration-functions.js"></script>
     <script src="js/iassign-integration-functions.js"></script>
+    <style>
+      .CodeMirror {
+        height: 100% !important;
+      }
+    </style>
   </head>
   </head>
   <body>
   <body>
 
 
@@ -74,7 +80,8 @@
 
 
               <i class="icons">
               <i class="icons">
                 <i class="icon superscript" style="margin-top: -2px;margin-bottom: 2px;margin-left: 1px;margin-right: 1px; font-size: 18px;"></i>
                 <i class="icon superscript" style="margin-top: -2px;margin-bottom: 2px;margin-left: 1px;margin-right: 1px; font-size: 18px;"></i>
-                <i class="corner add icon inverted" style="font-size: 10px;padding-top: 5px;padding-left: 7px;"></i>
+                <i class="cor
+                ner add icon inverted" style="font-size: 10px;padding-top: 5px;padding-left: 7px;"></i>
               </i>
               </i>
               
               
             </div>
             </div>
@@ -98,7 +105,7 @@
 
 
 
 
         <div class="ui one column container segment ivprog_textual_panel loading" style="display: none;">
         <div class="ui one column container segment ivprog_textual_panel loading" style="display: none;">
-          <textarea id="ivprog-text-editor" class=".ivprog_textual_code" rows="20" cols="35"></textarea>
+          <textarea id="ivprog-text-editor" class=".ivprog_textual_code"></textarea>
         </div>
         </div>
         <div id='ivprog-term-div' class="six column wide">
         <div id='ivprog-term-div' class="six column wide">
           
           

+ 1 - 0
webpack.config.js

@@ -63,6 +63,7 @@ module.exports = {
         {from: 'img/trash-icon.png', to:path.resolve(__dirname, 'build/img')},
         {from: 'img/trash-icon.png', to:path.resolve(__dirname, 'build/img')},
         {from:'js/jquery.json-editor.min.js', to:path.resolve(__dirname, 'build/js')},
         {from:'js/jquery.json-editor.min.js', to:path.resolve(__dirname, 'build/js')},
         {from:'node_modules/codemirror/lib/codemirror.css', to:path.resolve(__dirname, 'build/css')},
         {from:'node_modules/codemirror/lib/codemirror.css', to:path.resolve(__dirname, 'build/css')},
+        {from:'node_modules/codemirror/addon/hint/show-hint.css', to:path.resolve(__dirname, 'build/css')},
         /*{from:'index.html', to:path.resolve(__dirname, 'build')},
         /*{from:'index.html', to:path.resolve(__dirname, 'build')},
         {from:'runner.html', to:path.resolve(__dirname, 'build')},*/
         {from:'runner.html', to:path.resolve(__dirname, 'build')},*/
       ])
       ])