Parcourir la source

Just Demo files

Lucas de Souza il y a 5 ans
Parent
commit
2c7e93c425
5 fichiers modifiés avec 178 ajouts et 210 suppressions
  1. 35 3
      index.html
  2. 116 0
      js/jquery.json-editor.min.js
  3. 0 47
      js/json-viewer/jquery.json-viewer.css
  4. 0 148
      js/json-viewer/jquery.json-viewer.js
  5. 27 12
      js/main.js

+ 35 - 3
index.html

@@ -1,13 +1,45 @@
 <!DOCTYPE html>
 <html>
 <head>
-  <link rel="stylesheet" href="js/json-viewer/jquery.json-viewer.css">
+  <link rel="stylesheet" type="text/css" href="js/semantic/semantic.min.css">
   <title></title>
 </head>
 <body>
-  <pre id="json-renderer"></pre>
+    <div style="padding-top: 50px;content: ''"></div>
+  <div class="ui container grid">
+    
+    <div class="four wide column">
+      <div class="row">
+        <textarea class="ui form control" name="input" id="input" cols="100" rows="30">
+            programa {
+
+              const real C = 5.5
+             
+              funcao inteiro inicio() {
+               inteiro a = 8
+               se (a * C > 80) {
+                a = 0
+               } senao {
+                 a = -1
+               }
+              }
+             }
+        </textarea>
+      </div>
+      <div class="row">
+          <button class="ui button" id="btn">Generate AST</button>
+      </div>
+    </div>
+    <div class="six wide column">
+      <div style="overflow-y: scroll; height: 20%;">
+          <pre id="json-renderer" class="ui right floated"></pre>
+      </div>
+    </div>
+  </div>
+  
+  
 </body>
 <script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
-<script type="text/javascript" src="js/json-viewer/jquery.json-viewer.js"></script>
+<script type="text/javascript" src="js/jquery.json-editor.min.js"></script>
 <script type="text/javascript" src="build/ivprog.bundle.js"></script>
 </html>

Fichier diff supprimé car celui-ci est trop grand
+ 116 - 0
js/jquery.json-editor.min.js


+ 0 - 47
js/json-viewer/jquery.json-viewer.css

@@ -1,47 +0,0 @@
-/* Syntax highlighting for JSON objects */
-ul.json-dict, ol.json-array {
-  list-style-type: none;
-  margin: 0 0 0 1px;
-  border-left: 1px dotted #ccc;
-  padding-left: 2em;
-}
-.json-string {
-  color: #0B7500;
-}
-.json-literal {
-  color: #1A01CC;
-  font-weight: bold;
-}
-
-/* Toggle button */
-a.json-toggle {
-  position: relative;
-  color: inherit;
-  text-decoration: none;
-}
-a.json-toggle:focus {
-  outline: none;
-}
-a.json-toggle:before {
-  color: #aaa;
-  content: "\25BC"; /* down arrow */
-  position: absolute;
-  display: inline-block;
-  width: 1em;
-  left: -1em;
-}
-a.json-toggle.collapsed:before {
-  transform: rotate(-90deg); /* Use rotated down arrow, prevents right arrow appearing smaller than down arrow in some browsers */
-  -ms-transform: rotate(-90deg);
-  -webkit-transform: rotate(-90deg);
-}
-
-/* Collapsable placeholder links */
-a.json-placeholder {
-  color: #aaa;
-  padding: 0 1em;
-  text-decoration: none;
-}
-a.json-placeholder:hover {
-  text-decoration: underline;
-}

+ 0 - 148
js/json-viewer/jquery.json-viewer.js

