From afbe2961a00d82abe70b5a697afb8640baef0f2b Mon Sep 17 00:00:00 2001 From: duaraghav8 Date: Sun, 23 Dec 2018 13:48:42 +0530 Subject: [PATCH] Add support for 'calldata' storage specifier --- README.md | 4 ++-- package.json | 2 +- solidity.pegjs | 9 +++++---- test/doc_examples.sol | 9 +++++++++ 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 11b3ef1..74d7995 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,9 @@ Pegjs-based Parser for the Solidity Programming language. It was originally a fork of [Consensys' solidity-parser](https://github.com/ConsenSys/solidity-parser) by Tim Coulter. @cgewecke, @duaraghav8 and @federicobond are co-authors. ## Note -Solparse is primarily meant for [Solium](https://github.com/duaraghav8/Solium). Because its sole purpose is to make life easier for the linter, we do not guarantee that there won't be any breaking changes, although we work hard to keep it friendly. +Solparse is primarily meant for [Ethlint](https://github.com/duaraghav8/Ethlint). Because its sole purpose is to make life easier for the linter, we do not guarantee that there won't be any breaking changes, although we work hard to keep it friendly. -If you use solparse in your production systems, use it as a fixed dependency, i.e., stick to a fixed version of the parser. +If you use solparse in your production systems, use it as a fixed dependency. ### License diff --git a/package.json b/package.json index d49061e..ee9f3f3 100755 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "index.js", "scripts": { "prepublish": "npm run build", - "build": "mkdirp ./build && pegjs --cache -o ./build/parser.js ./solidity.pegjs && pegjs -o ./build/imports_parser.js ./imports.pegjs", + "build": "mkdir -p ./build && pegjs --cache -o ./build/parser.js ./solidity.pegjs && pegjs -o ./build/imports_parser.js ./imports.pegjs", "test": "mocha --timeout 5000 --reporter spec", "lint": "eslint index.js test/ cli.js" }, diff --git a/solidity.pegjs b/solidity.pegjs index 46bd90c..641481d 100755 --- a/solidity.pegjs +++ b/solidity.pegjs @@ -470,6 +470,7 @@ PayableToken = "payable" !IdentifierPart AnonymousToken = "anonymous" !IdentifierPart AsToken = "as" !IdentifierPart BreakToken = "break" !IdentifierPart +CalldataToken = "calldata" !IdentifierPart ConstantToken = "constant" !IdentifierPart ContinueToken = "continue" !IdentifierPart ContractToken = "contract" !IdentifierPart @@ -784,6 +785,7 @@ VisibilitySpecifier StorageLocationSpecifier = StorageToken / MemoryToken + / CalldataToken StateVariableSpecifiers = specifiers:(VisibilitySpecifier __ ConstantToken?){ @@ -1632,16 +1634,15 @@ CommaSeparatedModifierNameList } InformalParameter - = type:Type __ isindexed:IndexedToken? __ isconstant:ConstantToken? __ isstorage:StorageToken? __ ismemory:MemoryToken? __ id:Identifier? + = type:Type __ isindexed:IndexedToken? __ isconstant:ConstantToken? __ storage:StorageLocationSpecifier? __ id:Identifier? { return { type: "InformalParameter", literal: type, id: id ? id.name : null, is_indexed: isindexed != null, - is_storage: isconstant != null, - is_storage: isstorage != null, - is_memory: ismemory != null, + is_constant: isconstant != null, + storage_location: storage ? storage[0]: null, start: location().start.offset, end: location().end.offset }; diff --git a/test/doc_examples.sol b/test/doc_examples.sol index b5f03ec..f9af250 100755 --- a/test/doc_examples.sol +++ b/test/doc_examples.sol @@ -155,6 +155,15 @@ library IntegerSet /// Number of stored items. uint size; } + struct Request { + bytes calldata data; + function(bytes memory) external callback; + } + function bar(uint[] memory self, function (uint) pure returns (uint) f) public { + (bool success, bytes memory data) = otherContract.call("f"); + uint[] calldata x = m_x; + } + function f(uint[][] calldata x) external {} function insert(data storage self, uint value) returns (bool alreadyPresent) { uint index = self.index[value];