Neutrino/NeutrinoParseTesting.ipynb

92 lines
3.0 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 25,
"source": [
"file = open(\"test.neu\")\r\n",
"dirty_blob = file.read()\r\n",
"\r\n",
"# get rid of comments and leading/trailing whitespace\r\n",
"lines = dirty_blob.split(\"\\n\")\r\n",
"for i, line in enumerate(lines):\r\n",
" lines[i] = line.strip()\r\n",
" if line.strip()[:2] == \"//\":\r\n",
" del lines[i]\r\n",
"\r\n",
"tidy_blob = \" \".join(lines)\r\n",
"lines"
],
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"['meta =', 'nice', ',', 'graph =', ',', 'cache =', ',']"
]
},
"metadata": {},
"execution_count": 25
}
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 26,
"source": [
"data = []\r\n",
"\r\n",
"# get objects\r\n",
"for line in lines:\r\n",
" object = {}\r\n",
" if \"=\" in line:\r\n",
" keytype = line.split(\" \")[0].split(\":\")\r\n",
" key = keytype[0]\r\n",
" object[\"key\"] = key\r\n",
" if len(keytype) > 1:\r\n",
" type = keytype[1]\r\n",
" object[\"type\"] = type\r\n",
" data.append(object)\r\n",
"\r\n",
"data"
],
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"{'key': 'meta'}\n",
"{'key': 'graph'}\n",
"{'key': 'cache'}\n"
]
}
],
"metadata": {}
}
],
"metadata": {
"orig_nbformat": 4,
"language_info": {
"name": "python",
"version": "3.7.8",
"mimetype": "text/x-python",
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"pygments_lexer": "ipython3",
"nbconvert_exporter": "python",
"file_extension": ".py"
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3.7.8 64-bit"
},
"interpreter": {
"hash": "57baa5815c940fdaff4d14510622de9616cae602444507ba5d0b6727c008cbd6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}