Documentation
¶
Overview ¶
Package solgo provides a suite of tools for parsing, analyzing, and interacting with Solidity contracts. It includes a contextual parser that maintains a stack of contexts as it parses a contract, allowing it to keep track of the current context (e.g., within a contract definition, function definition, etc.). It also includes a contract listener that extracts information about contracts as they are parsed, including the contract name, implemented interfaces, imported contracts, pragmas, and comments. Additionally, it includes a syntax error listener that listens for syntax errors in contracts and categorizes them by severity. The package also provides functionality for generating and working with Ethereum contract ABIs (Application Binary Interfaces). This includes parsing contract definitions to extract ABI information, normalizing type names, and handling complex types like mappings. These tools can be used together to provide a comprehensive interface for working with Solidity contracts, making it easier to understand their structure, identify potential issues, and interact with them on the Ethereum network.
Index ¶
- type ListenerName
- type SolGo
- func (s *SolGo) GetAllListeners() map[ListenerName]antlr.ParseTreeListener
- func (s *SolGo) GetContextualParser() *syntaxerrors.ContextualParser
- func (s *SolGo) GetInput() io.Reader
- func (s *SolGo) GetInputStream() *antlr.InputStream
- func (s *SolGo) GetLexer() *parser.SolidityLexer
- func (s *SolGo) GetListener(name ListenerName) (antlr.ParseTreeListener, error)
- func (s *SolGo) GetParser() *parser.SolidityParser
- func (s *SolGo) GetTokenStream() *antlr.CommonTokenStream
- func (s *SolGo) GetTree() antlr.ParseTree
- func (s *SolGo) IsListenerRegistered(name ListenerName) bool
- func (s *SolGo) Parse() []syntaxerrors.SyntaxError
- func (s *SolGo) RegisterListener(name ListenerName, listener antlr.ParseTreeListener) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ListenerName ¶
type ListenerName string
ListenerName represents the name of a listener.
const ( ListenerAbi ListenerName = "abi" ListenerContractInfo ListenerName = "contract_info" ListenerAst ListenerName = "ast" ListenerSyntaxErrors ListenerName = "syntax_errors" )
Predefined listener names.
func (ListenerName) String ¶ added in v0.1.4
func (l ListenerName) String() string
type SolGo ¶
type SolGo struct {
// contains filtered or unexported fields
}
SolGo is a struct that encapsulates the functionality for parsing and analyzing Solidity contracts.
func New ¶
New creates a new instance of SolGo. It takes a context and an io.Reader from which the Solidity contract is read. It initializes an input stream, lexer, token stream, and parser, and sets up error listeners.
func (*SolGo) GetAllListeners ¶
func (s *SolGo) GetAllListeners() map[ListenerName]antlr.ParseTreeListener
func (*SolGo) GetContextualParser ¶ added in v0.1.4
func (s *SolGo) GetContextualParser() *syntaxerrors.ContextualParser
GetContextualParser returns the ContextualParser which wraps the Solidity parser.
func (*SolGo) GetInput ¶
GetInput returns the raw input reader from which the Solidity contract is read.
func (*SolGo) GetInputStream ¶
func (s *SolGo) GetInputStream() *antlr.InputStream
GetInputStream returns the ANTLR input stream which is used by the lexer.
func (*SolGo) GetLexer ¶
func (s *SolGo) GetLexer() *parser.SolidityLexer
GetLexer returns the Solidity lexer which tokenizes the input stream.
func (*SolGo) GetListener ¶
func (s *SolGo) GetListener(name ListenerName) (antlr.ParseTreeListener, error)
func (*SolGo) GetParser ¶
func (s *SolGo) GetParser() *parser.SolidityParser
GetParser returns the Solidity parser which parses the token stream.
func (*SolGo) GetTokenStream ¶
func (s *SolGo) GetTokenStream() *antlr.CommonTokenStream
GetTokenStream returns the stream of tokens produced by the lexer.
func (*SolGo) GetTree ¶
GetTree returns the root of the parse tree that results from parsing the Solidity contract.
func (*SolGo) IsListenerRegistered ¶
func (s *SolGo) IsListenerRegistered(name ListenerName) bool
func (*SolGo) Parse ¶
func (s *SolGo) Parse() []syntaxerrors.SyntaxError
Parse initiates the parsing process. It walks the parse tree with all registered listeners and returns any syntax errors that were encountered during parsing.
func (*SolGo) RegisterListener ¶
func (s *SolGo) RegisterListener(name ListenerName, listener antlr.ParseTreeListener) error
Directories
¶
| Path | Synopsis |
|---|---|
|
Package abis provides functionality for parsing and manipulating Solidity contract ABIs (Application Binary Interfaces).
|
Package abis provides functionality for parsing and manipulating Solidity contract ABIs (Application Binary Interfaces). |
|
Package ast provides an Abstract Syntax Tree (AST) representation for Solidity contracts.
|
Package ast provides an Abstract Syntax Tree (AST) representation for Solidity contracts. |
|
Package contracts provides a set of utilities and listeners for working with Solidity contracts.
|
Package contracts provides a set of utilities and listeners for working with Solidity contracts. |
|
Package syntaxerrors provides tools for detecting and handling syntax errors in Solidity contracts.
|
Package syntaxerrors provides tools for detecting and handling syntax errors in Solidity contracts. |