question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Expose AST w/o import processing

See original GitHub issue

I’d like to use solc’s abstract syntax tree to evaluate imports and to eventually extend the import functionality using custom imports (i.e., import "Foo"; would pull Foo’s source from a package manager). Unfortunately, when creating the abstract syntax tree solc evaluates imports which, of course, can’t be resolved in this case. In response I’ve created my own solidity-parser project, but there’s no use maintaining two sets of code and I’d very much like to use the canonical AST. Can you expose a function that creates an abstract syntax tree without the need to resolve imports? Thanks!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
tcoultercommented, May 11, 2016

Not discouraged yet. 😃

0reactions
tcoultercommented, Sep 22, 2017

Hey @axic, any chance you can post an example? This input doesn’t seem to work:

pragma solidity ^0.14.15;

import "./Dependency.sol";

contract MyContract {

}
    var solcStandardInput = {
      language: "Solidity",
      sources: {
        "Contract.sol": {
          content: body // contract code
        }
      },
      settings: {
        outputSelection: {
          "*": {
            "*": [
              "ast",
            ]
          },
        }
      }
    };

    var output = solc.compileStandard(JSON.stringify(solcStandardInput));

The output is:

{ contracts: {},
  errors:
   [ { component: 'general',
       formattedMessage: 'Contract.sol:3:1: ParserError: Source "Dependency.sol" not found: File import callback not supported\nimport "./Dependency.sol";\n^------------------------^\n',
       message: 'Source "Dependency.sol" not found: File import callback not supported',
       severity: 'error',
       type: 'ParserError' } ],
  sources: {} }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Python AST Parsing and Custom Linting - YouTube
Let's write a custom linting plugin!Linting is the process of checking your code for various stylistic and structural things that you ...
Read more >
Understand Abstract Syntax Trees - ASTs - YouTube
... years educating yourself by working at a Silicon Valley company. ... Setup 15:38 Generating a JavaScript AST 22:07 Traversing an AST ......
Read more >
Cool Stuff With Go's AST Package Pt 1 - Medium
Starting off with the imports, we see that there are few more ... The AST package exposes an “inspect” function that takes in...
Read more >
ast — Abstract Syntax Trees — Python 3.11.1 documentation
The ast module helps Python applications to process trees of the Python abstract ... expr? msg) | Import(alias* names) | ImportFrom(identifier? module, ...
Read more >
Read JavaScript Source Code, Using an AST - DigitalOcean
Then you need to know what function or constants it exposes to the global scope. Let a computer read through your code and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found