Browse Source

Fix missing rule for array initialization

Lucas de Souza 4 years ago
parent
commit
7d0fbcdbdc
1 changed files with 15 additions and 10 deletions
  1. 15 10
      js/ast/ivprogParser.js

+ 15 - 10
js/ast/ivprogParser.js

@@ -109,7 +109,7 @@ export class IVProgParser {
       this.checkOpenCurly();
       this.pos++;
       this.pushVariableStack();
-      while(true) {
+      for(;;) {
         this.consumeNewLines();
         const token = this.getToken();
         if (token.type === this.lexerClass.RK_CONST || this.isVariableType(token)) {
@@ -467,12 +467,16 @@ export class IVProgParser {
   getBoolLiteral (token) {
     const val = toBool(token.text);
     const exp = new Expressions.BoolLiteral(val);
-    exp.sourceInfo = SourceInfo.createSourceInfo(token);;
+    exp.sourceInfo = SourceInfo.createSourceInfo(token);
     return exp;
   }
 
   parseArrayLiteral (typeString) {
-    this.checkOpenCurly();
+    const openCurly = this.checkOpenCurly(true);
+    if(!openCurly) {
+      // const invalid_token = this.getToken();
+      throw new Error("Array can only be init with a literal");
+    }
     const beginArray = this.getToken();
     if (this.parsingArrayDimension >= 2) {
       // TODO better message
@@ -513,7 +517,7 @@ export class IVProgParser {
   parseVectorList (typeString) {
     let list = [];
     let lastSize = null;
-    while(true) {
+    for(;;) {
       this.checkOpenCurly();
       const beginArray = this.getToken();
       if (this.parsingArrayDimension >= 2) {
@@ -630,7 +634,7 @@ export class IVProgParser {
   **/
   parseFormalParameters () {
     const list = [];
-    while(true) {
+    for(;;) {
       let dimensions = 0;
       const typeString = this.parseType();
       const idToken = this.getToken();
@@ -723,7 +727,7 @@ export class IVProgParser {
     }
     this.consumeNewLines();
     let parsedCommand =  false;
-    while(true) {
+    for(;;) {
 
       const cmd = this.parseCommand();
       if (cmd === null)
@@ -1164,11 +1168,12 @@ export class IVProgParser {
   parseTerm () {
     const token = this.getToken();
     let sourceInfo = null;
+    let exp = null;
     switch(token.type) {
       case this.lexerClass.SUM_OP:
         this.pos++;
         sourceInfo = SourceInfo.createSourceInfo(token);
-        const exp = new Expressions.UnaryApp(convertFromString(token.text), this.parseTerm());
+        exp = new Expressions.UnaryApp(convertFromString(token.text), this.parseTerm());
         exp.sourceInfo = sourceInfo;
         return exp;
       case this.lexerClass.INTEGER:
@@ -1266,14 +1271,14 @@ export class IVProgParser {
   parseParenthesisExp () {
     this.checkOpenParenthesis();
     const tokenA = this.getToken();
-    this.pos++;
+    this.pos += 1;
     this.consumeNewLines();
     const exp = this.parseExpressionOR();
     this.consumeNewLines();
     this.checkCloseParenthesis();
     const tokenB = this.getToken();
     const sourceInfo = SourceInfo.createSourceInfoFromList(tokenA, tokenB);
-    this.pos++;
+    this.pos += 1;
     exp.sourceInfo = sourceInfo;
     return exp;
   }
@@ -1295,7 +1300,7 @@ export class IVProgParser {
 
   parseExpressionList () {
     const list = [];
-    while(true) {
+    for(;;) {
       const exp = this.parseExpressionOR();
       list.push(exp);
       const maybeToken = this.getToken();