@@ -1,148 +0,0 @@
-/**
- * jQuery json-viewer
- * @author: Alexandre Bodelot <alexandre.bodelot@gmail.com>
- */
-(function($){
-
-  /**
-   * Check if arg is either an array with at least 1 element, or a dict with at least 1 key
-   * @return boolean
-   */
-  function isCollapsable(arg) {
-    return arg instanceof Object && Object.keys(arg).length > 0;
-  }
-
-  /**
-   * Check if a string represents a valid url
-   * @return boolean
-   */
-  function isUrl(string) {
-     var regexp = /^(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
-     return regexp.test(string);
-  }
-
-  /**
-   * Transform a json object into html representation
-   * @return string
-   */
-  function json2html(json, options) {
-    var html = '';
-    if (typeof json === 'string') {
-      /* Escape tags */
-      json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
-      if (isUrl(json))
-        html += '<a href="' + json + '" class="json-string">' + json + '</a>';
-      else
-        html += '<span class="json-string">"' + json + '"</span>';
-    }
-    else if (typeof json === 'number') {
-      html += '<span class="json-literal">' + json + '</span>';
-    }
-    else if (typeof json === 'boolean') {
-      html += '<span class="json-literal">' + json + '</span>';
-    }
-    else if (json === null) {
-      html += '<span class="json-literal">null</span>';
-    }
-    else if (json instanceof Array) {
-      if (json.length > 0) {
-        html += '[<ol class="json-array">';
-        for (var i = 0; i < json.length; ++i) {
-          html += '<li>';
-          /* Add toggle button if item is collapsable */
-          if (isCollapsable(json[i])) {
-            html += '<a href class="json-toggle"></a>';
-          }
-          html += json2html(json[i], options);
-          /* Add comma if item is not last */
-          if (i < json.length - 1) {
-            html += ',';
-          }
-          html += '</li>';
-        }
-        html += '</ol>]';
-      }
-      else {
-        html += '[]';
-      }
-    }
-    else if (typeof json === 'object') {
-      var key_count = Object.keys(json).length;
-      if (key_count > 0) {
-        html += '{<ul class="json-dict">';
-        for (var key in json) {
-          if (json.hasOwnProperty(key)) {
-            html += '<li>';
-            var keyRepr = options.withQuotes ?
-              '<span class="json-string">"' + key + '"</span>' : key;
-            /* Add toggle button if item is collapsable */
-            if (isCollapsable(json[key])) {
-              html += '<a href class="json-toggle">' + keyRepr + '</a>';
-            }
-            else {
-              html += keyRepr;
-            }
-            html += ': ' + json2html(json[key], options);
-            /* Add comma if item is not last */
-            if (--key_count > 0)
-              html += ',';
-            html += '</li>';
-          }
-        }
-        html += '</ul>}';
-      }
-      else {
-        html += '{}';
-      }
-    }
-    return html;
-  }
-
-  /**
-   * jQuery plugin method
-   * @param json: a javascript object
-   * @param options: an optional options hash
-   */
-  $.fn.jsonViewer = function(json, options) {
-    options = options || {};
-
-    /* jQuery chaining */
-    return this.each(function() {
-
-      /* Transform to HTML */
-      var html = json2html(json, options);
-      if (isCollapsable(json))
-        html = '<a href class="json-toggle"></a>' + html;
-
-      /* Insert HTML in target DOM element */
-      $(this).html(html);
-
-      /* Bind click on toggle buttons */
-      $(this).off('click');
-      $(this).on('click', 'a.json-toggle', function() {
-        var target = $(this).toggleClass('collapsed').siblings('ul.json-dict, ol.json-array');
-        target.toggle();
-        if (target.is(':visible')) {
-          target.siblings('.json-placeholder').remove();
-        }
-        else {
-          var count = target.children('li').length;
-          var placeholder = count + (count > 1 ? ' items' : ' item');
-          target.after('<a href class="json-placeholder">' + placeholder + '</a>');
-        }
-        return false;
-      });
-
-      /* Simulate click on toggle button when placeholder is clicked */
-      $(this).on('click', 'a.json-placeholder', function() {
-        $(this).siblings('a.json-toggle').click();
-        return false;
-      });
-
-      if (options.collapsed == true) {
-        /* Trigger click to collapse all nodes */
-        $(this).find('a.json-toggle').click();
-      }
-    });
-  };
-})(jQuery);

+ 27 - 12
js/main.js

@@ -2,6 +2,7 @@ import {
     InputStream,
     CommonTokenStream
 } from 'antlr4/index';
+import * as Commands from './ast/commands';
 import { IVProgParser } from './ast/ivprogParser';
 import Lexers from '../grammar/';
 
@@ -11,18 +12,20 @@ const ivprogLexer = Lexers[lang];
 
 const input = `programa {
 
-  const real PI = 5.5
-  inteiro V = -10*2
+  const real C = 6.8-5.8+1
+             
+  funcao abc() {
+     inteiro a = 8
+     se (a * C > 80) {
+        a = 0
+     } senao se(verdadeiro) {
+        a = -1
+       fun()
+     }
+  }
 
-  funcao inteiro test(real i) {
-    escolha (i) {
-      caso 1:
-        i = i + 5
-        retorne i
-      caso contrario:
-        i =  i * 2 + 3
-        retorne i
-    }
+  funcao real fun() {
+    retorne 3
   }
 }`;
 
@@ -40,7 +43,19 @@ const anaSin = new IVProgParser(input, ivprogLexer);
 try {
   const data = anaSin.parseTree();
   console.log(data);
-  $('#json-renderer').jsonViewer(data);
+  var editor = new JsonEditor('#json-renderer', data);
+  $('#btn').click( () => {
+    const input = $('#input').val();
+    const analiser = new IVProgParser(input, ivprogLexer);
+    try {
+      const data = analiser.parseTree();
+      console.log(data);
+      editor.load(data);  
+    } catch (error) {
+      alert(error);
+    }
+    
+  });
 } catch(a) {
   console.log(a);
 }