Comments (9)
The node for function MyContract {}
has a name
key with "MyContract" as value, whereas in constructor() {}
, name
is null.
Please try different sources and review the full generated AST. You should be able to get most of your answers from there.
from solidity-parser-antlr.
HI @obernardovieira, without looking at the whole AST it's hard to know what's going on. I think you should see a parent node FunctionCall with name onERC721Received
that takes that function call as expression, but I could be wrong. Let me know if that helps.
from solidity-parser-antlr.
Hi @federicobond thanks for the quick answer, and thanks for this package btw.
You right, I was not clear.
So I put everything together and I realized I was doing one thing wrong, which was fDef.body.statements.forEach((fLink) => {
because I actually don't need it, so I removed and updated parser.visit(fLink, {
to parser.visit(fDef, {
and it still catches IERC721Receiver again.
parser.visit(ast, {
FunctionDefinition: (fDef) => {
fDef.body.statements.forEach((fLink) => {
parser.visit(fLink, {
FunctionCall: (functionCallNode) => {
if (functionCallNode.expression.name === 'IERC721Receiver') {
console.log(functionCallNode);
}
},
});
});
},
});
What I want to do here it to map the function being called in a function's body. And ast is the complete file.
from solidity-parser-antlr.
Not sure I understand you correctly. Examining the full contract AST in the console should help you understand where to look for. If the piece you are looking for it's not there, please describe the AST output you are getting and what you would have expected to see.
from solidity-parser-antlr.
Hi, I can confirm, I miss one thing. Thanks.
On the other hand, the ConstructorDefinition returns nothing and the constructor is actually returned as FunctionDefinition with an "isConstructor" variable as true. Is it a known problem?
from solidity-parser-antlr.
Where did you see this ConstructorDefinition?
from solidity-parser-antlr.
Well, here https://github.com/solidityj/solidity-antlr4/blob/edce5c44d2d681e32bb23034d822bf0fcf1cb43e/Solidity.g4#L65
I assumed it would have the same names. Bad assumption I guess 😁
from solidity-parser-antlr.
Ahh right, AST names are different from ANTLR parser rules. You can have a function MyContract {}
which would be a FunctionDefinition according to ANTLR but is another form of constructor.
from solidity-parser-antlr.
I know, but what about constructor() {}
? How can I catch it?
from solidity-parser-antlr.
Related Issues (20)
- Cannot get parsed ast correctly in production HOT 4
- Failing to parse abstract contracts in Solidity 0.6
- ANTLR grammar in the Solidity repository HOT 1
- Augment the `Parameter` type HOT 2
- Drop ParameterList and Parameter node types HOT 2
- docs: document the loc attribute
- Parse error when using underscores in numbers HOT 6
- Can't read property expressionList of null HOT 1
- Natspec feature throwing errors in natspec not attached to functions HOT 9
- Support inheritance specifier with optional arguments HOT 1
- `UnaryOperation` expression type missing from type definitions HOT 1
- `NewExpression` expression type missing from type definitions
- Parses error with arrays with ABIEncoderV2 HOT 3
- feat(visitor): support early termination
- Non-ascii characters corrupt the range data HOT 4
- Some bugs HOT 3
- Tokenize function is not working
- `parse` fails to parse empty files with `{ loc: true }` option
- solc 0.6.0 array slicing syntax for calldata arrays does not compile HOT 1
- 0.6.0: Support try/catch syntax HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from solidity-parser-antlr.