소스 검색

Merge branch 'fixLang' of LInE/ivprog into master

Lucas de Souza 5 년 전
부모
커밋
c741178ea8

+ 1 - 1
js/ast/expressions/arrayLiteral.js

@@ -25,7 +25,7 @@ export class ArrayLiteral extends Literal {
     if (!(element instanceof ArrayLiteral)){
       return null;
     } else {
-      return element.value[0].value.length;
+      return element.value[0].length;
     }
   }
 

+ 8 - 9
js/processor/ivprogProcessor.js

@@ -86,21 +86,20 @@ export class IVProgProcessor {
 
   interpretAST () {
     this.prepareState();
-    this.initGlobal();
-    const mainFunc = this.findMainFunction();
-    if(mainFunc === null) {
-      throw ProcessorErrorFactory.main_missing();
-    }
-    return this.runFunction(mainFunc, [], this.globalStore);
+    return this.initGlobal().then( _ => {
+      const mainFunc = this.findMainFunction();
+      if(mainFunc === null) {
+        throw ProcessorErrorFactory.main_missing();
+      }
+      return this.runFunction(mainFunc, [], this.globalStore);
+    });
   }
 
   initGlobal () {
     if(!this.checkContext(Context.BASE)) {
       throw ProcessorErrorFactory.invalid_global_var();
     }
-    this.ast.global.forEach(decl => {
-      this.executeCommand(this.globalStore, decl).then(sto => this.globalStore = sto);
-    });
+    return this.executeCommands(this.globalStore, this.ast.global);
   }
 
   findMainFunction () {

+ 0 - 1
js/processor/store/store.js

@@ -18,7 +18,6 @@ export class Store {
       if (this.nextStore !== null) {
         return this.nextStore.applyStore(id);
       } else {
-        // TODO: better error message
         throw new Error(`Variable ${id} not found.`);
       }
     }

+ 2 - 4
js/services/languageService.js

@@ -1,13 +1,11 @@
 import Lexers from './../../grammar/';
 import line_i18n from 'line-i18n';
-
-// This is for LanguageService with localStorage
-const DEFAULT_LANG = "pt";
+import { Config } from "./../util/config";
 
 class LanguageServiceExtended extends line_i18n.LanguageServiceNoLS {
 
   constructor () {
-    super(DEFAULT_LANG);
+    super(typeof(iLMparameters) === 'undefined' ? Config.default_lang : iLMparameters.lang);
   }
 
   getCurrentLexer () {

+ 1 - 0
js/util/config.js

@@ -4,6 +4,7 @@ class ConfigObject {
     this.loopTimeout = 5000;
     this.decimalPlaces = 5;
     this.intConvertRoundMode = 2;
+    this.default_lang = 'pt';
   }
 
   setConfig (opts) {

+ 3 - 5
tests/test39.spec.js

@@ -1,10 +1,8 @@
 import { LanguageService } from './../js/services/languageService';
 describe('LanguageService.getLang() ', function () {
-  beforeEach(() => {
-    localStorage.setItem('ivprog.lang', 'pt_br');
-  });
-  it("should return the value associated to the key ivprog.lang, inside localStorage", function () {
+  LanguageService.setLang('pt_br');
+  it("should return the value passed as parameter to LanguageService.setLang()", function () {
     expect(LanguageService.getLang()).toEqual('pt_br');
   });
-  afterEach(() => localStorage.removeItem('ivprog.lang'));
+  afterEach(() => LanguageService.setLang('pt'));
 });

+ 8 - 4
tests/test40.spec.js

@@ -5,8 +5,12 @@ import { LanguageService } from '../js/services/languageService';
 
 describe('The LanguageService', function () {
 
-  beforeEach( () => {
-    localStorage.setItem('ivprog.lang', 'en');  
+  beforeAll( () => {
+    
+  });
+
+  afterAll(function () {
+    
   });
 
   const code = `program {
@@ -18,7 +22,7 @@ describe('The LanguageService', function () {
   }`;
 
   const output = new OutputTest();
-  localStorage.setItem('ivprog.lang', 'en');
+  LanguageService.setLang('en');
   const lexer = LanguageService.getCurrentLexer();
 
   it(`should provide the appropriate lexer`, function (done) {
@@ -27,7 +31,7 @@ describe('The LanguageService', function () {
     exec.registerOutput(output);
     exec.interpretAST().then(sto => {
       expect(output.list).toEqual(['8.01']);
-      localStorage.removeItem('ivprog.lang');
+      LanguageService.setLang('pt');
       done();
     }).catch( err => done(err));
   });

+ 32 - 0
tests/testMatrixGlobal.spec.js

@@ -0,0 +1,32 @@
+import { IVProgParser } from './../js/ast/ivprogParser';
+import { IVProgProcessor} from './../js/processor/ivprogProcessor'
+import { SemanticAnalyser } from "./../js/processor/semantic/semanticAnalyser";
+import { LanguageService } from '../js/services/languageService';
+import { OutputTest } from '../js/util/outputTest';
+
+describe('A global matrix variable',function () {
+  let input = `programa { 
+    inteiro nova_global_0 [4][4] = {{1,1,1,1},{1,1,1,1},{1,1,1,1},{1,1,1,1}}
+
+    funcao vazio inicio (  )  {
+      escreva ( nova_global_0 [ 0 ]  [ 0 ]  ) 
+    }
+
+  }`
+
+  const lexer = LanguageService.getCurrentLexer();
+  const out = new OutputTest();
+
+  it(`should not throw an exception`, function (done) {
+    const parser = new IVProgParser(input, lexer);
+    const semantic = new SemanticAnalyser(parser.parseTree());
+    const exec = new IVProgProcessor(semantic.analyseTree());
+    exec.registerOutput(out);
+    exec.interpretAST().then(_ => {
+      expect(out.list.length).toEqual(1);
+      done();
+    }).catch(err => {
+      done(err);
+    });
+  });
+});

+ 0 - 1
tests/testMatrixSemantic.spec.js

@@ -1,5 +1,4 @@
 import { IVProgParser } from './../js/ast/ivprogParser';
-import { IVProgProcessor} from './../js/processor/ivprogProcessor'
 import { SemanticAnalyser } from "./../js/processor/semantic/semanticAnalyser";
 import { LanguageService } from '../js/services/languageService';