Ver Fonte

Merge pull request #1170 from seanyoung/parser-publish

Bump solang-parser for crate publish
Sean Young há 2 anos atrás
pai
commit
4386c4546a
4 ficheiros alterados com 56 adições e 3 exclusões
  1. 1 1
      Cargo.toml
  2. 1 1
      solang-parser/Cargo.toml
  3. 52 0
      solang-parser/README.md
  4. 2 1
      solang-parser/src/lib.rs

+ 1 - 1
Cargo.toml

@@ -46,7 +46,7 @@ itertools = "0.10"
 num-rational = "0.4"
 indexmap = "1.9"
 once_cell = "1.17"
-solang-parser = { path = "solang-parser", version = "0.2.1" }
+solang-parser = { path = "solang-parser", version = "0.2.2" }
 codespan-reporting = "0.11"
 phf = { version = "0.11", features = ["macros"] }
 rust-lapper = "1.1"

+ 1 - 1
solang-parser/Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "solang-parser"
-version = "0.2.1"
+version = "0.2.2"
 authors = ["Sean Young <sean@mess.org>", "Lucas Steuernagel <lucas.tnagel@gmail.com>", "Cyrill Leutwiler <bigcyrill@hotmail.com>"]
 homepage = "https://github.com/hyperledger/solang"
 documentation = "https://solang.readthedocs.io/"

+ 52 - 0
solang-parser/README.md

@@ -0,0 +1,52 @@
+
+# Hyperledger Solang Solidity parser
+
+This crate is part of [Hyperledger Solang](https://solang.readthedocs.io/). It contains the
+parser for Solidity, including the dialects used by Solang for Solana and Substrate.
+
+```rust
+use solang_parser::{pt::{SourceUnitPart, ContractPart}, parse};
+
+let (tree, comments) = parse(r#"
+contract flipper {
+    bool private value;
+
+    /// Constructor that initializes the `bool` value to the given `init_value`.
+    constructor(bool initvalue) {
+        value = initvalue;
+    }
+
+    /// A message that can be called on instantiated contracts.
+    /// This one flips the value of the stored `bool` from `true`
+    /// to `false` and vice versa.
+    function flip() public {
+        value = !value;
+    }
+
+    /// Simply returns the current value of our `bool`.
+    function get() public view returns (bool) {
+        return value;
+    }
+}
+"#, 0).unwrap();
+
+for part in &tree.0 {
+    match part {
+        SourceUnitPart::ContractDefinition(def) => {
+            println!("found contract {:?}", def.name);
+            for part in &def.parts {
+                match part {
+                    ContractPart::VariableDefinition(def) => {
+                        println!("variable {:?}", def.name);
+                    }
+                    ContractPart::FunctionDefinition(def) => {
+                        println!("function {:?}", def.name);
+                    }
+                    _ => (),
+                }
+            }
+        }
+        _ => (),
+    }
+}
+```

+ 2 - 1
solang-parser/src/lib.rs

@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: Apache-2.0
 
-//! Solidity file parser
+#![doc = include_str!("../README.md")]
+
 use crate::lexer::LexicalError;
 use crate::lexer::Token;
 use crate::pt::CodeLocation;