mirror of https://github.com/Wilfred/difftastic/
Unvendor tree-sitter-solidity
parent
65a803b203
commit
3a94668aee
@ -1 +0,0 @@
|
||||
../tree-sitter-solidity/queries/highlights.scm
|
||||
@ -1 +0,0 @@
|
||||
tree-sitter-solidity/src
|
||||
@ -1,34 +0,0 @@
|
||||
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
|
||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
|
||||
|
||||
name: Node.js CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [12.x]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
npm install yarn -g
|
||||
npm install tree-sitter-cli -g
|
||||
- name: Generate tree-sitter parser
|
||||
run: tree-sitter generate
|
||||
- run: yarn
|
||||
- run: yarn test
|
||||
@ -1,45 +0,0 @@
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
name: 🦀 Build and Test rust bindings
|
||||
|
||||
jobs:
|
||||
build_and_test:
|
||||
name: Rust project
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
- name: 📥 Download the repository
|
||||
uses: actions/checkout@v2
|
||||
- name: 🦀 Install rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
|
||||
- name: 📥 Setup node
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 12
|
||||
|
||||
- name: 📥 Install js dependencies
|
||||
run: |
|
||||
npm install yarn
|
||||
npm install tree-sitter-cli -g
|
||||
|
||||
- name: 🌲 Generate the parser
|
||||
run: tree-sitter generate
|
||||
|
||||
- name: 🛠 Build rust bindings
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: build
|
||||
args: --release --all-features
|
||||
|
||||
# Run the tests
|
||||
- name: 🧪 Now run the rust tests
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: test
|
||||
@ -1,14 +0,0 @@
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
|
||||
.vscode/
|
||||
index.js
|
||||
|
||||
# Rust
|
||||
Cargo.lock
|
||||
target
|
||||
build
|
||||
@ -1,18 +0,0 @@
|
||||
# Tree-sitter
|
||||
corpus
|
||||
examples
|
||||
script
|
||||
|
||||
# Other compilation artefacts
|
||||
build
|
||||
|
||||
# Rust
|
||||
target
|
||||
Cargo.lock
|
||||
|
||||
# Js
|
||||
node_modules
|
||||
|
||||
# Other
|
||||
.github
|
||||
.vscode
|
||||
@ -1,31 +0,0 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Run tree-sitter test",
|
||||
"request": "launch",
|
||||
"runtimeArgs": [
|
||||
"test",
|
||||
],
|
||||
"runtimeExecutable": "npm",
|
||||
"skipFiles": [
|
||||
"<node_internals>/**"
|
||||
],
|
||||
"type": "node"
|
||||
},
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Generate Grammar",
|
||||
"skipFiles": [
|
||||
"<node_internals>/**"
|
||||
],
|
||||
"program": "${workspaceFolder}/node_modules/bin/tree-sitter",
|
||||
"args": ["generate"],
|
||||
},
|
||||
|
||||
]
|
||||
}
|
||||
@ -1,26 +0,0 @@
|
||||
[package]
|
||||
name = "tree-sitter-solidity"
|
||||
description = "Solidity grammar for the tree-sitter parsing library"
|
||||
version = "0.0.3"
|
||||
keywords = ["incremental", "parsing", "Solidity"]
|
||||
categories = ["parsing", "text-editors"]
|
||||
repository = "https://github.com/JoranHonig/tree-sitter-solidity"
|
||||
edition = "2018"
|
||||
license = "MIT"
|
||||
|
||||
build = "bindings/rust/build.rs"
|
||||
include = [
|
||||
"bindings/rust/*",
|
||||
"grammar.js",
|
||||
"queries/*",
|
||||
"src/*",
|
||||
]
|
||||
|
||||
[lib]
|
||||
path = "bindings/rust/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
tree-sitter = "0.19.5"
|
||||
|
||||
[build-dependencies]
|
||||
cc = "1.0"
|
||||
@ -1,7 +0,0 @@
|
||||
Copyright (c) 2020 Joran Honig
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
@ -1,37 +0,0 @@
|
||||
## 🌴 tree-sitter-solidity
|
||||
[](https://github.com/JoranHonig/tree-sitter-solidity/actions/workflows/node.js.yml)
|
||||
[](https://badge.fury.io/js/tree-sitter-solidity)
|
||||
|
||||
> 💡 this grammar is still in development, the structure of the generated AST is not stable
|
||||
|
||||
This repository contains a grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter).
|
||||
|
||||
The goal of this project is to provide an parser efficient low-dependency parser for solidity which targets most solidity versions in use and is designed for enabling metaprogramming.
|
||||
|
||||
|
||||
### Navigating this repository
|
||||
The primary file in this repository is `grammar.js` which describes the tree-sitter grammar.
|
||||
|
||||
```
|
||||
# Primary file:
|
||||
grammar.js
|
||||
# Tests:
|
||||
/test/**/*
|
||||
|
||||
# Auto generated:
|
||||
/src/**/*
|
||||
index.js
|
||||
binding.gyp
|
||||
```
|
||||
|
||||
### References
|
||||
-> Ethereum solidity grammar:
|
||||
- https://github.com/ethereum/solidity/blob/develop/docs/grammar/SolidityParser.g4
|
||||
- https://github.com/ethereum/solidity/blob/develop/docs/grammar/SolidityLexer.g4
|
||||
- https://docs.soliditylang.org/en/latest/grammar.html?#
|
||||
|
||||
-> Tree-sitter javascript grammar: https://github.com/tree-sitter/tree-sitter-javascript/blob/master/grammar.js
|
||||
|
||||
-> Solidity antlr grammar: https://github.com/ConsenSys/solidity-parser-antlr
|
||||
|
||||
Major inspriration & some structures have been taken from tree-sitter-javascript, a big thanks to the contributors to this repo!
|
||||
@ -1,18 +0,0 @@
|
||||
{
|
||||
"targets": [
|
||||
{
|
||||
"target_name": "tree_sitter_solidity_binding",
|
||||
"include_dirs": [
|
||||
"<!(node -e \"require('nan')\")",
|
||||
"src"
|
||||
],
|
||||
"sources": [
|
||||
"src/parser.c",
|
||||
"bindings/node/binding.cc"
|
||||
],
|
||||
"cflags_c": [
|
||||
"-std=c99",
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -1,28 +0,0 @@
|
||||
#include "tree_sitter/parser.h"
|
||||
#include <node.h>
|
||||
#include "nan.h"
|
||||
|
||||
using namespace v8;
|
||||
|
||||
extern "C" TSLanguage * tree_sitter_solidity();
|
||||
|
||||
namespace {
|
||||
|
||||
NAN_METHOD(New) {}
|
||||
|
||||
void Init(Local<Object> exports, Local<Object> module) {
|
||||
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
|
||||
tpl->SetClassName(Nan::New("Language").ToLocalChecked());
|
||||
tpl->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
|
||||
Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked();
|
||||
Local<Object> instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
|
||||
Nan::SetInternalFieldPointer(instance, 0, tree_sitter_solidity());
|
||||
|
||||
Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("Solidity").ToLocalChecked());
|
||||
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
|
||||
}
|
||||
|
||||
NODE_MODULE(tree_sitter_solidity_binding, Init)
|
||||
|
||||
} // namespace
|
||||
@ -1,40 +0,0 @@
|
||||
fn main() {
|
||||
let src_dir = std::path::Path::new("src");
|
||||
|
||||
let mut c_config = cc::Build::new();
|
||||
c_config.include(&src_dir);
|
||||
c_config
|
||||
.flag_if_supported("-Wno-unused-parameter")
|
||||
.flag_if_supported("-Wno-unused-but-set-variable")
|
||||
.flag_if_supported("-Wno-trigraphs");
|
||||
let parser_path = src_dir.join("parser.c");
|
||||
c_config.file(&parser_path);
|
||||
|
||||
// If your language uses an external scanner written in C,
|
||||
// then include this block of code:
|
||||
|
||||
/*
|
||||
let scanner_path = src_dir.join("scanner.c");
|
||||
c_config.file(&scanner_path);
|
||||
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
|
||||
*/
|
||||
|
||||
c_config.compile("parser");
|
||||
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
|
||||
|
||||
// If your language uses an external scanner written in C++,
|
||||
// then include this block of code:
|
||||
|
||||
/*
|
||||
let mut cpp_config = cc::Build::new();
|
||||
cpp_config.cpp(true);
|
||||
cpp_config.include(&src_dir);
|
||||
cpp_config
|
||||
.flag_if_supported("-Wno-unused-parameter")
|
||||
.flag_if_supported("-Wno-unused-but-set-variable");
|
||||
let scanner_path = src_dir.join("scanner.cc");
|
||||
cpp_config.file(&scanner_path);
|
||||
cpp_config.compile("scanner");
|
||||
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
|
||||
*/
|
||||
}
|
||||
@ -1,58 +0,0 @@
|
||||
//! This crate provides Solidity language support for the [tree-sitter][] parsing library.
|
||||
//!
|
||||
//! The bindings in https://github.com/tree-sitter/tree-sitter-javascript/blob/master/bindings/rust were used
|
||||
//! as a template for the tree-sitter-solidity rust bindings.
|
||||
//!
|
||||
//! Typically, you will use the [language][language func] function to add this language to a
|
||||
//! tree-sitter [Parser][], and then use the parser to parse some code:
|
||||
//!
|
||||
//! ```
|
||||
//! let code = "";
|
||||
//! let mut parser = tree_sitter::Parser::new();
|
||||
//! parser.set_language(tree_sitter_solidity::language()).expect("Error loading Solidity grammar");
|
||||
//! let tree = parser.parse(code, None).unwrap();
|
||||
//! ```
|
||||
//!
|
||||
//! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
|
||||
//! [language func]: fn.language.html
|
||||
//! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
|
||||
//! [tree-sitter]: https://tree-sitter.github.io/
|
||||
|
||||
use tree_sitter::Language;
|
||||
|
||||
extern "C" {
|
||||
fn tree_sitter_solidity() -> Language;
|
||||
}
|
||||
|
||||
/// Get the tree-sitter [Language][] for this grammar.
|
||||
///
|
||||
/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
|
||||
pub fn language() -> Language {
|
||||
unsafe { tree_sitter_solidity() }
|
||||
}
|
||||
|
||||
/// The source of the Solidity tree-sitter grammar description.
|
||||
pub const GRAMMAR: &'static str = include_str!("../../grammar.js");
|
||||
|
||||
/// The content of the [`node-types.json`][] file for this grammar.
|
||||
///
|
||||
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
|
||||
pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json");
|
||||
|
||||
// Uncomment these to include any queries that this grammar contains
|
||||
|
||||
pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm");
|
||||
// pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm");
|
||||
// pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm");
|
||||
// pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm");
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn test_can_load_grammar() {
|
||||
let mut parser = tree_sitter::Parser::new();
|
||||
parser
|
||||
.set_language(super::language())
|
||||
.expect("Error loading Solidity language");
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,19 +0,0 @@
|
||||
{
|
||||
"name": "tree-sitter-solidity",
|
||||
"version": "1.1.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"nan": {
|
||||
"version": "2.15.0",
|
||||
"resolved": "https://registry.npmjs.org/nan/-/nan-2.15.0.tgz",
|
||||
"integrity": "sha512-8ZtvEnA2c5aYCZYd1cvgdnU6cqwixRoYg70xPLWUws5ORTa/lnw+u4amixRS/Ac5U5mQVgp9pnlSUnbNWFaWZQ=="
|
||||
},
|
||||
"tree-sitter-cli": {
|
||||
"version": "0.20.6",
|
||||
"resolved": "https://registry.npmjs.org/tree-sitter-cli/-/tree-sitter-cli-0.20.6.tgz",
|
||||
"integrity": "sha512-tjbAeuGSMhco/EnsThjWkQbDIYMDmdkWsTPsa/NJAW7bjaki9P7oM9TkLxfdlnm4LXd1wR5wVSM2/RTLtZbm6A==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,29 +0,0 @@
|
||||
{
|
||||
"name": "tree-sitter-solidity",
|
||||
"version": "1.2.0",
|
||||
"description": "A tree sitter parser for Solidity",
|
||||
"main": "bindings/node",
|
||||
"scripts": {
|
||||
"test": "tree-sitter generate && tree-sitter test"
|
||||
},
|
||||
"author": "Joran Honig",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"nan": "^2.15.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tree-sitter-cli": "^0.20.6"
|
||||
},
|
||||
"tree-sitter": [
|
||||
{
|
||||
"scope": "source.sol",
|
||||
"file-types": [
|
||||
"sol"
|
||||
],
|
||||
"highlights": [
|
||||
"queries/highlights.scm"
|
||||
],
|
||||
"injection-regex": "^(sol|solidity)$"
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -1,217 +0,0 @@
|
||||
; identifiers
|
||||
; -----------
|
||||
(identifier) @variable
|
||||
(yul_identifier) @variable
|
||||
|
||||
; Pragma
|
||||
(pragma_directive) @tag
|
||||
(solidity_version_comparison_operator _ @tag)
|
||||
|
||||
; Literals
|
||||
; --------
|
||||
|
||||
[
|
||||
(string)
|
||||
(hex_string_literal)
|
||||
(unicode_string_literal)
|
||||
(yul_string_literal)
|
||||
] @string
|
||||
[
|
||||
(number_literal)
|
||||
(yul_decimal_number)
|
||||
(yul_hex_number)
|
||||
] @number
|
||||
[
|
||||
(true)
|
||||
(false)
|
||||
] @constant.builtin
|
||||
|
||||
(comment) @comment
|
||||
|
||||
; Definitions and references
|
||||
; -----------
|
||||
|
||||
(type_name) @type
|
||||
(primitive_type) @type
|
||||
(user_defined_type (identifier) @type)
|
||||
|
||||
(payable_conversion_expression "payable" @type)
|
||||
; Ensures that delimiters in mapping( ... => .. ) are not colored like types
|
||||
(type_name "(" @punctuation.bracket "=>" @punctuation.delimiter ")" @punctuation.bracket)
|
||||
|
||||
; Definitions
|
||||
(struct_declaration
|
||||
name: (identifier) @type)
|
||||
(enum_declaration
|
||||
name: (identifier) @type)
|
||||
(contract_declaration
|
||||
name: (identifier) @type)
|
||||
(library_declaration
|
||||
name: (identifier) @type)
|
||||
(interface_declaration
|
||||
name: (identifier) @type)
|
||||
(event_definition
|
||||
name: (identifier) @type)
|
||||
|
||||
(function_definition
|
||||
name: (identifier) @function)
|
||||
|
||||
(modifier_definition
|
||||
name: (identifier) @function)
|
||||
(yul_evm_builtin) @function.builtin
|
||||
|
||||
; Use contructor coloring for special functions
|
||||
(constructor_definition "constructor" @constructor)
|
||||
(fallback_receive_definition "receive" @constructor)
|
||||
(fallback_receive_definition "fallback" @constructor)
|
||||
|
||||
(struct_member name: (identifier) @property)
|
||||
(enum_value) @constant
|
||||
|
||||
; Invocations
|
||||
(emit_statement . (identifier) @type)
|
||||
(modifier_invocation (identifier) @function)
|
||||
|
||||
(call_expression . (member_expression property: (identifier) @function.method))
|
||||
(call_expression . (identifier) @function)
|
||||
|
||||
; Function parameters
|
||||
(call_struct_argument name: (identifier) @field)
|
||||
(event_paramater name: (identifier) @parameter)
|
||||
(parameter name: (identifier) @variable.parameter)
|
||||
|
||||
; Yul functions
|
||||
(yul_function_call function: (yul_identifier) @function)
|
||||
(yul_function_definition . (yul_identifier) @function (yul_identifier) @parameter)
|
||||
|
||||
|
||||
; Structs and members
|
||||
(member_expression property: (identifier) @property)
|
||||
(struct_expression type: ((identifier) @type .))
|
||||
(struct_field_assignment name: (identifier) @property)
|
||||
|
||||
|
||||
; Tokens
|
||||
; -------
|
||||
|
||||
; Keywords
|
||||
(meta_type_expression "type" @keyword)
|
||||
; Keywords
|
||||
[
|
||||
"pragma"
|
||||
"contract"
|
||||
"interface"
|
||||
"library"
|
||||
"is"
|
||||
"struct"
|
||||
"enum"
|
||||
"event"
|
||||
"using"
|
||||
"assembly"
|
||||
"emit"
|
||||
"public"
|
||||
"internal"
|
||||
"private"
|
||||
"external"
|
||||
"pure"
|
||||
"view"
|
||||
"payable"
|
||||
"modifier"
|
||||
"memory"
|
||||
"storage"
|
||||
"calldata"
|
||||
"var"
|
||||
"constant"
|
||||
(virtual)
|
||||
(override_specifier)
|
||||
(yul_leave)
|
||||
] @keyword
|
||||
|
||||
[
|
||||
"for"
|
||||
"while"
|
||||
"do"
|
||||
] @repeat
|
||||
|
||||
[
|
||||
"break"
|
||||
"continue"
|
||||
"if"
|
||||
"else"
|
||||
"switch"
|
||||
"case"
|
||||
"default"
|
||||
] @conditional
|
||||
|
||||
[
|
||||
"try"
|
||||
"catch"
|
||||
] @exception
|
||||
|
||||
[
|
||||
"return"
|
||||
"returns"
|
||||
] @keyword.return
|
||||
|
||||
"function" @keyword.function
|
||||
|
||||
"import" @include
|
||||
(import_directive "as" @include)
|
||||
(import_directive "from" @include)
|
||||
|
||||
(event_paramater "indexed" @keyword)
|
||||
|
||||
; Punctuation
|
||||
|
||||
[
|
||||
"("
|
||||
")"
|
||||
"["
|
||||
"]"
|
||||
"{"
|
||||
"}"
|
||||
] @punctuation.bracket
|
||||
|
||||
|
||||
[
|
||||
"."
|
||||
","
|
||||
] @punctuation.delimiter
|
||||
|
||||
|
||||
; Operators
|
||||
|
||||
[
|
||||
"&&"
|
||||
"||"
|
||||
">>"
|
||||
">>>"
|
||||
"<<"
|
||||
"&"
|
||||
"^"
|
||||
"|"
|
||||
"+"
|
||||
"-"
|
||||
"*"
|
||||
"/"
|
||||
"%"
|
||||
"**"
|
||||
"<"
|
||||
"<="
|
||||
"=="
|
||||
"!="
|
||||
"!=="
|
||||
">="
|
||||
">"
|
||||
"!"
|
||||
"~"
|
||||
"-"
|
||||
"+"
|
||||
"++"
|
||||
"--"
|
||||
] @operator
|
||||
|
||||
[
|
||||
"delete"
|
||||
"new"
|
||||
] @keyword.operator
|
||||
@ -1,9 +0,0 @@
|
||||
(function_definition) @local.scope
|
||||
(block_statement) @local.scope
|
||||
|
||||
(function_definition (parameter name: (identifier) @local.definition))
|
||||
|
||||
; still have to support tuple assignments
|
||||
(assignment_expression left: (identifier) @local.definition)
|
||||
|
||||
(identifier) @local.reference
|
||||
@ -1,43 +0,0 @@
|
||||
;; Method and Function declarations
|
||||
(contract_declaration (_
|
||||
(function_definition
|
||||
name: (identifier) @name) @definition.method))
|
||||
|
||||
(source_file
|
||||
(function_definition
|
||||
name: (identifier) @name) @definition.function)
|
||||
|
||||
;; Contract, struct, enum and interface declarations
|
||||
(contract_declaration
|
||||
name: (identifier) @name) @definition.class
|
||||
|
||||
(interface_declaration
|
||||
name: (identifier) @name) @definition.interface
|
||||
|
||||
(library_declaration
|
||||
name: (identifier) @name) @definition.interface
|
||||
|
||||
(struct_declaration name: (identifier) @name) @definition.class
|
||||
(enum_declaration name: (identifier) @name) @definition.class
|
||||
(event_definition name: (identifier) @name) @definition.class
|
||||
|
||||
;; Function calls
|
||||
(call_expression (identifier) @name ) @reference.call
|
||||
|
||||
(call_expression
|
||||
(member_expression
|
||||
property: (identifier) @name )) @reference.call
|
||||
|
||||
;; Log emit
|
||||
(emit_statement name: (identifier) @name) @reference.class
|
||||
|
||||
|
||||
;; Inheritance
|
||||
|
||||
(inheritance_specifier
|
||||
ancestor: (user_defined_type (identifier) @name . )) @reference.class
|
||||
|
||||
|
||||
;; Imports ( note that unknown is not standardised )
|
||||
(import_directive
|
||||
import_name: (identifier) @name ) @reference.unknown
|
||||
@ -1,21 +0,0 @@
|
||||
// pragma
|
||||
pragma solidity >=0.4.25 <0.7;
|
||||
|
||||
// import
|
||||
import "SomeFile";
|
||||
import "SomeFile" as b;
|
||||
import * from "SomeFile";
|
||||
import * as c from "SomeFile";
|
||||
import a as a from "SomeFile";
|
||||
import {a} from "someFile";
|
||||
import {a as b} from "Somefile";
|
||||
import {a, c as b} from "someFile";
|
||||
|
||||
contract Metacoin {
|
||||
|
||||
}
|
||||
|
||||
enum example {
|
||||
optioN,
|
||||
option2,
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,224 +0,0 @@
|
||||
#ifndef TREE_SITTER_PARSER_H_
|
||||
#define TREE_SITTER_PARSER_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define ts_builtin_sym_error ((TSSymbol)-1)
|
||||
#define ts_builtin_sym_end 0
|
||||
#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024
|
||||
|
||||
typedef uint16_t TSStateId;
|
||||
|
||||
#ifndef TREE_SITTER_API_H_
|
||||
typedef uint16_t TSSymbol;
|
||||
typedef uint16_t TSFieldId;
|
||||
typedef struct TSLanguage TSLanguage;
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
TSFieldId field_id;
|
||||
uint8_t child_index;
|
||||
bool inherited;
|
||||
} TSFieldMapEntry;
|
||||
|
||||
typedef struct {
|
||||
uint16_t index;
|
||||
uint16_t length;
|
||||
} TSFieldMapSlice;
|
||||
|
||||
typedef struct {
|
||||
bool visible;
|
||||
bool named;
|
||||
bool supertype;
|
||||
} TSSymbolMetadata;
|
||||
|
||||
typedef struct TSLexer TSLexer;
|
||||
|
||||
struct TSLexer {
|
||||
int32_t lookahead;
|
||||
TSSymbol result_symbol;
|
||||
void (*advance)(TSLexer *, bool);
|
||||
void (*mark_end)(TSLexer *);
|
||||
uint32_t (*get_column)(TSLexer *);
|
||||
bool (*is_at_included_range_start)(const TSLexer *);
|
||||
bool (*eof)(const TSLexer *);
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
TSParseActionTypeShift,
|
||||
TSParseActionTypeReduce,
|
||||
TSParseActionTypeAccept,
|
||||
TSParseActionTypeRecover,
|
||||
} TSParseActionType;
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
uint8_t type;
|
||||
TSStateId state;
|
||||
bool extra;
|
||||
bool repetition;
|
||||
} shift;
|
||||
struct {
|
||||
uint8_t type;
|
||||
uint8_t child_count;
|
||||
TSSymbol symbol;
|
||||
int16_t dynamic_precedence;
|
||||
uint16_t production_id;
|
||||
} reduce;
|
||||
uint8_t type;
|
||||
} TSParseAction;
|
||||
|
||||
typedef struct {
|
||||
uint16_t lex_state;
|
||||
uint16_t external_lex_state;
|
||||
} TSLexMode;
|
||||
|
||||
typedef union {
|
||||
TSParseAction action;
|
||||
struct {
|
||||
uint8_t count;
|
||||
bool reusable;
|
||||
} entry;
|
||||
} TSParseActionEntry;
|
||||
|
||||
struct TSLanguage {
|
||||
uint32_t version;
|
||||
uint32_t symbol_count;
|
||||
uint32_t alias_count;
|
||||
uint32_t token_count;
|
||||
uint32_t external_token_count;
|
||||
uint32_t state_count;
|
||||
uint32_t large_state_count;
|
||||
uint32_t production_id_count;
|
||||
uint32_t field_count;
|
||||
uint16_t max_alias_sequence_length;
|
||||
const uint16_t *parse_table;
|
||||
const uint16_t *small_parse_table;
|
||||
const uint32_t *small_parse_table_map;
|
||||
const TSParseActionEntry *parse_actions;
|
||||
const char * const *symbol_names;
|
||||
const char * const *field_names;
|
||||
const TSFieldMapSlice *field_map_slices;
|
||||
const TSFieldMapEntry *field_map_entries;
|
||||
const TSSymbolMetadata *symbol_metadata;
|
||||
const TSSymbol *public_symbol_map;
|
||||
const uint16_t *alias_map;
|
||||
const TSSymbol *alias_sequences;
|
||||
const TSLexMode *lex_modes;
|
||||
bool (*lex_fn)(TSLexer *, TSStateId);
|
||||
bool (*keyword_lex_fn)(TSLexer *, TSStateId);
|
||||
TSSymbol keyword_capture_token;
|
||||
struct {
|
||||
const bool *states;
|
||||
const TSSymbol *symbol_map;
|
||||
void *(*create)(void);
|
||||
void (*destroy)(void *);
|
||||
bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist);
|
||||
unsigned (*serialize)(void *, char *);
|
||||
void (*deserialize)(void *, const char *, unsigned);
|
||||
} external_scanner;
|
||||
const TSStateId *primary_state_ids;
|
||||
};
|
||||
|
||||
/*
|
||||
* Lexer Macros
|
||||
*/
|
||||
|
||||
#define START_LEXER() \
|
||||
bool result = false; \
|
||||
bool skip = false; \
|
||||
bool eof = false; \
|
||||
int32_t lookahead; \
|
||||
goto start; \
|
||||
next_state: \
|
||||
lexer->advance(lexer, skip); \
|
||||
start: \
|
||||
skip = false; \
|
||||
lookahead = lexer->lookahead;
|
||||
|
||||
#define ADVANCE(state_value) \
|
||||
{ \
|
||||
state = state_value; \
|
||||
goto next_state; \
|
||||
}
|
||||
|
||||
#define SKIP(state_value) \
|
||||
{ \
|
||||
skip = true; \
|
||||
state = state_value; \
|
||||
goto next_state; \
|
||||
}
|
||||
|
||||
#define ACCEPT_TOKEN(symbol_value) \
|
||||
result = true; \
|
||||
lexer->result_symbol = symbol_value; \
|
||||
lexer->mark_end(lexer);
|
||||
|
||||
#define END_STATE() return result;
|
||||
|
||||
/*
|
||||
* Parse Table Macros
|
||||
*/
|
||||
|
||||
#define SMALL_STATE(id) id - LARGE_STATE_COUNT
|
||||
|
||||
#define STATE(id) id
|
||||
|
||||
#define ACTIONS(id) id
|
||||
|
||||
#define SHIFT(state_value) \
|
||||
{{ \
|
||||
.shift = { \
|
||||
.type = TSParseActionTypeShift, \
|
||||
.state = state_value \
|
||||
} \
|
||||
}}
|
||||
|
||||
#define SHIFT_REPEAT(state_value) \
|
||||
{{ \
|
||||
.shift = { \
|
||||
.type = TSParseActionTypeShift, \
|
||||
.state = state_value, \
|
||||
.repetition = true \
|
||||
} \
|
||||
}}
|
||||
|
||||
#define SHIFT_EXTRA() \
|
||||
{{ \
|
||||
.shift = { \
|
||||
.type = TSParseActionTypeShift, \
|
||||
.extra = true \
|
||||
} \
|
||||
}}
|
||||
|
||||
#define REDUCE(symbol_val, child_count_val, ...) \
|
||||
{{ \
|
||||
.reduce = { \
|
||||
.type = TSParseActionTypeReduce, \
|
||||
.symbol = symbol_val, \
|
||||
.child_count = child_count_val, \
|
||||
__VA_ARGS__ \
|
||||
}, \
|
||||
}}
|
||||
|
||||
#define RECOVER() \
|
||||
{{ \
|
||||
.type = TSParseActionTypeRecover \
|
||||
}}
|
||||
|
||||
#define ACCEPT_INPUT() \
|
||||
{{ \
|
||||
.type = TSParseActionTypeAccept \
|
||||
}}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TREE_SITTER_PARSER_H_
|
||||
@ -1,106 +0,0 @@
|
||||
================================================================================
|
||||
Contract Constructor
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
constructor () {}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(constructor_definition
|
||||
body: (function_body)))))
|
||||
|
||||
================================================================================
|
||||
Contract Constructor Parameters
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
constructor (uint256 paramaeter0, user.type param1) {}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(constructor_definition
|
||||
(parameter
|
||||
type: (type_name
|
||||
(primitive_type))
|
||||
name: (identifier))
|
||||
(parameter
|
||||
type: (type_name
|
||||
(user_defined_type
|
||||
(identifier)
|
||||
(identifier)))
|
||||
name: (identifier))
|
||||
body: (function_body)))))
|
||||
|
||||
================================================================================
|
||||
Contract Constructor Modifier
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
constructor (uint256 paramaeter0, user.type param1) onlyOwner {}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(constructor_definition
|
||||
(parameter
|
||||
type: (type_name
|
||||
(primitive_type))
|
||||
name: (identifier))
|
||||
(parameter
|
||||
type: (type_name
|
||||
(user_defined_type
|
||||
(identifier)
|
||||
(identifier)))
|
||||
name: (identifier))
|
||||
(modifier_invocation
|
||||
(identifier))
|
||||
body: (function_body)))))
|
||||
|
||||
================================================================================
|
||||
Contract Constructor Keywords
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
constructor () payable public {}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(constructor_definition
|
||||
body: (function_body)))))
|
||||
|
||||
================================================================================
|
||||
Contract Constructor Keywords Order
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
constructor () internal payable {}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(constructor_definition
|
||||
body: (function_body)))))
|
||||
@ -1,78 +0,0 @@
|
||||
================================================================================
|
||||
Contract
|
||||
================================================================================
|
||||
|
||||
contract Example {}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body)))
|
||||
|
||||
================================================================================
|
||||
Abstract Contract
|
||||
================================================================================
|
||||
|
||||
abstract contract Example {}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body)))
|
||||
|
||||
================================================================================
|
||||
Inheriting contract
|
||||
================================================================================
|
||||
|
||||
contract Example is NotAContract() {}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
(inheritance_specifier
|
||||
ancestor: (user_defined_type
|
||||
(identifier)))
|
||||
body: (contract_body)))
|
||||
|
||||
================================================================================
|
||||
Inheriting contract without parentheses
|
||||
================================================================================
|
||||
|
||||
contract Example is NotAContract{}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
(inheritance_specifier
|
||||
ancestor: (user_defined_type
|
||||
(identifier)))
|
||||
body: (contract_body)))
|
||||
|
||||
================================================================================
|
||||
Multiple Inheritance
|
||||
================================================================================
|
||||
|
||||
contract Example is NotAContract(), AContract(1) {}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
(inheritance_specifier
|
||||
ancestor: (user_defined_type
|
||||
(identifier)))
|
||||
(inheritance_specifier
|
||||
ancestor: (user_defined_type
|
||||
(identifier))
|
||||
ancestor_arguments: (call_argument
|
||||
(number_literal)))
|
||||
body: (contract_body)))
|
||||
@ -1,30 +0,0 @@
|
||||
================================================================================
|
||||
Enum Declarations
|
||||
================================================================================
|
||||
|
||||
enum example {
|
||||
option1,
|
||||
option2,
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(enum_declaration
|
||||
name: (identifier)
|
||||
(enum_value)
|
||||
(enum_value)))
|
||||
|
||||
================================================================================
|
||||
Enum Declarations One Option
|
||||
================================================================================
|
||||
enum example {
|
||||
oneOption
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(enum_declaration
|
||||
name: (identifier)
|
||||
(enum_value)))
|
||||
@ -1,67 +0,0 @@
|
||||
================================================================================
|
||||
Error Declaration
|
||||
================================================================================
|
||||
|
||||
error Something(uint a);
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(error_declaration
|
||||
(identifier)
|
||||
(error_parameter
|
||||
(type_name
|
||||
(primitive_type))
|
||||
(identifier))))
|
||||
|
||||
================================================================================
|
||||
Revert with custom error
|
||||
================================================================================
|
||||
|
||||
function test() {
|
||||
revert Error();
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(function_definition
|
||||
(identifier)
|
||||
(function_body
|
||||
(revert_statement
|
||||
(identifier)
|
||||
(revert_arguments)))))
|
||||
|
||||
================================================================================
|
||||
Revert regularly
|
||||
================================================================================
|
||||
|
||||
function test() {
|
||||
revert(variableName);
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(function_definition
|
||||
(identifier)
|
||||
(function_body
|
||||
(revert_statement
|
||||
(parenthesized_expression
|
||||
(identifier))))))
|
||||
|
||||
================================================================================
|
||||
Very old revert
|
||||
================================================================================
|
||||
|
||||
function test() {
|
||||
revert;
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(function_definition
|
||||
(identifier)
|
||||
(function_body
|
||||
(revert_statement))))
|
||||
@ -1,81 +0,0 @@
|
||||
====================
|
||||
Event
|
||||
====================
|
||||
|
||||
contract Example {
|
||||
event Exx();
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(event_definition
|
||||
name: (identifier)))))
|
||||
|
||||
====================
|
||||
Event anonymous
|
||||
====================
|
||||
|
||||
contract Example {
|
||||
event Exx() anonymous;
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(event_definition
|
||||
name: (identifier)))))
|
||||
|
||||
|
||||
====================
|
||||
Event parameter
|
||||
====================
|
||||
|
||||
contract Example {
|
||||
event Exx(int) anonymous;
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(event_definition
|
||||
name: (identifier)
|
||||
(event_paramater type: (type_name (primitive_type)))))))
|
||||
|
||||
====================
|
||||
Event parameters
|
||||
====================
|
||||
|
||||
contract Example {
|
||||
event Exx(int, int named, int indexed, int indexed name);
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(event_definition
|
||||
name: (identifier)
|
||||
|
||||
(event_paramater type: (type_name (primitive_type)))
|
||||
|
||||
(event_paramater
|
||||
type: (type_name (primitive_type))
|
||||
name: (identifier))
|
||||
|
||||
(event_paramater type: (type_name (primitive_type)))
|
||||
|
||||
(event_paramater
|
||||
type: (type_name (primitive_type))
|
||||
name: (identifier))))))
|
||||
@ -1,645 +0,0 @@
|
||||
================================================================================
|
||||
Member Access
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function example() {
|
||||
int a;
|
||||
a.b;
|
||||
TypeA memory a = new TypeA(1);
|
||||
TypeA[] a = new TypeA[](1);
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
body: (function_body
|
||||
(variable_declaration_statement
|
||||
(variable_declaration
|
||||
type: (type_name
|
||||
(primitive_type))
|
||||
name: (identifier)))
|
||||
(expression_statement
|
||||
(member_expression
|
||||
object: (identifier)
|
||||
property: (identifier)))
|
||||
(variable_declaration_statement
|
||||
(variable_declaration
|
||||
type: (type_name
|
||||
(user_defined_type
|
||||
(identifier)))
|
||||
name: (identifier))
|
||||
value: (call_expression
|
||||
function: (new_expression
|
||||
name: (type_name
|
||||
(user_defined_type
|
||||
(identifier))))
|
||||
(call_argument
|
||||
(number_literal))))
|
||||
(variable_declaration_statement
|
||||
(variable_declaration
|
||||
type: (type_name
|
||||
(type_name
|
||||
(user_defined_type
|
||||
(identifier))))
|
||||
name: (identifier))
|
||||
value: (call_expression
|
||||
function: (new_expression
|
||||
name: (type_name
|
||||
(type_name
|
||||
(user_defined_type
|
||||
(identifier)))))
|
||||
(call_argument
|
||||
(number_literal)))))))))
|
||||
|
||||
================================================================================
|
||||
Subscript Access
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function example() {
|
||||
a[1];
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
body: (function_body
|
||||
(expression_statement
|
||||
(array_access
|
||||
base: (identifier)
|
||||
index: (number_literal))))))))
|
||||
|
||||
================================================================================
|
||||
Slice Access
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function example() {
|
||||
a[1:];
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
body: (function_body
|
||||
(expression_statement
|
||||
(slice_access
|
||||
base: (identifier)
|
||||
from: (number_literal))))))))
|
||||
|
||||
================================================================================
|
||||
Parenthesized expression
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function example() {
|
||||
(1);
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
body: (function_body
|
||||
(expression_statement
|
||||
(parenthesized_expression
|
||||
(number_literal))))))))
|
||||
|
||||
================================================================================
|
||||
Maths expression
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function example() {
|
||||
1+1;
|
||||
++a;
|
||||
a>>b;
|
||||
a<=b;
|
||||
a||c;
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
body: (function_body
|
||||
(expression_statement
|
||||
(binary_expression
|
||||
left: (number_literal)
|
||||
right: (number_literal)))
|
||||
(expression_statement
|
||||
(update_expression
|
||||
argument: (identifier)))
|
||||
(expression_statement
|
||||
(binary_expression
|
||||
left: (identifier)
|
||||
right: (identifier)))
|
||||
(expression_statement
|
||||
(binary_expression
|
||||
left: (identifier)
|
||||
right: (identifier)))
|
||||
(expression_statement
|
||||
(binary_expression
|
||||
left: (identifier)
|
||||
right: (identifier))))))))
|
||||
|
||||
================================================================================
|
||||
Struct expression
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function example() {
|
||||
a{b: c};
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
body: (function_body
|
||||
(expression_statement
|
||||
(struct_expression
|
||||
type: (identifier)
|
||||
(struct_field_assignment
|
||||
name: (identifier)
|
||||
value: (identifier)))))))))
|
||||
|
||||
================================================================================
|
||||
Call
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function example() {
|
||||
a(b);
|
||||
c({d: e, f: g});
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
body: (function_body
|
||||
(expression_statement
|
||||
(call_expression
|
||||
function: (identifier)
|
||||
(call_argument
|
||||
(identifier))))
|
||||
(expression_statement
|
||||
(call_expression
|
||||
function: (identifier)
|
||||
(call_argument
|
||||
(call_struct_argument
|
||||
name: (identifier)
|
||||
value: (identifier))
|
||||
(call_struct_argument
|
||||
name: (identifier)
|
||||
value: (identifier))))))))))
|
||||
|
||||
================================================================================
|
||||
Payable conversion
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function example() {
|
||||
payable(b);
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
body: (function_body
|
||||
(expression_statement
|
||||
(payable_conversion_expression
|
||||
(call_argument
|
||||
(identifier)))))))))
|
||||
|
||||
================================================================================
|
||||
increment and unary
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function example() {
|
||||
++b;
|
||||
delete b;
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
body: (function_body
|
||||
(expression_statement
|
||||
(update_expression
|
||||
argument: (identifier)))
|
||||
(expression_statement
|
||||
(unary_expression
|
||||
argument: (identifier))))))))
|
||||
|
||||
================================================================================
|
||||
call and unary
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function example() {
|
||||
!call();
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
body: (function_body
|
||||
(expression_statement
|
||||
(unary_expression
|
||||
argument: (call_expression
|
||||
function: (identifier)))))))))
|
||||
|
||||
================================================================================
|
||||
call and binary
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function example() {
|
||||
value == call();
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
body: (function_body
|
||||
(expression_statement
|
||||
(binary_expression
|
||||
left: (identifier)
|
||||
right: (call_expression
|
||||
function: (identifier)))))))))
|
||||
|
||||
================================================================================
|
||||
Boolean logic
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function example() {
|
||||
a && b;
|
||||
a || c;
|
||||
|
||||
// Bit
|
||||
a & c;
|
||||
a ^ d;
|
||||
a | b;
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
body: (function_body
|
||||
(expression_statement
|
||||
(binary_expression
|
||||
left: (identifier)
|
||||
right: (identifier)))
|
||||
(expression_statement
|
||||
(binary_expression
|
||||
left: (identifier)
|
||||
right: (identifier)))
|
||||
(comment)
|
||||
(expression_statement
|
||||
(binary_expression
|
||||
left: (identifier)
|
||||
right: (identifier)))
|
||||
(expression_statement
|
||||
(binary_expression
|
||||
left: (identifier)
|
||||
right: (identifier)))
|
||||
(expression_statement
|
||||
(binary_expression
|
||||
left: (identifier)
|
||||
right: (identifier))))))))
|
||||
|
||||
================================================================================
|
||||
Comparisons
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function example() {
|
||||
a == b;
|
||||
a < b;
|
||||
a > b;
|
||||
a >= b;
|
||||
a <= b;
|
||||
a != b;
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
(identifier)
|
||||
(contract_body
|
||||
(function_definition
|
||||
(identifier)
|
||||
(function_body
|
||||
(expression_statement
|
||||
(binary_expression
|
||||
(identifier)
|
||||
(identifier)))
|
||||
(expression_statement
|
||||
(binary_expression
|
||||
(identifier)
|
||||
(identifier)))
|
||||
(expression_statement
|
||||
(binary_expression
|
||||
(identifier)
|
||||
(identifier)))
|
||||
(expression_statement
|
||||
(binary_expression
|
||||
(identifier)
|
||||
(identifier)))
|
||||
(expression_statement
|
||||
(binary_expression
|
||||
(identifier)
|
||||
(identifier)))
|
||||
(expression_statement
|
||||
(binary_expression
|
||||
(identifier)
|
||||
(identifier))))))))
|
||||
|
||||
================================================================================
|
||||
Update expression
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function example() {
|
||||
a = b;
|
||||
a |= b;
|
||||
a /= c;
|
||||
a %= d;
|
||||
a >>>= d;
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
(identifier)
|
||||
(contract_body
|
||||
(function_definition
|
||||
(identifier)
|
||||
(function_body
|
||||
(expression_statement
|
||||
(assignment_expression
|
||||
(identifier)
|
||||
(identifier)))
|
||||
(expression_statement
|
||||
(augmented_assignment_expression
|
||||
(identifier)
|
||||
(identifier)))
|
||||
(expression_statement
|
||||
(augmented_assignment_expression
|
||||
(identifier)
|
||||
(identifier)))
|
||||
(expression_statement
|
||||
(augmented_assignment_expression
|
||||
(identifier)
|
||||
(identifier)))
|
||||
(expression_statement
|
||||
(augmented_assignment_expression
|
||||
(identifier)
|
||||
(identifier))))))))
|
||||
|
||||
================================================================================
|
||||
Special Expression types
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function example() {
|
||||
(a, b);
|
||||
[1, 2];
|
||||
identifier;
|
||||
1;
|
||||
user.type;
|
||||
uint;
|
||||
}
|
||||
}
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
(identifier)
|
||||
(contract_body
|
||||
(function_definition
|
||||
(identifier)
|
||||
(function_body
|
||||
(expression_statement
|
||||
(tuple_expression
|
||||
(identifier)
|
||||
(identifier)))
|
||||
(expression_statement
|
||||
(inline_array_expression
|
||||
(number_literal)
|
||||
(number_literal)))
|
||||
(expression_statement
|
||||
(identifier))
|
||||
(expression_statement
|
||||
(number_literal))
|
||||
(expression_statement
|
||||
(member_expression
|
||||
(identifier)
|
||||
(identifier)))
|
||||
(expression_statement
|
||||
(primitive_type)))))))
|
||||
|
||||
================================================================================
|
||||
New expression
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function example() {
|
||||
new lambo;
|
||||
}
|
||||
}
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
(identifier)
|
||||
(contract_body
|
||||
(function_definition
|
||||
(identifier)
|
||||
(function_body
|
||||
(expression_statement
|
||||
(new_expression
|
||||
(type_name
|
||||
(user_defined_type
|
||||
(identifier))))))))))
|
||||
|
||||
================================================================================
|
||||
Ternary expression
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function example() {
|
||||
a ? b : c;
|
||||
}
|
||||
}
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
(identifier)
|
||||
(contract_body
|
||||
(function_definition
|
||||
(identifier)
|
||||
(function_body
|
||||
(expression_statement
|
||||
(ternary_expression
|
||||
(identifier)
|
||||
(identifier)
|
||||
(identifier))))))))
|
||||
|
||||
================================================================================
|
||||
Type cast
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function example() {
|
||||
uint64(2);
|
||||
}
|
||||
}
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
(identifier)
|
||||
(contract_body
|
||||
(function_definition
|
||||
(identifier)
|
||||
(function_body
|
||||
(expression_statement
|
||||
(type_cast_expression
|
||||
(primitive_type)
|
||||
(number_literal))))))))
|
||||
|
||||
================================================================================
|
||||
Type Expression
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function example() {
|
||||
uint64[2][2];
|
||||
}
|
||||
}
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
(identifier)
|
||||
(contract_body
|
||||
(function_definition
|
||||
(identifier)
|
||||
(function_body
|
||||
(expression_statement
|
||||
(array_access
|
||||
(array_access
|
||||
(primitive_type)
|
||||
(number_literal))
|
||||
(number_literal))))))))
|
||||
|
||||
================================================================================
|
||||
Type Cast Expression Nested (TODO: Solidity specification is wrong here fix it)
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function example(bytes b) {
|
||||
uint64[2][2] (b);
|
||||
}
|
||||
}
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
(identifier)
|
||||
(contract_body
|
||||
(function_definition
|
||||
(identifier)
|
||||
(parameter
|
||||
(type_name
|
||||
(primitive_type))
|
||||
(identifier))
|
||||
(function_body
|
||||
(expression_statement
|
||||
(call_expression
|
||||
(array_access
|
||||
(array_access
|
||||
(primitive_type)
|
||||
(number_literal))
|
||||
(number_literal))
|
||||
(call_argument
|
||||
(identifier)))))))))
|
||||
@ -1,74 +0,0 @@
|
||||
================================================================================
|
||||
Function Fallback
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
fallback () {}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(fallback_receive_definition
|
||||
body: (function_body)))))
|
||||
|
||||
================================================================================
|
||||
Function Fallback
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
receive () {}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(fallback_receive_definition
|
||||
body: (function_body)))))
|
||||
|
||||
================================================================================
|
||||
Function Fallback with modifiers and visibility
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
receive () onlyOwner virtual override(param) {}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(fallback_receive_definition
|
||||
(modifier_invocation
|
||||
(identifier))
|
||||
(virtual)
|
||||
(override_specifier
|
||||
(user_defined_type
|
||||
(identifier)))
|
||||
body: (function_body)))))
|
||||
|
||||
|
||||
================================================================================
|
||||
Function Old Fallback
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function () {}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(fallback_receive_definition
|
||||
body: (function_body)))))
|
||||
@ -1,189 +0,0 @@
|
||||
================================================================================
|
||||
Function
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function exampleFunction () {}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
body: (function_body)))))
|
||||
|
||||
================================================================================
|
||||
Function with argument
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function exampleFunction (string argument) {}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
(parameter
|
||||
type: (type_name
|
||||
(primitive_type))
|
||||
name: (identifier))
|
||||
body: (function_body)))))
|
||||
|
||||
================================================================================
|
||||
Function with return type
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function exampleFunction () returns (string, uint256 element) {}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
return_type: (return_type_definition
|
||||
(parameter
|
||||
type: (type_name
|
||||
(primitive_type)))
|
||||
(parameter
|
||||
type: (type_name
|
||||
(primitive_type))
|
||||
name: (identifier)))
|
||||
body: (function_body)))))
|
||||
|
||||
================================================================================
|
||||
Function with visibility, mutability, modifier and virtual
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function exampleFunction () payable external onlyOwner virtual returns (string, uint256 element) {}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
(state_mutability)
|
||||
(visibility)
|
||||
(modifier_invocation
|
||||
(identifier))
|
||||
(virtual)
|
||||
return_type: (return_type_definition
|
||||
(parameter
|
||||
type: (type_name
|
||||
(primitive_type)))
|
||||
(parameter
|
||||
type: (type_name
|
||||
(primitive_type))
|
||||
name: (identifier)))
|
||||
body: (function_body)))))
|
||||
|
||||
================================================================================
|
||||
Function with override
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function exampleFunction () override {}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
(override_specifier)
|
||||
body: (function_body)))))
|
||||
|
||||
================================================================================
|
||||
Function with explicit override
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function exampleFunction () override (element.name, item) {}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
(override_specifier
|
||||
(user_defined_type
|
||||
(identifier)
|
||||
(identifier))
|
||||
(user_defined_type
|
||||
(identifier)))
|
||||
body: (function_body)))))
|
||||
|
||||
================================================================================
|
||||
Function without block
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function exampleFunction ();
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(function_definition
|
||||
name: (identifier)))))
|
||||
|
||||
================================================================================
|
||||
Function not in contract
|
||||
================================================================================
|
||||
|
||||
function exampleFunction ();
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(function_definition
|
||||
name: (identifier)))
|
||||
|
||||
================================================================================
|
||||
Function with function type argument
|
||||
================================================================================
|
||||
|
||||
function exampleFunction (function(uint) public returns(bool));
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
(parameter
|
||||
type: (type_name
|
||||
parameters: (parameter
|
||||
type: (type_name
|
||||
(primitive_type)))
|
||||
(visibility)
|
||||
(return_parameter
|
||||
type: (type_name
|
||||
(primitive_type)))))))
|
||||
@ -1,75 +0,0 @@
|
||||
================================================================================
|
||||
Import
|
||||
================================================================================
|
||||
|
||||
import "./path";
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(import_directive
|
||||
(string)))
|
||||
|
||||
================================================================================
|
||||
Import As
|
||||
================================================================================
|
||||
|
||||
import "./path" as someIdentifier;
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(import_directive
|
||||
(string)
|
||||
(identifier)))
|
||||
|
||||
================================================================================
|
||||
Import from
|
||||
================================================================================
|
||||
|
||||
import { ERC20 } from "./path/contract.sol";
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(import_directive
|
||||
import_name: (identifier)
|
||||
source: (string)))
|
||||
|
||||
================================================================================
|
||||
Import from aliases
|
||||
================================================================================
|
||||
|
||||
import { ERC20 as Token } from "./path/contract.sol";
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(import_directive
|
||||
import_name: (identifier)
|
||||
alias: (identifier)
|
||||
source: (string)))
|
||||
|
||||
================================================================================
|
||||
Import multiple
|
||||
================================================================================
|
||||
|
||||
import { ERC20 as Token, ERC721 } from "./path/contract.sol";
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(import_directive
|
||||
import_name: (identifier)
|
||||
alias: (identifier)
|
||||
import_name: (identifier)
|
||||
source: (string)))
|
||||
|
||||
================================================================================
|
||||
Import single alias
|
||||
================================================================================
|
||||
|
||||
import * as ContractFile from "./path/contract.sol";
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(import_directive
|
||||
alias: (identifier)
|
||||
source: (string)))
|
||||
@ -1,49 +0,0 @@
|
||||
================================================================================
|
||||
Interface
|
||||
================================================================================
|
||||
|
||||
interface Example {}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(interface_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body)))
|
||||
|
||||
================================================================================
|
||||
Inheriting inteface
|
||||
================================================================================
|
||||
|
||||
interface Example is NotAContract() {}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(interface_declaration
|
||||
name: (identifier)
|
||||
(inheritance_specifier
|
||||
ancestor: (user_defined_type
|
||||
(identifier)))
|
||||
body: (contract_body)))
|
||||
|
||||
================================================================================
|
||||
Multiple Inheritance Interface
|
||||
================================================================================
|
||||
|
||||
interface Example is NotAContract(), AContract(1) {}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(interface_declaration
|
||||
name: (identifier)
|
||||
(inheritance_specifier
|
||||
ancestor: (user_defined_type
|
||||
(identifier)))
|
||||
(inheritance_specifier
|
||||
ancestor: (user_defined_type
|
||||
(identifier))
|
||||
ancestor_arguments: (call_argument
|
||||
(number_literal)))
|
||||
body: (contract_body)))
|
||||
@ -1,14 +0,0 @@
|
||||
====================
|
||||
Library
|
||||
====================
|
||||
|
||||
library Example {}
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(library_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body)))
|
||||
|
||||
|
||||
@ -1,180 +0,0 @@
|
||||
================================================================================
|
||||
Integer Literal
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function example() {
|
||||
11;
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
body: (function_body
|
||||
(expression_statement
|
||||
(number_literal)))))))
|
||||
|
||||
================================================================================
|
||||
String Literal
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function example() {
|
||||
"example";
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
body: (function_body
|
||||
(expression_statement
|
||||
(string_literal
|
||||
(string))))))))
|
||||
|
||||
================================================================================
|
||||
Double String Literal
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function example() {
|
||||
"example" "another string";
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
body: (function_body
|
||||
(expression_statement
|
||||
(string_literal
|
||||
(string)
|
||||
(string))))))))
|
||||
|
||||
================================================================================
|
||||
String Literal Escapes
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function example() {
|
||||
"example ' ";
|
||||
"\\yeah";
|
||||
'also a String with "';
|
||||
"";
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
body: (function_body
|
||||
(expression_statement
|
||||
(string_literal
|
||||
(string)))
|
||||
(expression_statement
|
||||
(string_literal
|
||||
(string)))
|
||||
(expression_statement
|
||||
(string_literal
|
||||
(string)))
|
||||
(expression_statement
|
||||
(string_literal
|
||||
(string))))))))
|
||||
|
||||
================================================================================
|
||||
Hex String Literal
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function example() {
|
||||
hex "aa";
|
||||
hex "aa_bb";
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
body: (function_body
|
||||
(expression_statement
|
||||
(hex_string_literal))
|
||||
(expression_statement
|
||||
(hex_string_literal)))))))
|
||||
|
||||
================================================================================
|
||||
Unicode String Literal
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function example() {
|
||||
unicode"asdf";
|
||||
unicode"😁";
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
body: (function_body
|
||||
(expression_statement
|
||||
(unicode_string_literal))
|
||||
(expression_statement
|
||||
(unicode_string_literal)))))))
|
||||
|
||||
================================================================================
|
||||
Bool Literal
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function example() {
|
||||
true;
|
||||
false;
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
body: (function_body
|
||||
(expression_statement
|
||||
(boolean_literal
|
||||
(true)))
|
||||
(expression_statement
|
||||
(boolean_literal
|
||||
(false))))))))
|
||||
@ -1,92 +0,0 @@
|
||||
================================================================================
|
||||
Modifier
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
modifier onlyOwner {}
|
||||
}
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(modifier_definition
|
||||
name: (identifier)
|
||||
body: (function_body)))))
|
||||
|
||||
================================================================================
|
||||
Modifier with parameter
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
modifier onlyOwner(address owner) {}
|
||||
}
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(modifier_definition
|
||||
name: (identifier)
|
||||
(parameter
|
||||
type: (type_name
|
||||
(primitive_type))
|
||||
name: (identifier))
|
||||
body: (function_body)))))
|
||||
|
||||
================================================================================
|
||||
Modifier virtual
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
modifier onlyOwner virtual {}
|
||||
}
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(modifier_definition
|
||||
name: (identifier)
|
||||
(virtual)
|
||||
body: (function_body)))))
|
||||
|
||||
================================================================================
|
||||
Modifier override
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
modifier onlyOwner override (element.be) {}
|
||||
}
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(modifier_definition
|
||||
name: (identifier)
|
||||
(override_specifier
|
||||
(user_defined_type
|
||||
(identifier)
|
||||
(identifier)))
|
||||
body: (function_body)))))
|
||||
|
||||
================================================================================
|
||||
Modifier empty
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
modifier onlyOwner;
|
||||
}
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(modifier_definition
|
||||
name: (identifier)))))
|
||||
@ -1,123 +0,0 @@
|
||||
================================================================================
|
||||
Pragma Any
|
||||
================================================================================
|
||||
|
||||
pragma experimental abiencoderv2;
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(pragma_directive
|
||||
(any_pragma_token
|
||||
(identifier)
|
||||
(pragma_value))))
|
||||
|
||||
================================================================================
|
||||
Pragma Directive
|
||||
================================================================================
|
||||
|
||||
pragma solidity 0.4.0;
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(pragma_directive
|
||||
(solidity_pragma_token
|
||||
(solidity_version))))
|
||||
|
||||
================================================================================
|
||||
Multiple Pragma Directives
|
||||
================================================================================
|
||||
|
||||
pragma solidity 0.4.0 0.5.0;
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(pragma_directive
|
||||
(solidity_pragma_token
|
||||
(solidity_version)
|
||||
(solidity_version))))
|
||||
|
||||
================================================================================
|
||||
Equality Pragma Directives
|
||||
================================================================================
|
||||
|
||||
pragma solidity <0.4.0 ^0.5.0 ~0.5;
|
||||
pragma solidity =0.4;
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(pragma_directive
|
||||
(solidity_pragma_token
|
||||
(solidity_version_comparison_operator)
|
||||
(solidity_version)
|
||||
(solidity_version_comparison_operator)
|
||||
(solidity_version)
|
||||
(solidity_version_comparison_operator)
|
||||
(solidity_version)))
|
||||
(pragma_directive
|
||||
(solidity_pragma_token
|
||||
(solidity_version_comparison_operator)
|
||||
(solidity_version))))
|
||||
|
||||
================================================================================
|
||||
Or Solidity Pragma Directives
|
||||
================================================================================
|
||||
|
||||
pragma solidity ^0.5.0 || ^0.6.0;
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(pragma_directive
|
||||
(solidity_pragma_token
|
||||
(solidity_version_comparison_operator)
|
||||
(solidity_version)
|
||||
(solidity_version_comparison_operator)
|
||||
(solidity_version))))
|
||||
|
||||
================================================================================
|
||||
Dot sol pragma
|
||||
================================================================================
|
||||
|
||||
pragma solidity .0;
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(pragma_directive
|
||||
(solidity_pragma_token
|
||||
(solidity_version))))
|
||||
|
||||
================================================================================
|
||||
Star sol pragma
|
||||
================================================================================
|
||||
|
||||
pragma solidity 0.8.*;
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(pragma_directive
|
||||
(solidity_pragma_token
|
||||
(solidity_version))))
|
||||
|
||||
================================================================================
|
||||
String solidity pragma
|
||||
================================================================================
|
||||
|
||||
pragma solidity "0.8.12";
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(pragma_directive
|
||||
(solidity_pragma_token
|
||||
(solidity_version))))
|
||||
@ -1,62 +0,0 @@
|
||||
================================================================================
|
||||
Variable Declaration
|
||||
================================================================================
|
||||
|
||||
contract StateVariable {
|
||||
int b;
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(state_variable_declaration
|
||||
type: (type_name
|
||||
(primitive_type))
|
||||
name: (identifier)))))
|
||||
|
||||
================================================================================
|
||||
Variable Declaration with initial value
|
||||
================================================================================
|
||||
|
||||
contract StateVariable {
|
||||
int b = 1;
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(state_variable_declaration
|
||||
type: (type_name
|
||||
(primitive_type))
|
||||
name: (identifier)
|
||||
value: (number_literal)))))
|
||||
|
||||
================================================================================
|
||||
Variable Declaration
|
||||
================================================================================
|
||||
|
||||
contract StateVariable {
|
||||
int override(a.b) c = 3;
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(state_variable_declaration
|
||||
type: (type_name
|
||||
(primitive_type))
|
||||
(override_specifier
|
||||
(user_defined_type
|
||||
(identifier)
|
||||
(identifier)))
|
||||
name: (identifier)
|
||||
value: (number_literal)))))
|
||||
@ -1,346 +0,0 @@
|
||||
================================================================================
|
||||
Array local variable declaration
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function example() {
|
||||
int[] a;
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
body: (function_body
|
||||
(variable_declaration_statement
|
||||
(variable_declaration
|
||||
type: (type_name
|
||||
(type_name
|
||||
(primitive_type)))
|
||||
name: (identifier))))))))
|
||||
|
||||
================================================================================
|
||||
Array local variable declaration subtype
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function example() {
|
||||
A.B[] storage a;
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
body: (function_body
|
||||
(variable_declaration_statement
|
||||
(variable_declaration
|
||||
type: (type_name
|
||||
(type_name
|
||||
(user_defined_type
|
||||
(identifier)
|
||||
(identifier))))
|
||||
name: (identifier))))))))
|
||||
|
||||
================================================================================
|
||||
Block statement
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function example() {
|
||||
{
|
||||
1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
(identifier)
|
||||
(contract_body
|
||||
(function_definition
|
||||
(identifier)
|
||||
(function_body
|
||||
(block_statement
|
||||
(expression_statement
|
||||
(number_literal))))))))
|
||||
|
||||
================================================================================
|
||||
If statement
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function example() {
|
||||
if (a) {
|
||||
|
||||
}
|
||||
if (d) {} else {
|
||||
b;
|
||||
}
|
||||
if (a) 1;
|
||||
|
||||
if (input >= 1) if (input > 2) 1; else 2;
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
(identifier)
|
||||
(contract_body
|
||||
(function_definition
|
||||
(identifier)
|
||||
(function_body
|
||||
(if_statement
|
||||
(identifier)
|
||||
(block_statement))
|
||||
(if_statement
|
||||
(identifier)
|
||||
(block_statement)
|
||||
(block_statement
|
||||
(expression_statement
|
||||
(identifier))))
|
||||
(if_statement
|
||||
(identifier)
|
||||
(expression_statement
|
||||
(number_literal)))
|
||||
(if_statement
|
||||
(binary_expression
|
||||
(identifier)
|
||||
(number_literal))
|
||||
(if_statement
|
||||
(binary_expression
|
||||
(identifier)
|
||||
(number_literal))
|
||||
(expression_statement
|
||||
(number_literal))
|
||||
(expression_statement
|
||||
(number_literal)))))))))
|
||||
|
||||
================================================================================
|
||||
For statement
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function example() {
|
||||
for (int i = 0; i++; i < 10) e++;
|
||||
for (; i++; i < 10) e++;
|
||||
for (;; i < 10) e++;
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
(identifier)
|
||||
(contract_body
|
||||
(function_definition
|
||||
(identifier)
|
||||
(function_body
|
||||
(for_statement
|
||||
(variable_declaration_statement
|
||||
(variable_declaration
|
||||
(type_name
|
||||
(primitive_type))
|
||||
(identifier))
|
||||
(number_literal))
|
||||
(expression_statement
|
||||
(update_expression
|
||||
(identifier)))
|
||||
(binary_expression
|
||||
(identifier)
|
||||
(number_literal))
|
||||
(expression_statement
|
||||
(update_expression
|
||||
(identifier))))
|
||||
(for_statement
|
||||
(expression_statement
|
||||
(update_expression
|
||||
(identifier)))
|
||||
(binary_expression
|
||||
(identifier)
|
||||
(number_literal))
|
||||
(expression_statement
|
||||
(update_expression
|
||||
(identifier))))
|
||||
(for_statement
|
||||
(binary_expression
|
||||
(identifier)
|
||||
(number_literal))
|
||||
(expression_statement
|
||||
(update_expression
|
||||
(identifier)))))))))
|
||||
|
||||
================================================================================
|
||||
While statement
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function example() {
|
||||
while (true) return;
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
(identifier)
|
||||
(contract_body
|
||||
(function_definition
|
||||
(identifier)
|
||||
(function_body
|
||||
(while_statement
|
||||
(boolean_literal
|
||||
(true))
|
||||
(return_statement)))))))
|
||||
|
||||
================================================================================
|
||||
While statement 2
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function example() {
|
||||
while (true) {
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
(identifier)
|
||||
(contract_body
|
||||
(function_definition
|
||||
(identifier)
|
||||
(function_body
|
||||
(while_statement
|
||||
(boolean_literal
|
||||
(true))
|
||||
(block_statement
|
||||
(break_statement)
|
||||
(continue_statement))))))))
|
||||
|
||||
================================================================================
|
||||
Try statement
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function example() {
|
||||
try callSomething() returns (uint param) {
|
||||
param++;
|
||||
} catch errorMessage(uint value) {
|
||||
param--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
(identifier)
|
||||
(contract_body
|
||||
(function_definition
|
||||
(identifier)
|
||||
(function_body
|
||||
(try_statement
|
||||
(call_expression
|
||||
(identifier))
|
||||
(parameter
|
||||
(type_name
|
||||
(primitive_type))
|
||||
(identifier))
|
||||
(block_statement
|
||||
(expression_statement
|
||||
(update_expression
|
||||
(identifier))))
|
||||
(catch_clause
|
||||
(identifier)
|
||||
(parameter
|
||||
(type_name
|
||||
(primitive_type))
|
||||
(identifier))
|
||||
(block_statement
|
||||
(expression_statement
|
||||
(update_expression
|
||||
(identifier)))))))))))
|
||||
|
||||
================================================================================
|
||||
Return statement
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function example() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
(identifier)
|
||||
(contract_body
|
||||
(function_definition
|
||||
(identifier)
|
||||
(function_body
|
||||
(return_statement))))))
|
||||
|
||||
================================================================================
|
||||
Emit statement
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function example() {
|
||||
emit logmessage();
|
||||
}
|
||||
}
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
(identifier)
|
||||
(contract_body
|
||||
(function_definition
|
||||
(identifier)
|
||||
(function_body
|
||||
(emit_statement
|
||||
(identifier)))))))
|
||||
|
||||
================================================================================
|
||||
Assembly statement
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function example() {
|
||||
emit logmessage();
|
||||
}
|
||||
}
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
(identifier)
|
||||
(contract_body
|
||||
(function_definition
|
||||
(identifier)
|
||||
(function_body
|
||||
(emit_statement
|
||||
(identifier)))))))
|
||||
@ -1,16 +0,0 @@
|
||||
====================
|
||||
Struct Declarations
|
||||
====================
|
||||
|
||||
struct example {
|
||||
uint256 element_a;
|
||||
int element_b;
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(struct_declaration
|
||||
(identifier)
|
||||
(struct_member (type_name (primitive_type)) (identifier))
|
||||
(struct_member (type_name (primitive_type)) (identifier))))
|
||||
@ -1,34 +0,0 @@
|
||||
====================
|
||||
Using directive
|
||||
====================
|
||||
|
||||
contract Example {
|
||||
using user.defined for *;
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(using_directive
|
||||
(type_alias (identifier) (identifier))
|
||||
source: (any_source_type)))))
|
||||
====================
|
||||
Using directive
|
||||
====================
|
||||
|
||||
contract Example {
|
||||
using user.defined for uint256;
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
name: (identifier)
|
||||
body: (contract_body
|
||||
(using_directive
|
||||
(type_alias (identifier) (identifier))
|
||||
source: (type_name (primitive_type))))))
|
||||
@ -1,146 +0,0 @@
|
||||
================================================================================
|
||||
Assembly
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function() {
|
||||
assembly {
|
||||
add(0x40, 0x60)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
(identifier)
|
||||
(contract_body
|
||||
(fallback_receive_definition
|
||||
(function_body
|
||||
(assembly_statement
|
||||
(yul_function_call
|
||||
(yul_evm_builtin)
|
||||
(yul_hex_number)
|
||||
(yul_hex_number))))))))
|
||||
|
||||
================================================================================
|
||||
Assembly switch
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function() {
|
||||
assembly {
|
||||
switch literal
|
||||
case 1 {
|
||||
return(a)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
(identifier)
|
||||
(contract_body
|
||||
(fallback_receive_definition
|
||||
(function_body
|
||||
(assembly_statement
|
||||
(yul_switch_statement
|
||||
(yul_path
|
||||
(yul_identifier
|
||||
(identifier)))
|
||||
(yul_decimal_number)
|
||||
(yul_block
|
||||
(yul_function_call
|
||||
(yul_evm_builtin)
|
||||
(yul_path
|
||||
(yul_identifier
|
||||
(identifier))))))))))))
|
||||
|
||||
================================================================================
|
||||
Assembly Assignment
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function() {
|
||||
assembly {
|
||||
_origin1 := 1
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
(identifier)
|
||||
(contract_body
|
||||
(fallback_receive_definition
|
||||
(function_body
|
||||
(assembly_statement
|
||||
(yul_assignment
|
||||
(yul_path
|
||||
(yul_identifier
|
||||
(identifier)))
|
||||
(yul_decimal_number))))))))
|
||||
|
||||
================================================================================
|
||||
Builtin Functions
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function() {
|
||||
assembly {
|
||||
sub(gas, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
(identifier)
|
||||
(contract_body
|
||||
(fallback_receive_definition
|
||||
(function_body
|
||||
(assembly_statement
|
||||
(yul_function_call
|
||||
(yul_evm_builtin)
|
||||
(yul_function_call
|
||||
(yul_evm_builtin))
|
||||
(yul_decimal_number))))))))
|
||||
|
||||
================================================================================
|
||||
Labels
|
||||
================================================================================
|
||||
|
||||
contract Example {
|
||||
function() {
|
||||
assembly {
|
||||
loop:
|
||||
sub(gas, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(contract_declaration
|
||||
(identifier)
|
||||
(contract_body
|
||||
(fallback_receive_definition
|
||||
(function_body
|
||||
(assembly_statement
|
||||
(yul_label
|
||||
(identifier))
|
||||
(yul_function_call
|
||||
(yul_evm_builtin)
|
||||
(yul_function_call
|
||||
(yul_evm_builtin))
|
||||
(yul_decimal_number))))))))
|
||||
@ -1,8 +0,0 @@
|
||||
contract test {
|
||||
function f() view {
|
||||
return 2;
|
||||
}
|
||||
function g() pure {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
@ -1,748 +0,0 @@
|
||||
// Credit for this file goes to Gonçalo Sá and Federico Bond: https://github.com/ConsenSys/solidity-parser-antlr/commits/master/test/test.sol
|
||||
pragma solidity 0.4.4;
|
||||
pragma solidity ^0.4.4;
|
||||
pragma solidity ~0.4.4;
|
||||
pragma solidity >0.4.4;
|
||||
pragma solidity >=0.4.4;
|
||||
pragma solidity <0.4.4;
|
||||
pragma solidity <=0.4.4;
|
||||
pragma solidity =0.4.4;
|
||||
pragma solidity 0.4;
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
|
||||
library a {}
|
||||
library b {}
|
||||
library c {}
|
||||
library f {}
|
||||
contract test {
|
||||
function f(uint a, uint b);
|
||||
function g(uint c);
|
||||
}
|
||||
contract c {
|
||||
event e(uint[10] a, bytes7[8] indexed b, c[3] x);
|
||||
}
|
||||
contract c {
|
||||
function f() {
|
||||
uint8[10 * 2] x;
|
||||
}
|
||||
}
|
||||
contract c {
|
||||
uint[10] a;
|
||||
uint[] a2;
|
||||
struct x { uint[2**20] b; y[0] c; }
|
||||
struct y { uint d; mapping(uint=>x)[] e; }
|
||||
}
|
||||
contract test {
|
||||
function fun(uint256 a) {
|
||||
uint256 x = ([1, 2, 3 + 4][a/=9] - 3) ** 4;
|
||||
}
|
||||
}
|
||||
import "./abc.sol" as x;
|
||||
import * as y from "./abc.sol";
|
||||
import {a as b, c as d, f} from "./abc.sol";
|
||||
|
||||
contract z {}
|
||||
contract A {
|
||||
function f() {
|
||||
uint x = 3 < 0 ? 2 > 1 ? 2 : 1 : 7 > 2 ? 7 : 6;
|
||||
}
|
||||
}
|
||||
contract A {
|
||||
function f() {
|
||||
uint x = true ? 1 : 0;
|
||||
uint y = false ? 0 : 1;
|
||||
}
|
||||
}
|
||||
contract A {
|
||||
function f() {
|
||||
uint y = 1;
|
||||
uint x = 3 < 0 ? x = 3 : 6;
|
||||
true ? x = 3 : 4;
|
||||
}
|
||||
}
|
||||
contract A {
|
||||
function f() {
|
||||
uint x = 3 > 0 ? 3 : 0;
|
||||
uint y = (3 > 0) ? 3 : 0;
|
||||
}
|
||||
}
|
||||
contract A {
|
||||
function f() {
|
||||
uint x = 3;
|
||||
uint y = 1;
|
||||
uint z = (x > y) ? x : y;
|
||||
uint w = x > y ? x : y;
|
||||
}
|
||||
}
|
||||
contract base {
|
||||
function fun() {
|
||||
uint64(2);
|
||||
}
|
||||
}
|
||||
|
||||
contract derived is base() {
|
||||
function fun() {
|
||||
uint64(2);
|
||||
}
|
||||
}
|
||||
|
||||
contract foo {
|
||||
function fun() {
|
||||
}
|
||||
}
|
||||
|
||||
contract bar {
|
||||
function fun() {
|
||||
}
|
||||
}
|
||||
|
||||
contract derived is foo, bar {
|
||||
function fun() {
|
||||
}
|
||||
}
|
||||
contract A {
|
||||
fixed40x40 storeMe;
|
||||
function f(ufixed x, fixed32x32 y) {
|
||||
ufixed8x8 a;
|
||||
fixed b;
|
||||
}
|
||||
}
|
||||
library d {}
|
||||
contract test {
|
||||
function fun(uint256 a) returns (address b) {
|
||||
if (a < 0) b = 0x67; else if (a == 0) b = 0x12; else b = 0x78;
|
||||
}
|
||||
}
|
||||
//
|
||||
contract test
|
||||
{}
|
||||
contract c {
|
||||
enum foo { }
|
||||
}
|
||||
contract test {
|
||||
uint256 stateVar;
|
||||
function functionName(bytes20 arg1, address addr) constant
|
||||
returns (int id)
|
||||
{ }
|
||||
}
|
||||
contract c {
|
||||
enum validEnum { Value1, Value2, Value3, Value4 }
|
||||
|
||||
function c () {
|
||||
a = validEnum.Value3;
|
||||
}
|
||||
|
||||
validEnum a;
|
||||
}
|
||||
contract c {
|
||||
event e();
|
||||
}
|
||||
contract c {
|
||||
event e() anonymous;
|
||||
}
|
||||
contract c {
|
||||
event e(uint a, bytes32 s);
|
||||
}
|
||||
contract c {
|
||||
event e(uint a, bytes32 indexed s, bool indexed b);
|
||||
}
|
||||
contract test {
|
||||
function fun(uint256 a) {
|
||||
uint256 x = 3 ** a;
|
||||
}
|
||||
}
|
||||
contract c {
|
||||
function x() external {}
|
||||
}
|
||||
contract c {
|
||||
function() { }
|
||||
}
|
||||
contract test {
|
||||
function fun(uint256 a) {
|
||||
uint256 i = 0;
|
||||
for (i = 0; i < 10; i++) {
|
||||
uint256 x = i;
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
contract test {
|
||||
function fun(uint256 a) {
|
||||
uint256 i = 0;
|
||||
for (;;) {
|
||||
uint256 x = i;
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
contract test {
|
||||
function fun(uint256 a) {
|
||||
uint256 i =0;
|
||||
for (i = 0; i < 10; i++)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
contract test {
|
||||
function fun(uint256 a) {
|
||||
for (uint256 i = 0; i < 10; i++) {
|
||||
uint256 x = i;
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
// contract from {
|
||||
// }
|
||||
contract test {
|
||||
function functionName(bytes32 input) returns (bytes32 out);
|
||||
}
|
||||
contract test {
|
||||
string a = hex"00FF0000";
|
||||
string b = hex'00AA0000';
|
||||
string b = hex'00AA_0000';
|
||||
string b = hex"";
|
||||
}
|
||||
contract test {
|
||||
function fun(uint256 a) {
|
||||
if (a >= 8) {
|
||||
return;
|
||||
} else {
|
||||
var b = 7;
|
||||
}
|
||||
}
|
||||
}
|
||||
import './abc.sol' as my_abc;
|
||||
|
||||
contract test {}
|
||||
import { a as my_a, b as my_b } from './abc.sol';
|
||||
|
||||
contract test {}
|
||||
import "./abc.sol";
|
||||
|
||||
contract test {
|
||||
function fun() {
|
||||
uint64(2);
|
||||
}
|
||||
}
|
||||
import * as abc from './abc.sol';
|
||||
|
||||
contract test {}
|
||||
contract c {
|
||||
uint[] a;
|
||||
function f() returns (uint, uint) {
|
||||
a = [1,2,3];
|
||||
return (a[3], [2,3,4][0]);
|
||||
}
|
||||
}
|
||||
library Lib {
|
||||
function f() { }
|
||||
}
|
||||
contract test {
|
||||
function test() {
|
||||
a = 1 wei;
|
||||
a = 2 szabo;
|
||||
a = 3 finney;
|
||||
a = 4 ether;
|
||||
|
||||
a = 1 seconds;
|
||||
a = 2 minutes;
|
||||
a = 3 hours;
|
||||
a = 4 days;
|
||||
a = 5 weeks;
|
||||
a = 6 years;
|
||||
}
|
||||
|
||||
uint256 a;
|
||||
}
|
||||
contract c {
|
||||
function c ()
|
||||
{
|
||||
a = 1 wei * 100 wei + 7 szabo - 3;
|
||||
}
|
||||
uint256 a;
|
||||
}
|
||||
contract Foo {
|
||||
function f() {
|
||||
uint[] storage x;
|
||||
uint[] memory y;
|
||||
}
|
||||
}
|
||||
// contract Foo {
|
||||
// function f(uint[] constant x, uint[] memory y) { }
|
||||
// }
|
||||
contract test {
|
||||
mapping(address => bytes32) names;
|
||||
}
|
||||
contract test {
|
||||
struct test_struct {
|
||||
address addr;
|
||||
uint256 count;
|
||||
mapping(bytes32 => test_struct) self_reference;
|
||||
}
|
||||
}
|
||||
contract test {
|
||||
struct test_struct {
|
||||
address addr;
|
||||
mapping (uint64 => mapping (bytes32 => uint)) complex_mapping;
|
||||
}
|
||||
}
|
||||
contract c {
|
||||
modifier mod { if (msg.sender == 0) _; }
|
||||
}
|
||||
contract c {
|
||||
modifier mod(address a) { if (msg.sender == a) _; }
|
||||
}
|
||||
contract c {
|
||||
modifier mod1(address a) { if (msg.sender == a) _; }
|
||||
modifier mod2 { if (msg.sender == 2) _; }
|
||||
function f() mod1(7) mod2 { }
|
||||
}
|
||||
contract c {
|
||||
mapping(uint => mapping(uint => int8)[8][][9])[] x;
|
||||
}
|
||||
contract C {
|
||||
function f() {
|
||||
var (a,b,c) = g();
|
||||
var (d) = 2;
|
||||
var (,e) = 3;
|
||||
var (f,) = 4;
|
||||
var (x,,) = g();
|
||||
var (,y,) = g();
|
||||
var (,,) = g();
|
||||
}
|
||||
function g() returns (uint, uint, uint) {}
|
||||
}
|
||||
contract test {
|
||||
function fun() {
|
||||
uint64(2);
|
||||
}
|
||||
}
|
||||
|
||||
contract test2 {
|
||||
function fun() {
|
||||
uint64(2);
|
||||
}
|
||||
}
|
||||
import "./abc.sol";
|
||||
|
||||
contract test {
|
||||
function fun() {
|
||||
}
|
||||
}
|
||||
|
||||
contract test2 {
|
||||
function fun() {
|
||||
}
|
||||
}
|
||||
|
||||
import "./def.sol";
|
||||
|
||||
contract foo {
|
||||
function foo(uint a) {
|
||||
}
|
||||
}
|
||||
|
||||
contract bar {
|
||||
function bar(string a, string b) {
|
||||
}
|
||||
}
|
||||
|
||||
contract derived is foo(2), bar("abc", "def") {
|
||||
function fun() {
|
||||
}
|
||||
}
|
||||
contract test {
|
||||
function f() returns(bool succeeded) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
contract test {
|
||||
uint256 stateVar;
|
||||
function functionName() {}
|
||||
}
|
||||
contract test {
|
||||
function fun(int256 a) {
|
||||
int256 x = (1 + 4) * (a - 12) + -9;
|
||||
bool y = true && (a < 6) || false;
|
||||
}
|
||||
}
|
||||
contract test {
|
||||
function fun(uint a) returns(uint r) { return a; }
|
||||
function fun(uint a, uint b) returns(uint r) { return a + b; }
|
||||
}
|
||||
contract c {
|
||||
function fun() returns (uint r) {
|
||||
var _ = 8;
|
||||
return _ + 1;
|
||||
}
|
||||
}
|
||||
pragma solidity ^0.4.4;
|
||||
|
||||
contract test {}
|
||||
contract test {
|
||||
uint256 stateVar;
|
||||
function functionName(bytes32 input) returns (bytes32 out) {}
|
||||
}
|
||||
contract test {
|
||||
uint256 stateVariable1;
|
||||
}
|
||||
contract test {
|
||||
function fun() {
|
||||
uint64(2);
|
||||
}
|
||||
}
|
||||
contract test {
|
||||
uint256 stateVar;
|
||||
struct MyStructName {
|
||||
address addr;
|
||||
uint256 count;
|
||||
}
|
||||
MyStructName({addr: myAddressVar, count: myCountVar})
|
||||
}
|
||||
contract C {
|
||||
function f() {
|
||||
uint a = (1);
|
||||
var (b,) = 1;
|
||||
var (c,d) = (1, 2 + a);
|
||||
var (e,) = (1, 2, b);
|
||||
(a) = 3;
|
||||
}
|
||||
}
|
||||
contract test {
|
||||
function fun() {
|
||||
var x = new uint64[](3);
|
||||
}
|
||||
}
|
||||
contract test {
|
||||
function f() {
|
||||
uint a = +10;
|
||||
a--;
|
||||
|
||||
a = ~a;
|
||||
delete a;
|
||||
|
||||
bool b = !true;
|
||||
}
|
||||
}
|
||||
library Lib {
|
||||
}
|
||||
|
||||
contract C {
|
||||
struct s { uint a; }
|
||||
using Lib for uint;
|
||||
using Lib for *;
|
||||
using Lib for s;
|
||||
|
||||
function f() {
|
||||
}
|
||||
}
|
||||
contract test {
|
||||
function fun(uint256 a) {
|
||||
var b = 5;
|
||||
uint256 c;
|
||||
mapping(address=>bytes32) d;
|
||||
}
|
||||
}
|
||||
contract test {
|
||||
function fun(uint256 a) {
|
||||
var b = 2;
|
||||
uint256 c = 0x87;
|
||||
uint256 d = 0X78;
|
||||
mapping(address=>bytes32) d;
|
||||
bytes32 name = "Solidity";
|
||||
}
|
||||
}
|
||||
contract c {
|
||||
uint private a;
|
||||
uint internal b;
|
||||
uint public c;
|
||||
uint d;
|
||||
function f() {}
|
||||
function f_priv() private {}
|
||||
function f_public() public {}
|
||||
function f_internal() internal {}
|
||||
}
|
||||
contract test {
|
||||
function fun(uint256 a) {
|
||||
while (true) { uint256 x = 1; break; continue; } x = 9;
|
||||
}
|
||||
}
|
||||
|
||||
contract test {
|
||||
function() {
|
||||
// assembly {
|
||||
// mstore(0x40, 0x60) // store the "free memory pointer"
|
||||
// // function dispatcher
|
||||
// switch div(calldataload(0), exp(2, 226))
|
||||
// case 0xb3de648b {
|
||||
// let (r) := f(calldataload(4))
|
||||
// let ret := $allocate(0x20)
|
||||
// mstore(ret, r)
|
||||
// return(ret, 0x20)
|
||||
// }
|
||||
// default { revert(0, 0) }
|
||||
// // memory allocator
|
||||
// function $allocate(size) -> pos {
|
||||
// pos := mload(0x40)
|
||||
// mstore(0x40, add(pos, size))
|
||||
// }
|
||||
// // the contract function
|
||||
// function f(x) -> y {
|
||||
// y := 1
|
||||
// for { let i := 0 } lt(i, x) { i := add(i, 1) } {
|
||||
// y := mul(2, y)
|
||||
// }
|
||||
// if gt(y, 2) { revert(0, 0) }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
contract test {
|
||||
function f() view {
|
||||
return 2;
|
||||
}
|
||||
function g() pure {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
contract test {
|
||||
function f() {
|
||||
uint256 a = 2.3e5;
|
||||
}
|
||||
}
|
||||
|
||||
contract test {
|
||||
function f() {
|
||||
uint256 a;
|
||||
(a,) = g();
|
||||
(,) = g();
|
||||
() = ();
|
||||
}
|
||||
}
|
||||
|
||||
contract test {
|
||||
function foo() public returns (byte b) {
|
||||
// assembly {
|
||||
// n := byte(0x0)
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
contract test {
|
||||
function() {
|
||||
emit EventCalled(1, 2, 3);
|
||||
}
|
||||
}
|
||||
|
||||
contract test {
|
||||
constructor(uint a, uint b) withModifier {}
|
||||
}
|
||||
|
||||
contract test {
|
||||
function () payable {
|
||||
(bytes32 a, uint b) = foo();
|
||||
}
|
||||
}
|
||||
|
||||
contract test {
|
||||
uint x = .1 ether;
|
||||
}
|
||||
|
||||
contract test {
|
||||
function () {
|
||||
type(Proxy).creationCode;
|
||||
}
|
||||
}
|
||||
|
||||
contract test {
|
||||
uint x = 1000000;
|
||||
int x2 = -1000000;
|
||||
int x3 = -1000000 * 200;
|
||||
uint y = .25;
|
||||
uint y2 = 0.25;
|
||||
// uint y3 = 10.25;
|
||||
// uint y4 = 100.25;
|
||||
// uint y5 = 0.0025 * 1e18;
|
||||
uint z = 0x11_22;
|
||||
uint z2 = 0x1122;
|
||||
}
|
||||
|
||||
contract test {
|
||||
function _finalization() internal {
|
||||
if (goalReached()) {
|
||||
_escrow.close();
|
||||
_escrow.beneficiaryWithdraw();
|
||||
} else {
|
||||
_escrow.enableRefunds();
|
||||
}
|
||||
|
||||
super._finalization();
|
||||
}
|
||||
}
|
||||
|
||||
contract test {
|
||||
function testFunction() {
|
||||
assembly {
|
||||
function power(base, exponent) -> result {
|
||||
switch exponent
|
||||
case 0 { result := 1 }
|
||||
case 1 { result := base }
|
||||
default {
|
||||
result := power(mul(base, base), div(exponent, 2))
|
||||
switch mod(exponent, 2)
|
||||
case 1 {
|
||||
result := mul(base, result)
|
||||
leave
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
contract Sharer {
|
||||
function sendHalf(address payable addr) public payable returns (uint balance) {
|
||||
require(msg.value % 2 == 0, "Even value required.");
|
||||
uint balanceBeforeTransfer = address(this).balance;
|
||||
addr.transfer(msg.value / 2);
|
||||
// Since transfer throws an exception on failure and
|
||||
// cannot call back here, there should be no way for us to
|
||||
// still have half of the money.
|
||||
assert(address(this).balance == balanceBeforeTransfer - msg.value / 2);
|
||||
return address(this).balance;
|
||||
}
|
||||
}
|
||||
|
||||
contract FeedConsumer {
|
||||
DataFeed feed;
|
||||
uint errorCount;
|
||||
function rate(address token) public returns (uint value, bool success) {
|
||||
// Permanently disable the mechanism if there are
|
||||
// more than 10 errors.
|
||||
require(errorCount < 10);
|
||||
try feed.getData(token) returns (uint v) {
|
||||
return (v, true);
|
||||
} catch Error(string memory /*reason*/) {
|
||||
// This is executed in case
|
||||
// revert was called inside getData
|
||||
// and a reason string was provided.
|
||||
errorCount++;
|
||||
return (0, false);
|
||||
} catch (bytes memory /*lowLevelData*/) {
|
||||
// This is executed in case revert() was used
|
||||
// or there was a failing assertion, division
|
||||
// by zero, etc. inside getData.
|
||||
errorCount++;
|
||||
return (0, false);
|
||||
} catch {
|
||||
// This is also executed in case revert() was used
|
||||
// or there was a failing assertion, division
|
||||
// by zero, etc. inside getData.
|
||||
errorCount++;
|
||||
return (0, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
contract test {
|
||||
receive () external payable {}
|
||||
fallback () external payable {}
|
||||
}
|
||||
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
|
||||
contract D {
|
||||
uint public x;
|
||||
constructor(uint a) public payable {
|
||||
x = a;
|
||||
}
|
||||
}
|
||||
|
||||
contract C {
|
||||
D d = new D(4); // will be executed as part of C's constructor
|
||||
|
||||
function createD(uint arg) public {
|
||||
D newD = new D(arg);
|
||||
newD.x();
|
||||
}
|
||||
|
||||
function createAndEndowD(uint arg, uint amount) public payable {
|
||||
// Send ether along with the creation
|
||||
D newD = new D{value: amount}(arg);
|
||||
newD.x();
|
||||
}
|
||||
}
|
||||
|
||||
pragma solidity >0.6.1 <0.7.0;
|
||||
|
||||
contract D {
|
||||
uint public x;
|
||||
constructor(uint a) public {
|
||||
x = a;
|
||||
}
|
||||
}
|
||||
|
||||
contract C {
|
||||
function createDSalted(bytes32 salt, uint arg) public {
|
||||
/// This complicated expression just tells you how the address
|
||||
/// can be pre-computed. It is just there for illustration.
|
||||
/// You actually only need ``new D{salt: salt}(arg)``.
|
||||
address predictedAddress = address(bytes20(keccak256(abi.encodePacked(
|
||||
byte(0xff),
|
||||
address(this),
|
||||
salt,
|
||||
keccak256(abi.encodePacked(
|
||||
type(D).creationCode,
|
||||
arg
|
||||
))
|
||||
))));
|
||||
|
||||
D d = new D{salt: salt}(arg);
|
||||
require(address(d) == predictedAddress);
|
||||
}
|
||||
}
|
||||
|
||||
contract c {
|
||||
string a = "aaa"
|
||||
"bbb";
|
||||
string b = "aaa""bbb";
|
||||
string c = "aaa" "bbb";
|
||||
}
|
||||
|
||||
pragma solidity >=0.4.22 <0.7.0;
|
||||
|
||||
contract owned {
|
||||
constructor() public { owner = msg.sender; }
|
||||
address payable owner;
|
||||
}
|
||||
|
||||
contract Destructible is owned {
|
||||
function destroy() virtual public {
|
||||
if (msg.sender == owner) selfdestruct(owner);
|
||||
}
|
||||
}
|
||||
|
||||
contract Base1 is Destructible {
|
||||
function destroy() public virtual override { /* do cleanup 1 */ super.destroy(); }
|
||||
}
|
||||
|
||||
|
||||
contract Base2 is Destructible {
|
||||
function destroy() public virtual override { /* do cleanup 2 */ super.destroy(); }
|
||||
}
|
||||
|
||||
contract Final is Base1, Base2 {
|
||||
function destroy() public override(Base1, Base2) { super.destroy(); }
|
||||
}
|
||||
|
||||
contract PayableAddress {
|
||||
function payableFn() public pure {
|
||||
address x;
|
||||
address y = payable(x);
|
||||
}
|
||||
}
|
||||
@ -1,30 +0,0 @@
|
||||
# tree-sitter-solidity
|
||||
|
||||
This is an automatically generated python package using [python-tree-sitter-types](https://github.com/JoranHonig/python-tree-sitter-types).
|
||||
|
||||
It provides nice typed bindings for the tree-sitter raw parser.
|
||||
|
||||
### Installation
|
||||
|
||||
```bash
|
||||
pip install tree-sitter-solidity
|
||||
```
|
||||
|
||||
### Example
|
||||
|
||||
```python
|
||||
|
||||
from tree_sitter_solidity import load_language, parse_node
|
||||
from tree_sitter import Parser
|
||||
|
||||
language = load_language('tree-sitter-solidity', 'solidity')
|
||||
|
||||
parser = Parser()
|
||||
parser.set_language(language)
|
||||
|
||||
tree = parser.parse(bytes("<some solidity code>", "utf-8"))
|
||||
|
||||
typed_tree = parse_node(tree.root_node)
|
||||
|
||||
# Your cool clean code:
|
||||
```
|
||||
@ -1 +0,0 @@
|
||||
tree-sitter-types
|
||||
@ -1,30 +0,0 @@
|
||||
import pathlib
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
# The directory containing this file
|
||||
HERE = pathlib.Path(__file__).parent
|
||||
|
||||
# The text of the README file
|
||||
README = (HERE / "README.md").read_text()
|
||||
|
||||
REQUIREMENTS = (HERE / "requirements.txt")
|
||||
|
||||
requirements = [x for x in map(str.strip, REQUIREMENTS.read_text().split("\n")) if x != ""]
|
||||
|
||||
setup(
|
||||
name="tree-sitter-solidity",
|
||||
version="0.0.1",
|
||||
description="A tree-sitter based typed parser for the solidity language",
|
||||
long_description=README,
|
||||
long_description_content_type="text/markdown",
|
||||
url="https://github.com/joranhonig/tree-sitter-solidity/",
|
||||
author="Joran Honig",
|
||||
author_email="joran.honig@gmail.com",
|
||||
classifiers=[
|
||||
"Programming Language :: Python :: 3",
|
||||
"Programming Language :: Python :: 3.7",
|
||||
],
|
||||
packages=find_packages(),
|
||||
include_package_data=True,
|
||||
install_requires=requirements,
|
||||
)
|
||||
@ -1 +0,0 @@
|
||||
from typed_parser import *
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue