add thought; update css to support syntax highlighting

This commit is contained in:
gnat 2024-09-12 09:58:20 -07:00
parent 941449bb61
commit a2323f29e4
3 changed files with 217 additions and 12 deletions

View File

@ -1,17 +1,17 @@
2024-02-18: Cleaned up header css, added changelog. 2024-02-18: cleaned up header css, added changelog.
2024-02-24: Made dir_index.html slightly less cursed server side 2024-02-24: made dir_index.html slightly less cursed server side
2024-04-10: Fix albert hacking my website by rewriting the entire backend (lol) 2024-04-10: fix albert hacking my website by rewriting the entire backend (lol)
2024-04-12: Add "natalie-sightings.html" 2024-04-12: add "natalie-sightings.html"
2024-04-14: Add "cool-sites.html", update home.html to actually be html compliant, updated comment system, add 88x31 collection, minor modification to "natalie-info.html". 2024-04-14: add "cool-sites.html", update home.html to actually be html compliant, updated comment system, add 88x31 collection, minor modification to "natalie-info.html".
2024-04-25: Move hosting to server taken from school basement, (somewhat notable) 2024-04-25: move hosting to server taken from school basement, (somewhat notable)
2024-04-26: Updated server-migration.html, site-info.html. 2024-04-26: updated server-migration.html, site-info.html.
2024-05-03: Added link to blog page in home.html, added random statement to home page upon each load 2024-05-03: added link to blog page in home.html, added random statement to home page upon each load
2024-05-11: Rewrote the webserver code, again. Fixed a few things in home.html. 2024-05-11: rewrote the webserver code, again. Fixed a few things in home.html.
2024-05-19: update theme to be in compliance with new laptop. depricate laptop page 2024-05-19: update theme to be in compliance with new laptop. depricate laptop page
2024-07-06: Now supports http and https. This creates a race condition in theory. Don't care 2024-07-06: now supports http and https. this creates a race condition in theory. don't care
2024-07-09: updated natalie-info.html at the request of cinnabar, who was annoyed at the small number of incorrect things 2024-07-09: updated natalie-info.html at the request of cinnabar, who was annoyed at the small number of incorrect things
2024-07-18: create & add header to all pages, changes to css so as to scale with vw 2024-07-18: create & add header to all pages, changes to css so as to scale with vw
2024-07-24: Append to list of interesting sights, add page complaining about discord 2024-07-24: append to list of interesting sights, add page complaining about discord
2024-07-24: add thoughts page in /html/, update natalie info page 2024-07-24: add thoughts page in /html/, update natalie info page
2024-07-24: updated wording in site-info.html, add /stats/ routes, update home.html to make filetree hidden by default because it is big 2024-07-24: updated wording in site-info.html, add /stats/ routes, update home.html to make filetree hidden by default because it is big
2024-07-25: rewrite css because winter told me to. Now has dark mode based on a media query. 2024-07-25: rewrite css because winter told me to. Now has dark mode based on a media query.
@ -19,7 +19,7 @@
2024-07-26: add <a href='https://git.natalieee.net'>git.natalieee.net</a> 2024-07-26: add <a href='https://git.natalieee.net'>git.natalieee.net</a>
2024-07-26: update site-info.html 2024-07-26: update site-info.html
2024-07-26: I have a dns server now. oops. there go my sleeping plans. email me if you want to use it for some insane reason. 2024-07-26: I have a dns server now. oops. there go my sleeping plans. email me if you want to use it for some insane reason.
2024-07-27: Update style on non blog posts 2024-07-27: update style on non blog posts
2024-07-27: modernize /html/site-info.html, finally 2024-07-27: modernize /html/site-info.html, finally
2024-07-27: improve image accessibility, update blog posts to be compliant with new style 2024-07-27: improve image accessibility, update blog posts to be compliant with new style
2024-07-28: add support for planned footer in all relevant html documents, simplify inclusion of other documents in a document using include script 2024-07-28: add support for planned footer in all relevant html documents, simplify inclusion of other documents in a document using include script
@ -36,3 +36,4 @@
2024-09-05: hopefully? fix issue with natalie-info.html, update home.html 2024-09-05: hopefully? fix issue with natalie-info.html, update home.html
2024-09-07: add additional random homepage statements 2024-09-07: add additional random homepage statements
2024-09-07: add license, finally; edit site-info 2024-09-07: add license, finally; edit site-info
2024-09-12: update style.css to support syntax highlighting

170
html/thoughts/python-goto Normal file
View File

@ -0,0 +1,170 @@
<!-- TITLE: implementing goto statements in python (in under 50 lines)-->
<!-- DATE: 2024-09-12 08:43:04 -->
python is extremely extensible, though I'm not sure that is intentional.
<hr>
firstly, here is the end product of this venture:
<pre>
<span class="-keyword">from</span> <span class="-variable"><span class="DiagnosticUnderlineError">goto_label</span></span> <span class="-keyword">import</span> <span class="Operator"><span class="SpecialChar">*</span></span>
<span class="-variable">count</span> <span class="Operator">=</span> <span class="Number">0</span>
<span class="Comment"><span class="-spell">#LABEL lol</span></span>
<span class="-variable"><span class="-function"><span class="-function-builtin">print</span></span></span><span class="-punctuation-bracket">(</span><span class="String">'this prints twice'</span><span class="-punctuation-bracket">)</span>
<span class="-variable">count</span> <span class="Operator">+=</span> <span class="Number">1</span>
<span class="-variable"><span class="DiagnosticUnderlineError">goto</span></span> <span class="Operator">&amp;</span><span class="-variable"><span class="DiagnosticUnderlineError">lol</span></span> <span class="-keyword">if</span> <span class="-punctuation-bracket">(</span><span class="-variable">count</span> <span class="Operator">&lt;=</span> <span class="Number">1</span><span class="-punctuation-bracket">)</span> <span class="-keyword">else</span> <span class="-variable"><span class="DiagnosticUnderlineError">goto</span></span> <span class="Operator">&amp;</span><span class="-variable"><span class="DiagnosticUnderlineError">goto_statements_are_a_perfectly_reasonable_thing_to_have_in_python</span></span>
<span class="Comment"><span class="-spell">#LABEL last_print</span></span>
<span class="-variable"><span class="-function"><span class="-function-builtin">print</span></span></span><span class="-punctuation-bracket">(</span><span class="String">'this prints last'</span><span class="-punctuation-bracket">)</span>
<span class="-variable"><span class="DiagnosticUnderlineWarn"><span class="DiagnosticUnderlineError">goto</span></span></span><span class="DiagnosticUnderlineWarn"> <span class="Operator">&amp;</span><span class="-variable"><span class="DiagnosticUnderlineError">stop</span></span></span><span class="-variable"></span>
<span class="Comment"><span class="-spell">#LABEL ellipsis</span></span>
<span class="-variable"><span class="-function"><span class="-function-builtin">print</span></span></span><span class="-punctuation-bracket">(</span><span class="String">'at least Ellipsis() has some use now, for normal reasons that make sense'</span><span class="-punctuation-bracket">)</span>
<span class="-variable"><span class="DiagnosticUnderlineWarn"><span class="DiagnosticUnderlineError">goto</span></span></span><span class="DiagnosticUnderlineWarn"> <span class="Operator">&amp;</span><span class="-variable"><span class="DiagnosticUnderlineError">last_print</span></span></span><span class="-variable"></span>
<span class="Comment"><span class="-spell">#LABEL goto_statements_are_a_perfectly_reasonable_thing_to_have_in_python</span></span>
<span class="-variable"><span class="-function"><span class="-function-builtin">print</span></span></span><span class="-punctuation-bracket">(</span><span class="String">'I am sure this is how the variety of language features I am abusing were intended to be used'</span><span class="-punctuation-bracket">)</span>
<span class="-variable"><span class="DiagnosticUnderlineWarn"><span class="DiagnosticUnderlineError">goto</span></span></span><span class="DiagnosticUnderlineWarn"> <span class="Operator">&amp;</span><span class="-variable">ellipsis</span></span><span class="-variable"></span>
<span class="Comment"><span class="-spell">#LABEL stop</span></span>
<span class="-punctuation-delimiter">...</span>
</pre>
its beautiful.<br>
this outputs the following:
<pre>
this prints twice
this prints twice
I am sure this is how the variety of language features I am abusing were intended to be used
at least Ellipsis() has some use now, for normal reasons that make sense
this prints last
</pre>
<hr>
now then, how does it work?
<h3>design decisions</h3>
given that evidence suggests python programs can be edited, I decided not to use line number based gotos and instead define labels that could be jumped to.
this makes things less annoying to edit and maintain, and developer experience is obviously a very important consideration with this project.<br>
additionally, to maximize ease with which this ""library"" can be utilized, one must only import the file to experience the wonder of python with goto statements.
<h3>technical implementation</h3>
firstly, labels: <br>
goto_label.py has a function prepare_labels(fp, scope).
this function looks for any labels (defined via /^#LABEL labelname/) in the file at fp, and defines them under the scope scope.
each label is defined as a label object. I resent using an object for this (which you can see by my not using the class keyword), but python is python and you cannot override operators without having a class.
I could just not override the operators, but I want goto to be called in a unique way that is separate from how a function would be called.
label objects have only one attribute: lineno, which is determined by an extremely rudimentary parser and then offset by 2 to account for the fact that lines are 0 indexed in the "parser" but not in real life and the fact that the label definition comment takes its own line.
<br><br>
the actual goto implementation:<br>
I don't remember how this works because I wrote most of the _goto function like 3 months ago after reading the sys and inspect module docs.
my projects have this fun property where they are in one of three states: done; not touched or thought about for 2-36 months; and done.
oh well, the goto function is vaguely self explanatory anyways.
<br>
there is some weirdness with operator overloading and how every goto statement is actually just calling what would normally be the bitwise and operator on an instance of the class _goto (not to be confused with the function _goto) and a label object, but that is both very simple and not required to understand this.<br>
also, I don't want to explain it because I am tired.
<br><br>
automatically parsing the importing file on import:<br>
normally, globals are not shared between modules, but python has this cool feature where if there is a general statement to be made about it then this statement can be invalidated using either the sys, inspect, or ctypes library.
this is easily the simplest part as we just grab the filename and global scope of the importing file via the inspect library and pass them to prepare_labels().
<hr>
<h3>goto_label.py</h3>
<pre>
<span class="-keyword">import</span> <span class="-variable">sys</span><span class="-punctuation-delimiter">,</span> <span class="-variable">inspect</span>
<span class="-variable">debug</span> <span class="Operator">=</span> <span class="Boolean">False</span>
<span class="-keyword-function">def</span> <span class="-variable"><span class="-function">prepare_labels</span></span><span class="-punctuation-bracket">(</span><span class="-variable"><span class="-variable">fp</span></span><span class="-punctuation-delimiter">,</span> <span class="-variable"><span class="-variable">scope</span></span><span class="-punctuation-bracket">)</span><span class="-punctuation-delimiter">:</span>
<span class="-keyword">with</span> <span class="-variable"><span class="-function"><span class="-function-builtin">open</span></span></span><span class="-punctuation-bracket">(</span><span class="-variable">fp</span><span class="-punctuation-delimiter">,</span> <span class="String">'r'</span><span class="-punctuation-bracket">)</span> <span class="-keyword">as</span> <span class="-variable">f</span><span class="-punctuation-delimiter">:</span>
<span class="-variable">lines</span> <span class="Operator">=</span> <span class="-variable">f</span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable"><span class="-function">readlines</span></span></span><span class="-punctuation-bracket">(</span><span class="-punctuation-bracket">)</span>
<span class="-keyword">for</span> <span class="-variable">lineno</span><span class="-punctuation-delimiter">,</span> <span class="-variable">line</span> <span class="-keyword-operator">in</span> <span class="-variable"><span class="-function"><span class="-function-builtin">enumerate</span></span></span><span class="-punctuation-bracket">(</span><span class="-variable">lines</span><span class="-punctuation-bracket">)</span><span class="-punctuation-delimiter">:</span>
<span class="-keyword">if</span> <span class="-variable">line</span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable"><span class="-function">startswith</span></span></span><span class="-punctuation-bracket">(</span><span class="String">'#LABEL'</span><span class="-punctuation-bracket">)</span><span class="-punctuation-delimiter">:</span>
<span class="Comment"><span class="-spell"># 1 + 1, first to account for 0 index then to account for comment line</span></span>
<span class="-variable">scope</span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-constant-builtin"><span class="-variable"><span class="-function">__setitem__</span></span></span></span><span class="-punctuation-bracket">(</span><span class="-variable">line</span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable"><span class="-function">split</span></span></span><span class="-punctuation-bracket">(</span><span class="String">' '</span><span class="-punctuation-bracket">)</span><span class="-punctuation-bracket">[</span><span class="Number">1</span><span class="-punctuation-bracket">]</span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable"><span class="-function">strip</span></span></span><span class="-punctuation-bracket">(</span><span class="-punctuation-bracket">)</span><span class="-punctuation-delimiter">,</span> <span class="-variable"><span class="-function"><span class="-function-builtin"><span class="Type">type</span></span></span></span><span class="-punctuation-bracket">(</span>
<span class="String">'label'</span><span class="-punctuation-delimiter">,</span>
<span class="-punctuation-bracket">(</span><span class="-variable"><span class="Type">object</span></span><span class="-punctuation-delimiter">,</span><span class="-punctuation-bracket">)</span><span class="-punctuation-delimiter">,</span>
<span class="-variable"><span class="-function"><span class="-function-builtin"><span class="Type">dict</span></span></span></span><span class="-punctuation-bracket">(</span><span class="-variable"><span class="-variable">line</span></span><span class="Operator">=</span><span class="-variable">lineno</span><span class="Operator">+</span><span class="Number">2</span><span class="-punctuation-bracket">)</span>
<span class="-punctuation-bracket">)</span><span class="-punctuation-bracket">(</span><span class="-punctuation-bracket">)</span><span class="-punctuation-bracket">)</span>
<span class="-variable">_goto</span> <span class="Operator">=</span> <span class="-variable"><span class="-function"><span class="-function-builtin"><span class="Type"><span class="DiagnosticUnderlineError"><span class="DiagnosticUnderlineError">type</span></span></span><span class="DiagnosticUnderlineError"><span class="DiagnosticUnderlineError"></span></span></span><span class="DiagnosticUnderlineError"><span class="DiagnosticUnderlineError"></span></span></span><span class="DiagnosticUnderlineError"><span class="DiagnosticUnderlineError"></span></span></span><span class="DiagnosticUnderlineError"><span class="DiagnosticUnderlineError"><span class="-punctuation-bracket">(</span><span class="String">'goto'</span><span class="-punctuation-delimiter">,</span> <span class="-punctuation-bracket">(</span><span class="-variable"><span class="Type">object</span></span><span class="-punctuation-delimiter">,</span><span class="-punctuation-bracket">)</span><span class="-punctuation-delimiter">,</span> <span class="-variable"><span class="-function"><span class="-function-builtin"><span class="Type">dict</span></span></span></span><span class="-punctuation-bracket">(</span><span class="-variable"><span class="-constant-builtin"><span class="-variable">__and__</span></span></span><span class="Operator">=</span><span class="-keyword-function">lambda</span> <span class="-variable"><span class="-variable">_</span></span><span class="-punctuation-delimiter">,</span> <span class="-variable"><span class="-variable">other</span></span><span class="-punctuation-delimiter">:</span> <span class="-variable"><span class="-function">_goto</span></span><span class="-punctuation-bracket">(</span><span class="-variable">other</span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable">line</span></span><span class="-punctuation-bracket">)</span><span class="-punctuation-bracket">)</span><span class="-punctuation-bracket">)</span></span><span class="-punctuation-bracket"></span></span><span class="-punctuation-bracket"></span>
<span class="-variable">goto</span> <span class="Operator">=</span> <span class="-variable"><span class="-function"><span class="DiagnosticUnderlineError">_goto</span></span><span class="DiagnosticUnderlineError"></span></span><span class="DiagnosticUnderlineError"><span class="-punctuation-bracket">(</span><span class="-punctuation-bracket">)</span></span><span class="-punctuation-bracket"></span>
<span class="-keyword-function">def</span> <span class="-variable"><span class="-function">_goto</span></span><span class="-punctuation-bracket">(</span><span class="-variable"><span class="-variable">lineno</span></span><span class="-punctuation-bracket">)</span><span class="-punctuation-delimiter">:</span>
<span class="-keyword">if</span> <span class="-variable">debug</span><span class="-punctuation-delimiter">:</span> <span class="-variable"><span class="-function"><span class="-function-builtin">print</span></span></span><span class="-punctuation-bracket">(</span><span class="-variable">lineno</span><span class="-punctuation-bracket">)</span>
<span class="-variable">frame</span> <span class="Operator">=</span> <span class="-variable">sys</span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable"><span class="-function">_getframe</span></span></span><span class="-punctuation-bracket">(</span><span class="-punctuation-bracket">)</span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable">f_back</span></span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable"><span class="DiagnosticUnderlineError">f_back</span></span></span>
<span class="-variable">called_from</span> <span class="Operator">=</span> <span class="-variable">frame</span>
<span class="-keyword-function">def</span> <span class="-variable"><span class="-function">hook</span></span><span class="-punctuation-bracket">(</span><span class="-variable"><span class="-variable">frame</span></span><span class="-punctuation-delimiter">,</span> <span class="-variable"><span class="-variable">event</span></span><span class="-punctuation-delimiter">,</span> <span class="-variable"><span class="-variable"><span class="Comment">arg</span></span></span><span class="-punctuation-bracket">)</span><span class="-punctuation-delimiter">:</span>
<span class="-keyword">if</span> <span class="-variable">event</span> <span class="Operator">==</span> <span class="String">'line'</span> <span class="-keyword-operator">and</span> <span class="-variable">frame</span> <span class="Operator">==</span> <span class="-variable">called_from</span><span class="-punctuation-delimiter">:</span>
<span class="-keyword">try</span><span class="-punctuation-delimiter">:</span>
<span class="-variable">frame</span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable">f_lineno</span></span> <span class="Operator">=</span> <span class="-variable">lineno</span>
<span class="-keyword">except</span> <span class="-variable"><span class="Type"><span class="Type">ValueError</span></span></span> <span class="-keyword">as</span> <span class="-variable">e</span><span class="-punctuation-delimiter">:</span>
<span class="-variable"><span class="-function"><span class="-function-builtin">print</span></span></span><span class="-punctuation-bracket">(</span><span class="String">&quot;jump failed:&quot;</span><span class="-punctuation-delimiter">,</span> <span class="-variable">e</span><span class="-punctuation-bracket">)</span>
<span class="-keyword">while</span> <span class="-variable">frame</span><span class="-punctuation-delimiter">:</span>
<span class="-variable">frame</span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable">f_trace</span></span> <span class="Operator">=</span> <span class="-constant-builtin">None</span>
<span class="-variable">frame</span> <span class="Operator">=</span> <span class="-variable">frame</span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable">f_back</span></span>
<span class="-keyword">return</span> <span class="-constant-builtin">None</span>
<span class="-keyword">return</span> <span class="-variable">hook</span>
<span class="-keyword">while</span> <span class="-variable">frame</span><span class="-punctuation-delimiter">:</span>
<span class="-variable">frame</span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable">f_trace</span></span> <span class="Operator">=</span> <span class="-variable">hook</span>
<span class="-variable">frame</span> <span class="Operator">=</span> <span class="-variable">frame</span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable">f_back</span></span>
<span class="-variable">sys</span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable"><span class="-function">settrace</span></span></span><span class="-punctuation-bracket">(</span><span class="-variable">hook</span><span class="-punctuation-bracket">)</span>
<span class="-variable"><span class="-function">prepare_labels</span></span><span class="-punctuation-bracket">(</span><span class="-variable">inspect</span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable"><span class="-function">stack</span></span></span><span class="-punctuation-bracket">(</span><span class="-punctuation-bracket">)</span><span class="-punctuation-bracket">[</span><span class="Operator">-</span><span class="Number">1</span><span class="-punctuation-bracket">]</span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable">frame</span></span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable">f_code</span></span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable">co_filename</span></span><span class="-punctuation-delimiter">,</span> <span class="-variable">inspect</span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable"><span class="-function">stack</span></span></span><span class="-punctuation-bracket">(</span><span class="-punctuation-bracket">)</span><span class="-punctuation-bracket">[</span><span class="Operator">-</span><span class="Number">1</span><span class="-punctuation-bracket">]</span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable">frame</span></span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable">f_globals</span></span><span class="-punctuation-bracket">)</span>
</pre>
<hr>
I find much enjoyment in the syntax for calling a goto statement being goto &label. it looks like something that thoroughly does not belong in python.
<br><br>
ideas for future improvement:
making label names override builtin function names (unreasonably possible) and making a __call__ method on label objects that jumps to that label.
hopefully no one creates any labels named "print".
<hr>
random other programs I (badly) implemented using if conditions only for goto statements out of boredom:
<h3>fibonacci</h3>
<pre>
<span class="-keyword">from</span> <span class="-variable"><span class="DiagnosticUnderlineError">goto_label</span></span> <span class="-keyword">import</span> <span class="Operator"><span class="SpecialChar">*</span></span>
<span class="-keyword-function">def</span> <span class="-variable"><span class="-function">fib</span></span><span class="-punctuation-bracket">(</span><span class="-variable"><span class="-variable">n</span></span><span class="-punctuation-bracket">)</span><span class="-punctuation-delimiter">:</span>
<span class="-variable">depth</span> <span class="Operator">=</span> <span class="Number">0</span>
<span class="-variable">a</span> <span class="Operator">=</span> <span class="Number">1</span>
<span class="-variable">b</span> <span class="Operator">=</span> <span class="Number">0</span>
<span class="Comment"><span class="-spell">#LABEL fib_start</span></span>
<span class="-variable"><span class="-function"><span class="-function-builtin">print</span></span></span><span class="-punctuation-bracket">(</span><span class="-variable">a</span><span class="-punctuation-bracket">)</span>
<span class="-variable">a</span><span class="-punctuation-delimiter">,</span> <span class="-variable">b</span><span class="-punctuation-delimiter">,</span> <span class="-variable">depth</span> <span class="Operator">=</span> <span class="-variable">b</span><span class="-punctuation-delimiter">,</span> <span class="-variable">b</span> <span class="Operator">+</span> <span class="-variable">a</span><span class="-punctuation-delimiter">,</span> <span class="-variable">depth</span> <span class="Operator">+</span> <span class="Number">1</span>
<span class="-keyword">if</span> <span class="-variable">depth</span> <span class="Operator">&gt;</span> <span class="-variable">n</span><span class="Operator">+</span><span class="Number">1</span><span class="-punctuation-delimiter">:</span> <span class="-variable"><span class="DiagnosticUnderlineWarn"><span class="DiagnosticUnderlineError">goto</span></span></span><span class="DiagnosticUnderlineWarn"> <span class="Operator">&amp;</span><span class="-variable"><span class="DiagnosticUnderlineError">fib_end</span></span></span><span class="-variable"></span>
<span class="-variable"><span class="DiagnosticUnderlineWarn"><span class="DiagnosticUnderlineError">goto</span></span></span><span class="DiagnosticUnderlineWarn"> <span class="Operator">&amp;</span><span class="-variable"><span class="DiagnosticUnderlineError">fib_start</span></span></span><span class="-variable"></span>
<span class="Comment"><span class="-spell">#LABEL fib_end</span></span>
<span class="-punctuation-delimiter">...</span>
<span class="-variable"><span class="-function">fib</span></span><span class="-punctuation-bracket"><span class="MatchParen">(</span></span><span class="Number">20</span><span class="-punctuation-bracket"><span class="MatchParen">)</span></span>
</pre>
<h3>fizzbuzz</h3>
<pre>
<span class="-keyword">from</span> <span class="-variable"><span class="DiagnosticUnderlineError">goto_label</span></span> <span class="-keyword">import</span> <span class="Operator"><span class="SpecialChar">*</span></span>
<span class="-keyword-function">def</span> <span class="-variable"><span class="-function">fizzbuzz</span></span><span class="-punctuation-bracket">(</span><span class="-variable"><span class="-variable">n</span></span><span class="-punctuation-bracket">)</span><span class="-punctuation-delimiter">:</span>
<span class="-variable">count</span> <span class="Operator">=</span> <span class="Number">0</span>
<span class="Comment"><span class="-spell">#LABEL fizz_start</span></span>
<span class="-variable"><span class="Type">str</span></span> <span class="Operator">=</span> <span class="String">''</span>
<span class="-keyword">if</span> <span class="-variable">n</span> <span class="Operator">==</span> <span class="-variable">count</span><span class="-punctuation-delimiter">:</span> <span class="-variable"><span class="DiagnosticUnderlineWarn"><span class="DiagnosticUnderlineError">goto</span></span></span><span class="DiagnosticUnderlineWarn"> <span class="Operator">&amp;</span><span class="-variable"><span class="DiagnosticUnderlineError">fizz_end</span></span></span><span class="-variable"></span><span class="-punctuation-delimiter">;</span>
<span class="-variable">count</span> <span class="Operator">+=</span> <span class="Number">1</span>
<span class="-keyword">if</span> <span class="-variable">count</span> <span class="Operator">%</span> <span class="Number">3</span> <span class="Operator">==</span> <span class="Number">0</span><span class="-punctuation-delimiter">:</span> <span class="-variable"><span class="DiagnosticUnderlineWarn"><span class="DiagnosticUnderlineError">goto</span></span></span><span class="DiagnosticUnderlineWarn"> <span class="Operator">&amp;</span><span class="-variable"><span class="DiagnosticUnderlineError">fizz</span></span></span><span class="-variable"></span><span class="-punctuation-delimiter">;</span>
<span class="Comment"><span class="-spell">#LABEL buzz_check</span></span>
<span class="-keyword">if</span> <span class="-variable">count</span> <span class="Operator">%</span> <span class="Number">5</span> <span class="Operator">==</span> <span class="Number">0</span><span class="-punctuation-delimiter">:</span> <span class="-variable"><span class="DiagnosticUnderlineWarn"><span class="DiagnosticUnderlineError">goto</span></span></span><span class="DiagnosticUnderlineWarn"> <span class="Operator">&amp;</span><span class="-variable"><span class="DiagnosticUnderlineError">buzz</span></span></span><span class="-variable"></span><span class="-punctuation-delimiter">;</span>
<span class="-variable"><span class="DiagnosticUnderlineWarn"><span class="DiagnosticUnderlineError">goto</span></span></span><span class="DiagnosticUnderlineWarn"> <span class="Operator">&amp;</span><span class="-variable"><span class="DiagnosticUnderlineError">output</span></span></span><span class="-variable"></span><span class="-punctuation-delimiter">;</span>
<span class="Comment"><span class="-spell">#LABEL fizz</span></span>
<span class="-variable"><span class="Type">str</span></span> <span class="Operator">+=</span> <span class="String">'fizz'</span>
<span class="-variable"><span class="DiagnosticUnderlineWarn"><span class="DiagnosticUnderlineError">goto</span></span></span><span class="DiagnosticUnderlineWarn"> <span class="Operator">&amp;</span><span class="-variable"><span class="DiagnosticUnderlineError">buzz_check</span></span></span><span class="-variable"></span><span class="-punctuation-delimiter">;</span>
<span class="Comment"><span class="-spell">#LABEL buzz </span></span>
<span class="-variable"><span class="Type">str</span></span> <span class="Operator">+=</span> <span class="String">'buzz'</span>
<span class="Comment"><span class="-spell">#LABEL output</span></span>
<span class="-variable"><span class="-function"><span class="-function-builtin">print</span></span></span><span class="-punctuation-bracket">(</span><span class="-variable"><span class="Type">str</span></span> <span class="-keyword">if</span> <span class="-variable"><span class="Type">str</span></span> <span class="-keyword">else</span> <span class="-variable">count</span><span class="-punctuation-bracket">)</span>
<span class="-variable"><span class="DiagnosticUnderlineWarn"><span class="DiagnosticUnderlineError">goto</span></span></span><span class="DiagnosticUnderlineWarn"> <span class="Operator">&amp;</span><span class="-variable"><span class="DiagnosticUnderlineError">fizz_start</span></span></span><span class="-variable"></span><span class="-punctuation-delimiter">;</span>
<span class="Comment"><span class="-spell">#LABEL fizz_end </span></span>
<span class="-punctuation-delimiter">...</span>
<span class="-variable"><span class="-function">fizzbuzz</span></span><span class="-punctuation-bracket"><span class="MatchParen">(</span></span><span class="Number">100</span><span class="-punctuation-bracket"><span class="MatchParen">)</span></span>
</pre>
<hr>
<footnote>number of times the python interpreter segfaulted today: 7</footnote><br>
<footnote>syntax highlighting here is done via :TOhtml in vim. it should work?</footnote>

View File

@ -45,6 +45,23 @@
align-items: center; align-items: center;
} }
.-punctuation-bracket {color: #ff7eb6}
.-keyword-function {color: #ff7eb6}
.Number {color: #ffab91}
.-variable {color: #37474f}
.-variable-builtin {color: #37474f}
.-keyword {color: #ee5396}
.Operator {color: #ee5396}
.-constant-builtin {color: #08bdba}
.-function-builtin {color: #673ab7}
.Type {color: #ee5396}
.-function {font-weight: bold; color: #673ab7}
.String {color: #be95ff}
.Comment {font-style: italic; color: #161616}
.Boolean {color: #ee5396}
.-keyword-operator {color: #ff7eb6}
.-punctuation-delimiter {color: #ff7eb6}
@media (prefers-color-scheme: dark) { @media (prefers-color-scheme: dark) {
:root { :root {
--bg: #161616; --bg: #161616;
@ -56,6 +73,23 @@
--highlight: #33b1ff; --highlight: #33b1ff;
--gray: #202020; --gray: #202020;
} }
.-punctuation-bracket {color: #3ddbd9}
.-keyword-function {color: #3ddbd9}
.Number {color: #82cfff}
.-variable {color: #d0d0d0}
.-variable-builtin {color: #d0d0d0}
.-keyword {color: #78a9ff}
.Operator {color: #78a9ff}
.-constant-builtin {color: #08bdba}
.-function-builtin {color: #ff7eb6}
.Type {color: #78a9ff}
.-function {font-weight: bold; color: #ff7eb6}
.String {color: #be95ff}
.Comment {font-style: italic; color: #525252}
.Boolean {color: #78a9ff}
.-keyword-operator {color: #3ddbd9}
.-punctuation-delimiter {color: #3ddbd9}
} }
.rainbow-text { .rainbow-text {