creating parsing tests, experimenting with syntax

This commit is contained in:
Skye Terran 2021-08-19 19:33:31 -07:00
parent 9618a953d1
commit 6be68f74c6
2 changed files with 110 additions and 0 deletions

View File

@ -0,0 +1,92 @@
{
"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
}

18
test.neu Normal file
View File

@ -0,0 +1,18 @@
// this is a comment
meta =
scale:float = 1.0,
,
graph =
&0 =
name:string = "SM_LargeWindow_A",
mesh:mesh = *2,
transform:trans = #b,
,
&1 =
name:string = "SM_LargeWindow_A2",
mesh:mesh = *2,
transform:trans = #b,
,
cache =
//
,