Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ranges): allow dollar signs #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion formulas/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ const Address = {
},

columnNameToNumber: (columnName) => {
columnName = columnName.toUpperCase();
columnName = columnName.replace("$","").toUpperCase();
const len = columnName.length;
let number = 0;
for (let i = 0; i < len; i++) {
Expand Down
2 changes: 1 addition & 1 deletion grammar/dependency/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ class Utils {
* @return {number}
*/
toNumber(number) {
return Number(number);
return Number(number.replace("$",""));
}

/**
Expand Down
3 changes: 1 addition & 2 deletions grammar/lexing.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const Cell = createToken({

const Number = createToken({
name: 'Number',
pattern: /[0-9]+[.]?[0-9]*([eE][+\-][0-9]+)?/
pattern: /[$]?[0-9]+[.]?[0-9]*([eE][+\-][0-9]+)?/
});

const Boolean = createToken({
Expand All @@ -73,7 +73,6 @@ const Column = createToken({
longer_alt: Name
});


/**
* Symbols and operators
*/
Expand Down
2 changes: 1 addition & 1 deletion grammar/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ class Utils {
* @return {number}
*/
toNumber(number) {
return Number(number);
return Number(number.replace("$",""));
}

/**
Expand Down
16 changes: 16 additions & 0 deletions test/grammar/depParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ describe('Dependency parser', () => {
expect(actual).to.deep.eq([{sheet: 'Sheet1', from: {row: 1, col: 1}, to: {row: 3, col: 16384}}]);
});

it('should parse special ranges', () => {
actual = depParser.parse('$A:$C', position);
expect(actual).to.deep.eq([{sheet: 'Sheet1', from: {row: 1, col: 1}, to: {row: 1048576, col: 3}}]);
actual = depParser.parse('A:$C', position);
expect(actual).to.deep.eq([{sheet: 'Sheet1', from: {row: 1, col: 1}, to: {row: 1048576, col: 3}}]);
actual = depParser.parse('$A:C', position);
expect(actual).to.deep.eq([{sheet: 'Sheet1', from: {row: 1, col: 1}, to: {row: 1048576, col: 3}}]);

actual = depParser.parse('$1:$3', position);
expect(actual).to.deep.eq([{sheet: 'Sheet1', from: {row: 1, col: 1}, to: {row: 3, col: 16384}}]);
actual = depParser.parse('1:$3', position);
expect(actual).to.deep.eq([{sheet: 'Sheet1', from: {row: 1, col: 1}, to: {row: 3, col: 16384}}]);
actual = depParser.parse('$1:3', position);
expect(actual).to.deep.eq([{sheet: 'Sheet1', from: {row: 1, col: 1}, to: {row: 3, col: 16384}}]);
});

it('should parse variable', function () {
let actual = depParser.parse('aaaa', position);
expect(actual).to.deep.eq([{sheet: 'Sheet1', from: {row: 1, col: 1}, to: {row: 2, col: 2}}]);
Expand Down