Skip to content

Commit

Permalink
Apply "prettier" formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
kasbah committed Jan 21, 2018
1 parent af0107a commit d875dc5
Show file tree
Hide file tree
Showing 5 changed files with 4,943 additions and 55 deletions.
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tabWidth: 2
singleQuote: true
bracketSpacing: false
32 changes: 17 additions & 15 deletions js/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,29 @@ var ElectroGrammarToObjectListener = function() {
return this;
};

ElectroGrammarToObjectListener.prototype = Object.create(ElectroGrammarListener.prototype);
ElectroGrammarToObjectListener.prototype = Object.create(
ElectroGrammarListener.prototype
);
ElectroGrammarToObjectListener.prototype.constructor = ElectroGrammarToObjectListener;

ElectroGrammarToObjectListener.prototype.enterCapacitance = function(ctx) {
var cprefix_lookup = {'u': 10e-6, 'n': 10e-9, 'p': 10e-12};
var number = Number(ctx.NUMBER().getText());
var cprefix = cprefix_lookup[ctx.CPREFIX().getText()];
this.obj['capacitance'] = number * cprefix;
var cprefix_lookup = {u: 10e-6, n: 10e-9, p: 10e-12};
var number = Number(ctx.NUMBER().getText());
var cprefix = cprefix_lookup[ctx.CPREFIX().getText()];
this.obj['capacitance'] = number * cprefix;
};

var parse = function(input) {
var chars = new antlr4.InputStream(input);
var lexer = new ElectroGrammarLexer(chars);
var tokens = new antlr4.CommonTokenStream(lexer);
var parser = new ElectroGrammarParser(tokens);
parser.buildParseTrees = true;
var chars = new antlr4.InputStream(input);
var lexer = new ElectroGrammarLexer(chars);
var tokens = new antlr4.CommonTokenStream(lexer);
var parser = new ElectroGrammarParser(tokens);
parser.buildParseTrees = true;

var tree = parser.electro_grammar();
var listener = new ElectroGrammarToObjectListener();
var walker = antlr4.tree.ParseTreeWalker.DEFAULT.walk(listener, tree);
return listener.obj;
var tree = parser.electro_grammar();
var listener = new ElectroGrammarToObjectListener();
var walker = antlr4.tree.ParseTreeWalker.DEFAULT.walk(listener, tree);
return listener.obj;
};

module.exports = {'parse': parse};
module.exports = {parse: parse};
18 changes: 6 additions & 12 deletions js/test/test_units.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,29 @@ const {parse} = require('../lib/index');

describe('Capacitance', () => {
it('uF is parsed correctly', () => {
const cases = [
'10uF',
];
const cases = ['10uF'];

cases.forEach((text) => {
cases.forEach(text => {
const obj = parse(text);
console.log(text, obj['capacitance']);
assert(obj['capacitance'] === 10e-5);
});
});

it('nF is parsed correctly', () => {
const cases = [
'10nF',
];
const cases = ['10nF'];

cases.forEach((text) => {
cases.forEach(text => {
const obj = parse(text);
console.log(text, obj['capacitance']);
assert(obj['capacitance'] === 10e-8);
});
});

it('pF is parsed correctly', () => {
const cases = [
'10pF',
];
const cases = ['10pF'];

cases.forEach((text) => {
cases.forEach(text => {
const obj = parse(text);
console.log(text, obj['capacitance']);
assert(obj['capacitance'] === 10e-11);
Expand Down
Loading

0 comments on commit d875dc5

Please sign in to comment.