federicobond / solidity-parser-antlr

A Solidity parser for JS built on top of a robust ANTLR4 grammar
MIT License
155 stars 55 forks source link

Add suport for parsing type name fragments #85

Open cd1m0 opened 5 years ago

cd1m0 commented 5 years ago

In the process of introspecting solc's ast, we have a use case to parse the type strings embedded in some nodes. It seems that this can be perfectly solved using the solidity-parser-antlr. This PR propses a small new entry point to the parser:

function parseType(input, options) {

That is almost identical to parse(), but parses strings representing just typeName fragments, instead of whole contracts.

So for example one could run:

> parser.parseType('uint[]', {strict: true})
{ type: 'ArrayTypeName',
  baseTypeName: { type: 'ElementaryTypeName', name: 'uint' },
  length: null }
> 

The PR also adds several tests for common solidity types in test/index.js and fixes 2 small lint issues.

Thank you for considering this!

Best ~Dimo

cd1m0 commented 5 years ago

Appologies, I did not open an issue first. If you wish I can also open an issue and reference it here?

vibern0 commented 4 years ago

Hi, I see https://github.com/federicobond/solidity-parser-antlr/pull/85/commits/2273972a655e10cf53c8ac8a9ded5c1f9e87fca6 above, I wonder if you are working on any natspec related? I worked on it in the past, and it got merged (https://github.com/federicobond/solidity-parser-antlr/pull/71), but unfortunately, there were a few cases that I haven't tested so my changes got reverted. Since that time, and because I want to use solidity-parser-antlr for everything in my solidity documentation tool (https://github.com/HQ20/soldoc) I decided to fork and make it work. That was when I realized the limitations. See here https://github.com/obernardovieira/solidity-parser-antlr I'm very proud of it and planning to open a PR. If there's any chance that we merge our work or see wht fits best. I would appreciate a lot :+1: thanks for your time