Jelajahi Sumber

Update 'src/app/core/parser/file-parser.js'

Fixing midpoint object MiddlePoint: now constructing only one geometric object.
Indentation adjusts: inserted space in all function/method declaration (before open parenthesis) to distinguish it from its use.
Inserted one "console.log" to help in debug process.
leo 2 tahun lalu
induk
melakukan
cfdaae04d0
1 mengubah file dengan 26 tambahan dan 24 penghapusan
  1. 26 24
      src/app/core/parser/file-parser.js

+ 26 - 24
src/app/core/parser/file-parser.js

@@ -11,22 +11,20 @@ const HIDDEN = 7; // 0 (visivel) ou 1 (escondido)
 const PIXEL = 8; // LeScript usa (coordenada X e Y - inteiros)
 const FONT = 9; // 'Arial' T Tam: T = FONT.PLAIN, FONT.BOLD, FONT.ITALIC; Tam = 8, 9,...
 // PROIBIDO: "Arial" T Tam, pois em caso contrario nao sera lido como parametro
-//           usa  MARCAFNT = "\'" nao pode ser "\"" <[28/09/2006] agora vazio "">
+//           usar MARCAFNT = "\'" nao pode ser "\"" <[28/09/2006] agora vazio "">
 const LABEL_COLOR = 10; // cor de rotulo (tambem um inteiro) - inserido apos iGeom versao >= 2.9.9.31
 
 const OBJECT_LINE_REGEX = /^\{\w*(?:(?:\d+:@\|[^@]+@\|)|(?:\d+:[^,@|]+))\w(?:,\w*(?:(?:\d+:@\|[^@]+@\|)|(?:\d+:[^,@\|]+)))+\w*\}!?$/.compile();
 const ALPHA_MASK = 255 << 24;
 
 export class FileParser {
-  /**
-   *
-   * @param {string} content
-   */
-  constructor(content) {
+
+  // @param {string} content
+  constructor (content) {
     this.content = content;
-  }
+    }
 
-  parse() {
+  parse () {
     return this.content
       .split("\n")
       .filter(str => !str.match(/^[#\[]/))
@@ -34,23 +32,20 @@ export class FileParser {
         if (!OBJECT_LINE_REGEX.test(str.trim())) {
           console.error("Malformed object string in igeom file: ", str);
           return undefined;
-        }
+          }
         return this.parseObjectLine(str.trim());
-      });
-  }
+        });
+    }
 
-  /**
-   *
-   * @param {string} object_line
-   */
-  parseObjectLine(object_line) {
+  // @param {string} object_line
+  parseObjectLine (object_line) {
     const map = new Map();
     object_line = object_line.substring(1);
     if (object_line.endsWith("}!")) {
       object_line = object_line.substring(0, object_line.length - 2);
     } else {
       object_line = object_line.substring(0, object_line.length - 1);
-    }
+      }
     const properties = object_line.split(",");
     for (const index in properties) {
       const prop = properties[index];
@@ -64,17 +59,23 @@ export class FileParser {
         const id = prop_info[1];
         map.set("id", parseInt(id));
       } else if (key == DEFINITION) {
+var aux = "";
         const param_list = [];
         const list = prop_info[1].trim().split(" ");
+aux += "#prop_info[1]=" + list.length + ", ";
+var ii=0;       
         for (const i in list) {
           const param = list[i];
           const maybe_number = Number(param);
+aux += "(" + ii + "," + param + ", " + maybe_number + "); ";
+ii++;
           if (Number.isNaN(maybe_number)) {
             param_list.push(param);
           } else {
             param_list.push(maybe_number);
+            }
           }
-        }
+console.log("file-parser.js: DEFINITION: " + aux);
         map.set("param", param_list);
       } else if (key == LIST) {
         const id_list = [];
@@ -82,7 +83,7 @@ export class FileParser {
         for (const i in list) {
           const id = list[i];
           id_list.push(id);
-        }
+          }
         map.set("deps", id_list);
       } else if (key == LABEL) {
         const param_list = [];
@@ -94,8 +95,8 @@ export class FileParser {
             param_list.push(param);
           } else {
             param_list.push(maybe_number);
+            }
           }
-        }
         map.set("label", param_list);
       } else if (key == DEFINED) {
         const value = prop_info[1];
@@ -118,7 +119,7 @@ export class FileParser {
         for (const index in list) {
           const i = list[index];
           position.push(parseInt(i));
-        }
+          }
         map.set("position", position);
       } else if (key == FONT) {
         const param_list = prop_info[1].trim().split(" ");
@@ -132,9 +133,10 @@ export class FileParser {
         const g = (number >> 8) & 0xff;
         const b = number & 0xff;
         map.set("label_color", { alpha: alpha, r: r, g: g, b: b });
+        }
       }
-    }
 
     return map;
-  }
-}
+    }
+
+  }