algebra-latex
Advanced tools
Comparing version
@@ -111,2 +111,12 @@ 'use strict'; | ||
if (this.current_char() == '[') { | ||
this.increment(); | ||
return { type: 'bracket', open: true, value: '[' }; | ||
} | ||
if (this.current_char() == ']') { | ||
this.increment(); | ||
return { type: 'bracket', open: false, value: ']' }; | ||
} | ||
if (this.current_char() == '+') { | ||
@@ -113,0 +123,0 @@ this.increment(); |
@@ -160,2 +160,6 @@ 'use strict'; | ||
if (kwd == 'sqrt') { | ||
return this.sqrt(); | ||
} | ||
if (_functions2.default.includes(kwd.toLowerCase())) { | ||
@@ -172,2 +176,53 @@ return this.function(); | ||
}, { | ||
key: 'sqrt', | ||
value: function sqrt() { | ||
// sqrt : SQRT (L_SQUARE_BRAC NUMBER R_SQUARE_BRAC)? GROUP | ||
(0, _logger.debug)('sqrt'); | ||
this.eat('keyword'); | ||
if (this.current_token.value != 'sqrt') { | ||
this.error('Expected sqrt found ' + JSON.stringify(this.current_token)); | ||
} | ||
if (this.peek().value != '[') { | ||
var content = this.group(); | ||
return { | ||
type: 'function', | ||
value: 'sqrt', | ||
content: content | ||
}; | ||
} | ||
this.eat('bracket'); | ||
if (this.current_token.value != '[') { | ||
this.error('Expected "[" bracket, found ' + JSON.stringify(this.current_token)); | ||
} | ||
var base = this.number(); | ||
this.eat('bracket'); | ||
if (this.current_token.value != ']') { | ||
this.error('Expected "]" bracket, found ' + JSON.stringify(this.current_token)); | ||
} | ||
var value = this.group(); | ||
return { | ||
type: 'operator', | ||
operator: 'exponent', | ||
lhs: value, | ||
rhs: { | ||
type: 'operator', | ||
operator: 'divide', | ||
lhs: { | ||
type: 'number', | ||
value: 1 | ||
}, | ||
rhs: base | ||
} | ||
}; | ||
} | ||
}, { | ||
key: 'fraction', | ||
@@ -289,17 +344,9 @@ value: function fraction() { | ||
}; | ||
} /* else if (op.type == 'bracket' && op.open == true) { | ||
let rhs = this.group() | ||
return { | ||
type: 'operator', | ||
operator: 'multiply', | ||
lhs, | ||
rhs, | ||
} | ||
}*/else if (op.type != 'operator' || op.value != 'multiply' && op.value != 'divide') { | ||
(0, _logger.debug)('term only left side'); | ||
return lhs; | ||
} else { | ||
// Operator token | ||
this.next_token(); | ||
} | ||
} else if (op.type != 'operator' || op.value != 'multiply' && op.value != 'divide') { | ||
(0, _logger.debug)('term only left side'); | ||
return lhs; | ||
} else { | ||
// Operator token | ||
this.next_token(); | ||
} | ||
@@ -306,0 +353,0 @@ (0, _logger.debug)('op mul right'); |
{ | ||
"name": "algebra-latex", | ||
"version": "1.1.6", | ||
"version": "1.1.7", | ||
"scripts": { | ||
@@ -5,0 +5,0 @@ "build": "rm -rf ./lib && babel src -d lib", |
52285
2.58%1416
3.28%