npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@solidity-ide/antlr-parser

v1.0.1

Published

Ethereum Solidity language parser via ANTLR4.

Downloads

4

Readme

antlr-parser

Parser for Ethereum's Solidity language generated by ANTLR4 and wrapped in RxJS.

Installation

npm i -S @solidity-ide/antlr-parser

Example

import "rxjs/add/operator/filter";
import { SolidityParser } from "../lib/SolidityParser";

const parser = new SolidityParser();

// Emits RuleContextEvents as it walks the tree.
parser.Observable()
    .filter(r => r.type !== "enterEveryRule" && r.type !== "exitEveryRule")
    .subscribe(
        rule => console.log(rule.type),
    );

// Emits syntax erros.
parser.ErrorObservable().subscribe(
        e => console.log(e),
    );

parser.parseFile("./contract.sol");
parser.parseFile("./contract2.sol", "./contact3.sol");
parser.parseFile(...["./contract4.sol", "./contact5.sol"]);

Documentation

SolidityParser Class

The main class for parsing Solidity code. Provides RX Observables that emit rule contexts and syntax errors.

One SolidityParser instance can be used to parse multiple files. Distinguish between files with enterSourceUnit and exitSourceUnit event types. Optionally, set the Observables to complete after the first parsing.

Constructor

constructor (fireComplete = false)

False by default. If true, the Observables will complete after the first parsing.

Methods

parseText (...code: string[]): void

Parses Solidity code provided as a string.

parseFile (...path: string[]): void

Loads and parses Solidity code from a file.

Observable (): Observable<IRuleContextEvent>

Emits Rule Context events as it walks the tree of parsed Solidity code.

ErrorObservable (): Observable<ISyntaxErrorEvent>

Emits any Syntax Error events from parsed Solidity code.

complete (): void

Cleans up the class. Basically invoking complete() on any Observables.

IRuleContextEvent Interface

Emited by SolidityParser#Observable().

export interface IRuleContextEvent {
    type: string;
    context: RuleContext;
}

ISyntaxErrorEvent Interface

Emitted by SolidityParser#ErrorObservable.

export interface ISyntaxErrorEvent {
    line: number;
    column: number;
    message: string;
    error: Error;
}

RuleContextEvent Types

The definitions for these rules can be found in the grammar definition (./bin/Solidity.g4).

Event types come in pairs: enter* and exit* events.

  • enterEveryRule <=> exitEveryRule (Included for completeness. More helpful to filter out.)
  • enterSourceUnit <=> exitSourceUnit (Marks the start and end of the document.)
  • enterPragmaDirective <=> exitPragmaDirective
  • enterPragmaName <=> exitPragmaName
  • enterPragmaValue <=> exitPragmaValue
  • enterVersion <=> exitVersion
  • enterVersionOperator <=> exitVersionOperator
  • enterVersionConstraint <=> exitVersionConstraint
  • enterImportDeclaration <=> exitImportDeclaration
  • enterImportDirective <=> exitImportDirective
  • enterContractDefinition <=> exitContractDefinition
  • enterInheritanceSpecifier <=> exitInheritanceSpecifier
  • enterContractPart <=> exitContractPart
  • enterStateVariableDeclaration <=> exitStateVariableDeclaration
  • enterUsingForDeclaration <=> exitUsingForDeclaration
  • enterStructDefinition <=> exitStructDefinition
  • enterModifierDefinition <=> exitModifierDefinition
  • enterFunctionDefinition <=> exitFunctionDefinition
  • enterEventDefinition <=> exitEventDefinition
  • enterEnumValue <=> exitEnumValue
  • enterEnumDefinition <=> exitEnumDefinition
  • enterIndexedParameterList <=> exitIndexedParameterList
  • enterParameterList <=> exitParameterList
  • enterTypeNameList <=> exitTypeNameList
  • enterVariableDeclaration <=> exitVariableDeclaration
  • enterTypeName <=> exitTypeName
  • enterUserDefinedTypeName <=> exitUserDefinedTypeName
  • enterMapping <=> exitMapping
  • enterFunctionTypeName <=> exitFunctionTypeName
  • enterStorageLocation <=> exitStorageLocation
  • enterBlock <=> exitBlock
  • enterStatement <=> exitStatement
  • enterExpressionStatement <=> exitExpressionStatement
  • enterIfStatement <=> exitIfStatement
  • enterWhileStatement <=> exitWhileStatement
  • enterPlaceholderStatement <=> exitPlaceholderStatement
  • enterSimpleStatement <=> exitSimpleStatement
  • enterForStatement <=> exitForStatement
  • enterInlineAssemblyStatement <=> exitInlineAssemblyStatement
  • enterDoWhileStatement <=> exitDoWhileStatement
  • enterContinueStatement <=> exitContinueStatement
  • enterBreakStatement <=> exitBreakStatement
  • enterReturnStatement <=> exitReturnStatement
  • enterThrowStatement <=> exitThrowStatement
  • enterVariableDeclarationStatement <=> exitVariableDeclarationStatement
  • enterIdentifierList <=> exitIdentifierList
  • enterElementaryTypeName <=> exitElementaryTypeName
  • enterExpression <=> exitExpression
  • enterPrimaryExpression <=> exitPrimaryExpression
  • enterExpressionList <=> exitExpressionList
  • enterNameValueList <=> exitNameValueList
  • enterFunctionCall <=> exitFunctionCall
  • enterFunctionCallArguments <=> exitFunctionCallArguments
  • enterNewExpression <=> exitNewExpression
  • enterInlineAssemblyBlock <=> exitInlineAssemblyBlock
  • enterAssemblyItem <=> exitAssemblyItem
  • enterAssemblyLocalBinding <=> exitAssemblyLocalBinding
  • enterAssemblyAssignment <=> exitAssemblyAssignment
  • enterFunctionalAssemblyExpression <=> exitFunctionalAssemblyExpression
  • enterArrayLiteral <=> exitArrayLiteral
  • enterTupleLiteral <=> exitTupleLiteral
  • enterElementaryTypeNameExpression <=> exitElementaryTypeNameExpression
  • enterNumberLiteral <=> exitNumberLiteral

Special Thanks

This library started with the ANTL4 grammar definition created by Federico Bond (@federicobond).


License GPL 3.0