raineorshine/solgraph

whitespace problem in multi-variable assignments

gundas opened this issue · 4 comments

Valid whitespaces after ( or before ) in multi-variable assignments cause an exception:

contract test {
	function f2() returns (uint256 val1, uint256 val2) {
		// does not work
		//var ( r1, r2 ) = (23,15);
			
		// does not work
		//var (r1, r2 ) = (23,15);

		// does not work
		//var ( r1, r2) = (23,15);

		//works
		var (r1, r2) = (23,15);
		
		return (r1, r2);
	}
}

The exception is:

Parse error
{ SyntaxError: Expected ",", comment, end of line, or whitespace but ")" found. Line: 10, Column: 15
    at peg$buildStructuredError ((...)\npm\node_modules\solgraph\node_modules\solidity-parser\build\parser.js:1272:12)
    at Object.peg$parse [as parse] ((...)\npm\node_modules\solgraph\node_modules\solidity-parser\build\parser.js:13858:11)
    at Object.parse ((...)\npm\node_modules\solgraph\node_modules\solidity-parser\index.js:34:23)
    at exports.default ((...)\npm\node_modules\solgraph\dist\index.js:70:21)
    at (...)\npm\node_modules\solgraph\dist\bin.js:37:35
  message: 'Expected ",", comment, end of line, or whitespace but ")" found. Line: 10, Column: 15',
  expected:
   [ { type: 'other', description: 'whitespace' },
     { type: 'other', description: 'end of line' },
     { type: 'other', description: 'comment' },
     { type: 'literal', text: ',', ignoreCase: false } ],
  found: ')',
  location:
   { start: { offset: 192, line: 10, column: 15 },
     end: { offset: 193, line: 10, column: 16 } },
  name: 'SyntaxError' }

It also seem to fail/give same error when assignment is skipped for some variables in the multi-variable assignment?
var (owner,,,status) = MyContract(address).info();

SyntaxError: Expected comment, end of line, identifier, or whitespace but "," found.
at peg$buildStructuredError (C:\Users\mano\AppData\Roaming\npm\node_modules\solgraph\node_modules\solidity-parser\build\parser.js:1272:12)
at Object.peg$parse [as parse] (C:\Users\mano\AppData\Roaming\npm\node_modules\solgraph\node_modules\solidity-parser\build\parser.js:13858:11)
at Object.parse (C:\Users\mano\AppData\Roaming\npm\node_modules\solgraph\node_modules\solidity-parser\index.js:34:23)
at exports.default (C:\Users\mano\AppData\Roaming\npm\node_modules\solgraph\dist\index.js:70:21)
at C:\Users\mano\AppData\Roaming\npm\node_modules\solgraph\dist\bin.js:37:35
at
message: 'Expected comment, end of line, identifier, or whitespace but "," found. Line: 37, Column: 26',

Hello @manosamy ,

It does not work, because the current dependencies use old "solidity-parser": "0.3.0"
If you change that line in the https://github.com/raineorshine/solgraph/blob/master/package.json?#L46 to:

"solidity-parser": "0.4.0"

it should work.

Will close when solidity-parser is upgraded.

Duplicate of #7