Skip to content

Commit

Permalink
Merge pull request #3 from Veridise/dev
Browse files Browse the repository at this point in the history
fixed antlr grammar with new lexer and parser
  • Loading branch information
chyanju authored Mar 3, 2024
2 parents 50e283a + b4bcfd6 commit f9b633a
Show file tree
Hide file tree
Showing 30 changed files with 9,899 additions and 11,853 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ In case the parser is not compatible with your environment, you can generate it

```bash
cd ./vanguard/aleo/parser/
antlr4 -v 4.13.1 -Dlanguage=Python3 ./Aleo.g4
antlr4 -v 4.13.1 -Dlanguage=Python3 ./AleoLexer.g4 # generate lexer
antlr4 -v 4.13.1 -Dlanguage=Python3 ./AleoParser.g4 # generate parser
```

The parser/lexer file is located in `./vanguard/aleo/parser/Aleo.g4`.
The parser/lexer file is located in `./vanguard/aleo/parser/AleoLexer.g4` and `./vanguard/aleo/parser/AleoParser.g4`.

## Test Suite and Static Analysis APIs

Expand Down
37 changes: 8 additions & 29 deletions tests/test3.ipynb → tests/aleo2json-test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "4c8e2fda-c143-4942-b20d-48ebfe6b5b2d",
"metadata": {},
"outputs": [],
Expand All @@ -15,25 +15,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "1bd6be3d-a5e1-4ee0-b63f-5c5314c97be1",
"metadata": {},
"outputs": [],
"source": [
"from vanguard.aleo.testing import crawl_from_haruka_explorer, crawl_from_aleo_explorer"
"from vanguard.aleo.common import aleo2json"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"id": "92552997-9c7a-4338-b83a-d0fca318fb33",
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"# crawl_from_haruka_explorer(1, 16, \"tests/explorer/haruka/\")\n",
"crawl_from_aleo_explorer(\"tests/explorer/aleo/\")"
"project_name = \"divz0\"\n",
"obj = aleo2json(f\"./tests/public/{project_name}/build/main.aleo\")"
]
},
{
Expand All @@ -42,35 +42,14 @@
"id": "458ed9da-df04-4fe2-bdfb-bdef4b4766df",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "13cab74f-7fdc-41ac-8b1f-1e0831158e6a",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import time\n",
"os.chdir(\"..\")\n",
"from vanguard.aleo.common import aleo2json\n",
"\n",
"# for dp, _, fns in os.walk(\"tests/explorer/haruka/\"):\n",
"for dp, _, fns in os.walk(\"tests/explorer/aleo/\"):\n",
" for fn in fns:\n",
" p = os.path.abspath(os.path.join(dp, fn))\n",
" print(f\"# parsing: {p} ... \", end=\"\")\n",
" s = time.time()\n",
" obj = aleo2json(p)\n",
" e = time.time()\n",
" print(f\"{e-s}s\")"
"print(json.dumps(obj))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "aad44479-9c1f-4784-acff-006dd4f27ce4",
"id": "f97f8fd6-b302-43ea-a053-cf1366f87019",
"metadata": {},
"outputs": [],
"source": []
Expand Down
24 changes: 24 additions & 0 deletions tests/lexer-test.aleo
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
program test.aleo;

struct CollectionPublicData:
royalty_fees as u64;
royalty_address as u32;
metadata_uri as String64;
negbase_uri as String64;
publicizable as boolean;

function update_collection_public_data:
input r0 as Collection.record;
input r1 as CollectionPublicData.public;
cast r0.owner r0.id r0.data into r2 as Collection.record;
async update_collection_public_data r0.id r1 into r3;
output r2 as Collection.record;
output r3 as aleo_store_nft.aleo/update_collection_public_data.future;

finalize update_collection_public_data:
input r0 as CollectionId.public;
input r1 as CollectionPublicData.public;
get collectionPublicData[r0] into r2;
assert.eq r2.publicizable r1.recordjjj ;
set r1 into collectionPublicData[r0];
set r123 into rafew[r0];
257 changes: 257 additions & 0 deletions tests/lexer-test.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "92a381f1-d0c2-4d81-a601-6204575a5b6a",
"metadata": {},
"outputs": [],
"source": [
"# only run once every time kernel restarts\n",
"import json\n",
"import os\n",
"import sys\n",
"from antlr4 import *\n",
"os.chdir(\"..\")"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "0062f4dd-2067-4608-ada1-e423db3c8e27",
"metadata": {},
"outputs": [],
"source": [
"from vanguard.aleo.parser.AleoLexer import AleoLexer\n",
"input_stream = FileStream(f\"./tests/lexer-test.aleo\")\n",
"lexer = AleoLexer(input_stream)\n",
"tokens = lexer.getAllTokens()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "1b6e0beb-9df5-4748-a3f2-b7e1e112e248",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"program | 92 | PROGRAM\n",
"test | 116 | IDENTIFIER\n",
". | 1 | DOT\n",
"aleo | 116 | IDENTIFIER\n",
"; | 5 | SC\n",
"struct | 97 | STRUCT\n",
"CollectionPublicData | 116 | IDENTIFIER\n",
": | 7 | CL\n",
"royalty_fees | 116 | IDENTIFIER\n",
"as | 9 | AS\n",
"u64 | 105 | UNSIGNED_TYPE\n",
"; | 5 | SC\n",
"royalty_address | 116 | IDENTIFIER\n",
"as | 9 | AS\n",
"u32 | 105 | UNSIGNED_TYPE\n",
"; | 5 | SC\n",
"metadata_uri | 116 | IDENTIFIER\n",
"as | 9 | AS\n",
"String64 | 116 | IDENTIFIER\n",
"; | 5 | SC\n",
"negbase_uri | 116 | IDENTIFIER\n",
"as | 9 | AS\n",
"String64 | 116 | IDENTIFIER\n",
"; | 5 | SC\n",
"publicizable | 116 | IDENTIFIER\n",
"as | 9 | AS\n",
"boolean | 110 | BOOLEAN\n",
"; | 5 | SC\n",
"function | 101 | FUNCTION\n",
"update_collection_public_data | 116 | IDENTIFIER\n",
": | 7 | CL\n",
"input | 99 | INPUT\n",
"r0 | 115 | REGISTER\n",
"as | 9 | AS\n",
"Collection | 116 | IDENTIFIER\n",
". | 1 | DOT\n",
"record | 16 | RECORD\n",
"; | 5 | SC\n",
"input | 99 | INPUT\n",
"r1 | 115 | REGISTER\n",
"as | 9 | AS\n",
"CollectionPublicData | 116 | IDENTIFIER\n",
". | 1 | DOT\n",
"public | 12 | PUBLIC\n",
"; | 5 | SC\n",
"cast | 89 | CAST\n",
"r0 | 115 | REGISTER\n",
". | 1 | DOT\n",
"owner | 116 | IDENTIFIER\n",
"r0 | 115 | REGISTER\n",
". | 1 | DOT\n",
"id | 116 | IDENTIFIER\n",
"r0 | 115 | REGISTER\n",
". | 1 | DOT\n",
"data | 116 | IDENTIFIER\n",
"into | 10 | INTO\n",
"r2 | 115 | REGISTER\n",
"as | 9 | AS\n",
"Collection | 116 | IDENTIFIER\n",
". | 1 | DOT\n",
"record | 16 | RECORD\n",
"; | 5 | SC\n",
"async | 41 | ASYNC\n",
"update_collection_public_data | 116 | IDENTIFIER\n",
"r0 | 115 | REGISTER\n",
". | 1 | DOT\n",
"id | 116 | IDENTIFIER\n",
"r1 | 115 | REGISTER\n",
"into | 10 | INTO\n",
"r3 | 115 | REGISTER\n",
"; | 5 | SC\n",
"output | 100 | OUTPUT\n",
"r2 | 115 | REGISTER\n",
"as | 9 | AS\n",
"Collection | 116 | IDENTIFIER\n",
". | 1 | DOT\n",
"record | 16 | RECORD\n",
"; | 5 | SC\n",
"output | 100 | OUTPUT\n",
"r3 | 115 | REGISTER\n",
"as | 9 | AS\n",
"aleo_store_nft | 116 | IDENTIFIER\n",
". | 1 | DOT\n",
"aleo | 116 | IDENTIFIER\n",
"/ | 2 | SLASH\n",
"update_collection_public_data | 116 | IDENTIFIER\n",
". | 1 | DOT\n",
"future | 15 | FUTURE\n",
"; | 5 | SC\n",
"finalize | 102 | FINALIZE\n",
"update_collection_public_data | 116 | IDENTIFIER\n",
": | 7 | CL\n",
"input | 99 | INPUT\n",
"r0 | 115 | REGISTER\n",
"as | 9 | AS\n",
"CollectionId | 116 | IDENTIFIER\n",
". | 1 | DOT\n",
"public | 12 | PUBLIC\n",
"; | 5 | SC\n",
"input | 99 | INPUT\n",
"r1 | 115 | REGISTER\n",
"as | 9 | AS\n",
"CollectionPublicData | 116 | IDENTIFIER\n",
". | 1 | DOT\n",
"public | 12 | PUBLIC\n",
"; | 5 | SC\n",
"get | 28 | GET\n",
"collectionPublicData | 116 | IDENTIFIER\n",
"[ | 3 | LB\n",
"r0 | 115 | REGISTER\n",
"] | 4 | RB\n",
"into | 10 | INTO\n",
"r2 | 115 | REGISTER\n",
"; | 5 | SC\n",
"assert | 70 | ASSERT\n",
". | 1 | DOT\n",
"eq | 68 | EQ\n",
"r2 | 115 | REGISTER\n",
". | 1 | DOT\n",
"publicizable | 116 | IDENTIFIER\n",
"r1 | 115 | REGISTER\n",
". | 1 | DOT\n",
"recordjjj | 116 | IDENTIFIER\n",
"; | 5 | SC\n",
"set | 30 | SET\n",
"r1 | 115 | REGISTER\n",
"into | 10 | INTO\n",
"collectionPublicData | 116 | IDENTIFIER\n",
"[ | 3 | LB\n",
"r0 | 115 | REGISTER\n",
"] | 4 | RB\n",
"; | 5 | SC\n",
"set | 30 | SET\n",
"r12 | 115 | REGISTER\n",
"into | 10 | INTO\n",
"r123 | 115 | REGISTER\n",
"[ | 3 | LB\n",
"r0 | 115 | REGISTER\n",
"] | 4 | RB\n",
"; | 5 | SC\n"
]
}
],
"source": [
"for t in tokens:\n",
" print(f\"{t.text} | {t.type} | {lexer.symbolicNames[t.type]}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "80638ee0-d9a0-42f3-b737-dd5cc70545ef",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 15,
"id": "43f7bc52-ce30-480e-b030-7c2f7b8949ed",
"metadata": {},
"outputs": [],
"source": [
"# dir(lexer)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "1b719ef5-f739-41cf-80e5-36d7680e5380",
"metadata": {},
"outputs": [],
"source": [
"# dir(t)"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "68eefa99-d909-48fd-b8fe-ce886397fe76",
"metadata": {},
"outputs": [],
"source": [
"# t.type"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b42e12e8-f94f-4399-a64f-a47fee71e36f",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.0"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading

0 comments on commit f9b633a

Please sign in to comment.