| Crates.io | oak-solidity |
| lib.rs | oak-solidity |
| version | 0.0.1 |
| created_at | 2025-10-22 03:23:07.685126+00 |
| updated_at | 2026-01-23 05:19:14.662503+00 |
| description | High-performance incremental Solidity parser for the oak ecosystem with comprehensive support for smart contract syntax, emphasizing security and Ethereum compatibility. |
| homepage | https://github.com/ygg-lang/oaks |
| repository | https://github.com/ygg-lang/oaks |
| max_upload_size | |
| id | 1894879 |
| size | 98,552 |
A Solidity parser for the Oak parsing framework, providing robust parsing capabilities for Ethereum smart contracts and Solidity language constructs.
use oak::Parser;
use oak_solidity::SolidityLanguage;
fn main() {
let source = r#"
pragma solidity ^0.8.0;
contract SimpleStorage {
uint256 private storedData;
function set(uint256 x) public {
storedData = x;
}
function get() public view returns (uint256) {
return storedData;
}
}
"#;
let mut parser = Parser::new();
let language = SolidityLanguage::new();
match parser.parse(&source, &language) {
Ok(ast) => {
println!("Successfully parsed Solidity contract!");
println!("AST: {:#?}", ast);
}
Err(error) => {
eprintln!("Parse error: {}", error);
}
}
}
use oak::Parser;
use oak_solidity::SolidityLanguage;
fn main() {
let complex_contract = r#"
pragma solidity ^0.8.0;
interface IERC20 {
function transfer(address to, uint256 amount) external returns (bool);
function balanceOf(address account) external view returns (uint256);
}
contract TokenVault is Ownable {
IERC20 public token;
mapping(address => uint256) public deposits;
event Deposit(address indexed user, uint256 amount);
event Withdrawal(address indexed user, uint256 amount);
modifier validAmount(uint256 amount) {
require(amount > 0, "Amount must be positive");
_;
}
constructor(address _token) {
token = IERC20(_token);
}
function deposit(uint256 amount) external validAmount(amount) {
require(token.transferFrom(msg.sender, address(this), amount), "Transfer failed");
deposits[msg.sender] += amount;
emit Deposit(msg.sender, amount);
}
function withdraw(uint256 amount) external validAmount(amount) {
require(deposits[msg.sender] >= amount, "Insufficient balance");
deposits[msg.sender] -= amount;
require(token.transfer(msg.sender, amount), "Transfer failed");
emit Withdrawal(msg.sender, amount);
}
}
"#;
let mut parser = Parser::new();
let language = SolidityLanguage::new();
match parser.parse(&complex_contract, &language) {
Ok(ast) => {
println!("Successfully parsed complex contract with inheritance!");
// Process the AST for semantic analysis or code generation
}
Err(error) => {
eprintln!("Parse error at line {}: {}", error.line(), error.message());
}
}
}
use oak::Parser;
use oak_solidity::SolidityLanguage;
fn parse_with_diagnostics(source: &str) {
let mut parser = Parser::new();
let language = SolidityLanguage::new();
match parser.parse(source, &language) {
Ok(ast) => {
println!("Parsed successfully!");
}
Err(error) => {
eprintln!("Parse error at line {}, column {}", error.line(), error.column());
eprintln!("Error: {}", error.message());
// Show context around the error
let lines: Vec<&str> = source.lines().collect();
if error.line() > 0 && error.line() <= lines.len() {
eprintln!("Context:");
eprintln!(" {}", lines[error.line() - 1]);
eprintln!(" {}^", " ".repeat(error.column()));
}
}
}
}
The parser generates a rich AST with the following main node types:
The parser integrates seamlessly with the broader Oak ecosystem:
use oak::Parser;
use oak_solidity::SolidityLanguage;
// Use with other Oak tools for analysis and transformation
fn analyze_solidity_contract(source: &str) -> Result<Analysis, ParseError> {
let mut parser = Parser::new();
let language = SolidityLanguage::new();
let ast = parser.parse(source, &language)?;
// Perform semantic analysis, linting, or transformations
perform_analysis(ast)
}
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the MIT License - see the LICENSE file for details.