Solidity grammar for ANTLR4
Federico Bond (@federicobond)
MIT
Solidity grammar for ANTLR4
License: MIT License
Solidity grammar for ANTLR4
Federico Bond (@federicobond)
MIT
Would you like to join us? ;) https://github.com/antlr/grammars-v4
function g() {
// named arguments
f({value: 2, key: 3});
}
from
is not actually a language keyword. See here.
We can either modify our import rules to use an Identifier or turn the lexer rule for Identifier into a parser rule that accepts either from
or keyword. Solidity uses the first approach.
int8 y = -3;
uint x = uint(y);
See here.
Cannot parse oraclize api solidity file due to unrecognized versioning pragma.
pragma solidity >= 0.4.1 < 0.5
https://github.com/provable-things/ethereum-api/blob/master/oraclizeAPI_0.4.sol#L31
The list at the official documentation mentions these.
abstract, after, case, catch, default, final, in, inline, interface, let, match,
null, of, pure, relocatable, static, switch, try, type, typeof, view.
Make sure it's updated with the implementation.
In the following example, the field data
in the User
contract is defined using IntegerSet.data
type. Taken from the Solidity Features page.
pragma solidity ^0.4.4;
library IntegerSet
{
struct data
{
mapping(uint => uint) index;
uint[] items;
uint size;
}
function insert(data storage self, uint value) returns (bool alreadyPresent)
{
uint index = self.index[value];
if (index > 0)
return true;
else
{
if (self.items.length == 0) self.items.length = 1;
index = self.items.length++;
self.items[index] = value;
self.index[value] = index;
self.size++;
return false;
}
}
function remove(data storage self, uint value) returns (bool success)
{
uint index = self.index[value];
if (index == 0)
return false;
delete self.index[value];
delete self.items[index];
self.size --;
}
function contains(data storage self, uint value) returns (bool)
{
return self.index[value] > 0;
}
function iterate_start(data storage self) returns (uint index)
{
return iterate_advance(self, 0);
}
function iterate_valid(data storage self, uint index) returns (bool)
{
return index < self.items.length;
}
function iterate_advance(data storage self, uint index) returns (uint r_index)
{
index++;
while (iterate_valid(self, index) && self.index[self.items[index]] == index)
index++;
return index;
}
function iterate_get(data storage self, uint index) returns (uint value)
{
return self.items[index];
}
}
contract User
{
IntegerSet.data data;
function insert(uint v) returns (uint size)
{
IntegerSet.insert(data, v);
return data.size;
}
function sum() returns (uint s)
{
for (var i = IntegerSet.iterate_start(data); IntegerSet.iterate_valid(data, i); i = IntegerSet.iterate_advance(data, i))
s += IntegerSet.iterate_get(data, i);
}
}
It seems that the solidity type information are not supported. If I have a contract containing e.g. type(Proxy).creationCode;
it will fail with extraneous input 'type' expecting
.
Hi, I don't know much about ANTLR so sorry in advance if this doesn't make sense.
I want to add a Listener for functionCall
, but those nodes are interpreted as expression
s instead. I guess this happens because one of the rules for expression
(the fourth one) has the same definition as functionCall
(and that rule is not inside expression
). Maybe replacing that for functionCall
will do the trick?
Thanks!
Sorry to bother you, where can I find the newest version of this Solidity.g4 file?
Currently solidity-parser-antlr is unable to parse pragma solidity ~0.4.10
, because ~
isn't listed as a version operator in this repo.
Please check out, that tilda-ranges are as valid as carret-ranges https://docs.npmjs.com/misc/semver#tilde-ranges-123-12-1
I am now trying to understand what the field "names"
in a functionCall
node is for. So, I realized it has something to do with nameValueList
defined in this grammar at
Line 265 in edce5c4
Thanks
Move StorageLocation?
to VariableDeclaration
pragma solidity ^0.4.0;
contract C {
function f() {
g([uint(1), 2, 3]);
}
function g(uint[3] _data) {
// ...
}
}
See here.
Pinging @domainexpert and @frangio. Several people have approached me in the past with the intention of building tools with a more permissive license on top of this code. I would like to get your opinions or consent as collaborators to relicense this project to MIT.
Let me know if any of you disagrees or state your consent explicitly. Thank you in advance!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.