Skip to content

Commit ad2fd12

Browse files
committed
fix linter errors
1 parent 7af735c commit ad2fd12

File tree

7 files changed

+109
-17
lines changed

7 files changed

+109
-17
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ before_install:
1414
fi
1515

1616
install:
17-
- TRAVIS_NODE_VERSION="6";
17+
- TRAVIS_NODE_VERSION="7";
1818
# Clear out whatever version of NVM Travis has as it is old.
1919
- rm -rf ~/.nvm;
2020
# Grab NVM.
@@ -23,8 +23,8 @@ install:
2323
# Note that you can just hardcode a preferred version here.
2424
- (cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`);
2525
# Install the desired version of Node
26-
- source ~/.nvm/nvm.sh;
27-
- nvm install $TRAVIS_NODE_VERSION;
26+
- source ~/.nvm/nvm.sh;
27+
- nvm install $TRAVIS_NODE_VERSION;
2828
- npm install
2929
- npm run vscode:prepublish
3030

src/extension.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,24 @@
22
import * as vscode from 'vscode';
33

44
import FortranLintingProvider from './features/linter-provider';
5-
import FortranHoverProvider from "./features/hover-provider";
6-
import { FortranCompletionProvider } from "./features/completion-provider";
7-
import { FortranDocumentSymbolProvider } from "./features/document-symbol-provider";
5+
import FortranHoverProvider from './features/hover-provider';
6+
import { FortranCompletionProvider } from './features/completion-provider';
7+
import { FortranDocumentSymbolProvider } from './features/document-symbol-provider';
88

99
export function activate(context: vscode.ExtensionContext) {
1010

1111
let hoverProvider = new FortranHoverProvider();
1212
let completionProvider = new FortranCompletionProvider();
1313
let symbolProvider = new FortranDocumentSymbolProvider();
1414

15-
if (vscode.workspace.getConfiguration("fortran").get("linterEnabled", true)) {
15+
if (vscode.workspace.getConfiguration('fortran').get('linterEnabled', true)) {
1616

1717
let linter = new FortranLintingProvider();
1818
linter.activate(context.subscriptions);
1919
vscode.languages.registerCodeActionsProvider('fortran90', linter);
2020
}
2121

22-
vscode.languages.registerCompletionItemProvider("fortran90", completionProvider)
22+
vscode.languages.registerCompletionItemProvider('fortran90', completionProvider);
2323
vscode.languages.registerHoverProvider('fortran90', hoverProvider);
24-
vscode.languages.registerDocumentSymbolProvider("fortran90", symbolProvider);
25-
24+
vscode.languages.registerDocumentSymbolProvider('fortran90', symbolProvider);
2625
}

src/lib/tokenizer.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
2+
3+
4+
export enum TokenType {
5+
FUNCTION,
6+
SUBROUTINE,
7+
NUMBER,
8+
VARIABLE,
9+
END,
10+
DO,
11+
IF,
12+
LEFT_PARENTESIS,
13+
RIGHT_PARENTESIS,
14+
COMMA,
15+
BINARY_OPERATOR
16+
}
17+
18+
19+
export interface TokenInfo {
20+
21+
pattern: RegExp;
22+
token: TokenType;
23+
24+
}
25+
export interface Token {
26+
token: TokenType;
27+
sequence: string;
28+
29+
}
30+
export class Tokenizer {
31+
32+
tokenInfos: TokenInfo[];
33+
public tokens: Token[];
34+
constructor(){
35+
this.tokenInfos = [];
36+
this.tokens = [];
37+
}
38+
public add(regex, token){
39+
this.tokenInfos.push({pattern:regex, token: token});
40+
}
41+
public tokenize(expression:string){
42+
this.tokens = [];
43+
while(expression !== ''){
44+
let match = false;
45+
for(let i = 0; i < this.tokenInfos.length; i++){
46+
let info = this.tokenInfos[i];
47+
let result = info.pattern.exec(expression);
48+
console.log(expression);
49+
if(result && result.length > 0){
50+
match = true;
51+
this.tokens.push({token: info.token, sequence: result[0].trim()});
52+
expression = expression.replace(info.pattern,"");
53+
break;
54+
}
55+
}
56+
}
57+
58+
}
59+
60+
}

test/extension.test.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,14 @@ import * as vscode from 'vscode';
1414
import * as myExtension from '../src/extension';
1515

1616
// Defines a Mocha test suite to group tests of similar kind together
17-
suite("Extension Tests", () => {
17+
suite('Extension Tests', () => {
1818

1919
// Defines a Mocha unit test
20-
test("Something 1", () => {
20+
test('Something 1', () => {
2121
assert.equal(-1, [1, 2, 3].indexOf(5));
2222
assert.equal(-1, [1, 2, 3].indexOf(0));
2323
});
2424

25-
26-
27-
2825
});
2926

3027

test/helper.test.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,43 @@ suite("function helper test", () => {
1313
test("validVariableName does not allow variables starting with number", () => {
1414
assert.equal(false, validVariableName("1as"));
1515
});
16+
1617
test("validVariableName returns true with correct variable", () => {
1718
assert.equal(true, validVariableName("matA"));
1819
});
20+
1921
test("validVariableName returns true for variables starting with uppercase", () => {
2022
assert.equal(true, validVariableName("MatA"));
2123
});
24+
2225
test("validVariableName return true for variable starting with _", () => {
2326
assert.equal(true, validVariableName("_matA"));
2427
});
28+
2529
test("parseFuntion return undefined on empty line", () => {
2630
assert.equal(undefined, parseFunction(""));
2731
});
32+
2833
test("parseFuntion return undefined if function keyword is missing", () => {
2934
assert.equal(undefined, parseFunction("hello"));
3035
});
36+
3137
test("parseFuntion return correct function name", () => {
3238
assert.equal("hello", parseFunction("function hello()").name);
3339
});
3440

3541
test("parseFuntion return correct number of args", () => {
3642
assert.equal(2, parseFunction("function hello( a, b)").args.length);
3743
});
44+
3845
test("parseArgs return the correct number of args", () => {
3946
assert.equal(2, parseArgs("a,b").length);
40-
})
47+
});
48+
4149
test("parseArgs handle spaces well", () => {
4250
assert.equal(2, parseArgs(" a, b").length);
4351
});
52+
4453
test("parseArgs handle empty args", () => {
4554
assert.equal(0, parseArgs("").length);
4655
});

test/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// to report the results back to the caller. When the tests are finished, return
1111
// a possible error to the callback or null if none.
1212

13-
var testRunner = require('vscode/lib/testrunner');
13+
let testRunner = require('vscode/lib/testrunner');
1414

1515
// You can directly control Mocha options by uncommenting the following lines
1616
// See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info

test/tokenizer.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
// The module 'assert' provides assertion methods from node
3+
import * as assert from 'assert';
4+
import * as fs from 'fs';
5+
import { Tokenizer, TokenType } from '../src/lib/tokenizer';
6+
7+
suite("function helper test", () => {
8+
9+
test("sample test", () => {
10+
let tokenizer = new Tokenizer();
11+
tokenizer.add(/^function\s*/, TokenType.FUNCTION );
12+
tokenizer.add(/^subroutine\s*/, TokenType.SUBROUTINE );
13+
tokenizer.add(/^if\s*/, TokenType.IF);
14+
tokenizer.add(/^do\s*/, TokenType.DO);
15+
tokenizer.add(/^end\s*/, TokenType.END );
16+
tokenizer.add(/^[0-9]+\s*/, TokenType.NUMBER); // number
17+
tokenizer.add(/^[a-zA-Z_]+[a-zA-Z0-9_]*\s*/, TokenType.VARIABLE ); // variable
18+
tokenizer.add(/^\(\s*/, TokenType.LEFT_PARENTESIS); // left parentesis
19+
tokenizer.add(/^\)\s*/, TokenType.RIGHT_PARENTESIS); // right parentesis
20+
tokenizer.add(/^,\s*/, TokenType.COMMA); // right parentesis
21+
tokenizer.add(/[+\-*\/]\s*/, TokenType.BINARY_OPERATOR); // right parentesis
22+
23+
tokenizer.tokenize("function a( m, a10)\n 2 + 3\nend");
24+
let tokens = tokenizer.tokens;
25+
console.log(tokens);
26+
});
27+
});

0 commit comments

Comments
 (0)