Skip to content
This repository has been archived by the owner on Sep 27, 2020. It is now read-only.

[Question] automatically generating typing from concrete output or the test cases? #47

Open
yxliang01 opened this issue Feb 21, 2019 · 10 comments

Comments

@yxliang01
Copy link
Contributor

This issue is to discuss the possibility of having the typing for the output of the parser automatically generated. Currently, the typing file at https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/solidity-parser-antlr/index.d.ts is more or less manually written and is very incomplete. Since the output is very structured, I feel like this is doable. However, I haven't figured out a way yet. Any thoughts?

@federicobond
Copy link
Owner

Hi @yxliang01, thanks for bringing this up! I don't see a simple way of generating that sort of type information automatically, but I am more than willing to bring the type definitions into this repo so that they can be updated with less bureaucracy and kept up-to-date with any implementation changes.

Could you open a pull request to begin that effort?

@yxliang01
Copy link
Contributor Author

@federicobond Sure. It sounds good. I will do it tomorrow. But, since you are aware of this typing thing going on, would you think it's a good idea to bring the typescript tool chain to this project and we simply annotate the types incrementally? This way might some make this library even less error-prone and we sometimes might get benefit from the typescript compiler's type inference. What do you think?

@federicobond
Copy link
Owner

I think it's a good idea but I would like to do it in two phases. First, bring the type definitions as an independent file, then consider moving the codebase to TypeScript.

@yxliang01
Copy link
Contributor Author

@federicobond Please see #48 and the created PR as the begin of this effort.

@yxliang01
Copy link
Contributor Author

I had a deeper look at the ANTLR grammar and feel like it doesn't really define the structural constraint of the Solidity language. So, it indeed doesn't look like we can just "convert" the grammar to TS types. But, now I see a possibility that we might be able to convert from the quite complete test at https://raw.githubusercontent.com/federicobond/solidity-parser-antlr/master/test/ast.js (Thanks for the good testing :) ). Changing the issue title now.

@yxliang01 yxliang01 changed the title [Question] automatically generating typing from concrete output or ANTLR grammar? [Question] automatically generating typing from concrete output or the test cases? Feb 26, 2019
@yxliang01
Copy link
Contributor Author

@LogvinovLeon Would you like to describe how you created these types previously? Was it automatically generated?

Were you simply converting from

var ruleNames = [ "sourceUnit", "pragmaDirective", "pragmaName", "pragmaValue",
? Since I see some of the types I can't see the output statements of them in this library codebase (e.g. Expression, SimpleStatement) and looks like they are the intermediate types returned by the ANTLR parser. Correct me if wrong.

@LogvinovLeon
Copy link

I did parse a rather complex contract and iterated over the generated AST to generate those.
Didn't define all the properties there as I didn't need them at the time for my use-case.

@federicobond
Copy link
Owner

federicobond commented Feb 26, 2019

Since I see some of the types I can't see the output statements of them in this library codebase (e.g. Expression, SimpleStatement) and looks like they are the intermediate types returned by the ANTLR parser. Correct me if wrong.

@yxliang01 that's correct. ANTLR outputs a parse tree (which is a version of a concrete syntax tree). Most of the code in this lib is dedicated to transforming that parse tree into an AST.

@yxliang01
Copy link
Contributor Author

@federicobond Are you also confirming that Expression and SimpleStatement are not part of the output AST of this library? If so, I will fix it soon.

@federicobond
Copy link
Owner

I think so, yes.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants