<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Russell Baxt | UCSC OSPO</title><link>https://deploy-preview-1007--ucsc-ospo.netlify.app/author/russell-baxt/</link><atom:link href="https://deploy-preview-1007--ucsc-ospo.netlify.app/author/russell-baxt/index.xml" rel="self" type="application/rss+xml"/><description>Russell Baxt</description><generator>Wowchemy (https://wowchemy.com)</generator><language>en-us</language><image><url>https://deploy-preview-1007--ucsc-ospo.netlify.app/author/russell-baxt/avatar_hu1b45fd4f618586672daf9bec052f4c47_1157039_270x270_fill_q75_lanczos_center.jpg</url><title>Russell Baxt</title><link>https://deploy-preview-1007--ucsc-ospo.netlify.app/author/russell-baxt/</link></image><item><title>Grammar, Parsers, and Queries</title><link>https://deploy-preview-1007--ucsc-ospo.netlify.app/report/osre23/ucsc/livehd/20230819-rbaxt/</link><pubDate>Sat, 12 Aug 2023 00:00:00 +0000</pubDate><guid>https://deploy-preview-1007--ucsc-ospo.netlify.app/report/osre23/ucsc/livehd/20230819-rbaxt/</guid><description>&lt;h2 id="update-on-tree-sitter-pyrope">Update on tree-sitter-pyrope&lt;/h2>
&lt;p>The pyrope hardware description language now has syntax highlighting available for neovim users.
The &lt;a href="https://github.com/masc-ucsc/tree-sitter-pyrope" target="_blank" rel="noopener">repository&lt;/a> includes a guide to installing the parser, and activating highlights.
After we have tested the syntax highlighting, a pull request will be made to the &lt;a href="https://github.com/nvim-treesitter/nvim-treesitter" target="_blank" rel="noopener">nvim-treesitter repository&lt;/a>.
In this post, I will outline the highlighting process and reflect on a useful feature of neovim.&lt;/p>
&lt;h3 id="syntax-trees">Syntax Trees&lt;/h3>
&lt;p>The pyrope language is described by a grammar. A grammar is a set of rules that describes the allowed structure of a language.
A parser uses the grammar to generate a syntax tree. For example, consider this line of pyrope code.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-shell" data-lang="shell">&lt;span class="line">&lt;span class="cl">var a:u32 &lt;span class="o">=&lt;/span> &lt;span class="m">0&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Using the pyrope parser, we can get a syntax tree for this statement.
The command &lt;code>tree-sitter parse file.prp&lt;/code> gives us the following output.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-shell" data-lang="shell">&lt;span class="line">&lt;span class="cl">&lt;span class="o">(&lt;/span>statement &lt;span class="o">[&lt;/span>1, 0&lt;span class="o">]&lt;/span> - &lt;span class="o">[&lt;/span>1, 13&lt;span class="o">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">(&lt;/span>assignment_or_declaration_statement &lt;span class="o">[&lt;/span>1, 0&lt;span class="o">]&lt;/span> - &lt;span class="o">[&lt;/span>1, 13&lt;span class="o">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> decl: &lt;span class="o">(&lt;/span>var_or_let_or_reg &lt;span class="o">[&lt;/span>1, 0&lt;span class="o">]&lt;/span> - &lt;span class="o">[&lt;/span>1, 3&lt;span class="o">])&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> lvalue: &lt;span class="o">(&lt;/span>complex_identifier &lt;span class="o">[&lt;/span>1, 4&lt;span class="o">]&lt;/span> - &lt;span class="o">[&lt;/span>1, 5&lt;span class="o">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">(&lt;/span>identifier &lt;span class="o">[&lt;/span>1, 4&lt;span class="o">]&lt;/span> - &lt;span class="o">[&lt;/span>1, 5&lt;span class="o">]))&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> type: &lt;span class="o">(&lt;/span>type_cast &lt;span class="o">[&lt;/span>1, 5&lt;span class="o">]&lt;/span> - &lt;span class="o">[&lt;/span>1, 9&lt;span class="o">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> type: &lt;span class="o">(&lt;/span>primitive_type &lt;span class="o">[&lt;/span>1, 6&lt;span class="o">]&lt;/span> - &lt;span class="o">[&lt;/span>1, 9&lt;span class="o">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">(&lt;/span>sized_integer_type &lt;span class="o">[&lt;/span>1, 6&lt;span class="o">]&lt;/span> - &lt;span class="o">[&lt;/span>1, 9&lt;span class="o">])))&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> operator: &lt;span class="o">(&lt;/span>assignment_operator &lt;span class="o">[&lt;/span>1, 10&lt;span class="o">]&lt;/span> - &lt;span class="o">[&lt;/span>1, 11&lt;span class="o">])&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> rvalue: &lt;span class="o">(&lt;/span>constant &lt;span class="o">[&lt;/span>1, 12&lt;span class="o">]&lt;/span> - &lt;span class="o">[&lt;/span>1, 13&lt;span class="o">])))&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>The nvim-treesitter syntax highlighting is based on this tree structure.&lt;/p>
&lt;h3 id="queries">Queries&lt;/h3>
&lt;p>A query is an expression that selects nodes from the tree.
For example,&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-shell" data-lang="shell">&lt;span class="line">&lt;span class="cl">&lt;span class="o">(&lt;/span>complex_identifier &lt;span class="o">(&lt;/span>identifier&lt;span class="o">))&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>matches any identifier that is the child of a complex_identifier.
Color schemes in neovim assign colors to different highlight groups.
So, we can assign highlight groups to tree queries.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-shell" data-lang="shell">&lt;span class="line">&lt;span class="cl">&lt;span class="o">(&lt;/span>constant&lt;span class="o">)&lt;/span> @number
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Now, when a constant shows up in the syntax tree, it will highlight according to the @number group.
Most of the work I did on this project involved studying the pyrope grammar, and writing queries based on it.&lt;/p>
&lt;h2 id="neovim">neovim&lt;/h2>
&lt;p>The text editor &lt;a href="https://neovim.io/" target="_blank" rel="noopener">neovim&lt;/a> is a popular choice among programmers. It allows advanced user control with configuration files.
It also has an active community working on plugins to extend its functionality.
Tools such as lazyvim allow for features like code completion and file management that give neovim the same functionality as IDEs.
However, because neovim configuration is unique to each user, this may make it difficult to reproduce neovim instructions.
For example, Professor Renau was going to test pyrope syntax highlighting in neovim.
However, I did not know what configuration was necessary for him to see highlights in neovim.
While I knew that syntax highlighting worked on my setup, I have lots of configuration files that may have contributed to that success.
There is no guarantee that Professor Renau, or other potential users, have the same neovim configuration that I do.&lt;/p>
&lt;h3 id="nvim_appname">NVIM_APPNAME&lt;/h3>
&lt;p>So, Professor Renau suggested I use the &lt;code>$NVIM_APPNAME&lt;/code> variable to test the process on a fresh configuration.
This feature allows the user to specify the configuration files used to launch neovim.
For example, I installed &lt;a href="https://www.lazyvim.org/" target="_blank" rel="noopener">lazyvim&lt;/a> to the folder &lt;code>~/.config/lazy&lt;/code>. Then, I launched neovim with &lt;code>NVIM_APPNAME=lazy nvim&lt;/code>.
So instead of using my default configuration from &lt;code>~/.config/nvim&lt;/code>, the lazyvim configuration was used.
This allowed me to use a neovim instance that was unaffected by my configuration files.
I was able to preview the process of setting up syntax highlighting from the perspective of a lazyvim user.
Similarly, the process can be done with an empty folder to mimic a brand new neovim installation
The point is, configuration files can impact reproducibility in neovim.
However, this feature allows us to bypass our individual configurations, and create reproducible guidelines.&lt;/p>
&lt;h3 id="conclusion">Conclusion&lt;/h3>
&lt;p>In conclusion, most of my work involved writing queries for the pyrope tree-sitter grammar.
This was for the purpose of syntax highlighting in neovim.
However, an important part of any open source project is communicating the results and providing documentation.
The NVIM_APPNAME feature helps view neovim from the perspective of different users, which helps for writing useful documentation.&lt;/p></description></item><item><title>Highlighting and Formatting Pyrope HDL</title><link>https://deploy-preview-1007--ucsc-ospo.netlify.app/report/osre23/ucsc/livehd/20230526-rbaxt/</link><pubDate>Thu, 22 Jun 2023 00:00:00 +0000</pubDate><guid>https://deploy-preview-1007--ucsc-ospo.netlify.app/report/osre23/ucsc/livehd/20230526-rbaxt/</guid><description>&lt;p>As part of &lt;a href="https://deploy-preview-1007--ucsc-ospo.netlify.app/project/osre23/ucsc/livehd">Micro Architecture Santa Cruz (MASC)&lt;/a> my &lt;a href="https://drive.google.com/file/d/1aJIF-geNoN49zjkFS1W7yur2-rYCxhrt/view?usp=sharing" target="_blank" rel="noopener">proposal&lt;/a> under the mentorship of Jose Renau aims to develop syntax highlighting and a vertical alignment tool for Pyrope. Pyrope is a modern hardware description language under development by MASC. Code is parsed with the &lt;a href="https://github.com/masc-ucsc/tree-sitter-pyrope/tree/main" target="_blank" rel="noopener">tree-sitter grammar for Pyrope&lt;/a>. I am working on developing a query file for the nvim-treesitter plugin. This gives neovim users Pyrope syntax highlighting based on the parse tree. In addition to syntax highlighting, I am working on a vertical alignment tool to improve code readability. These features will improve the usability and convenience of Pyrope.&lt;/p></description></item></channel></rss>