Note

The Funtoo Linux project has transitioned to "Hobby Mode" and this wiki is now read-only.

FLOP:An Ebuild Abstract Syntax Tree

From Funtoo
Revision as of 03:29, December 28, 2021 by D4g33z (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Created on
2021/12/27
Original Author(s)
d4g33z
Git sources (for cloning)
Link
Status

Funtoo Linux Optimization Proposal: An Ebuild Abstract Syntax Tree

Let's Create An Abstract Syntax Tree for ebuilds.

feaster: The Funtoo Ebuild Abstract Syntax Tree Tool

Summary

Ebuilds are a rich source of information about software. Their semantics define the ecology of a Funtoo Linux instance: what software can live together under a single root. Their syntax is Bash, a powerful but ill-understood language. I believe that the EAPI may be the most complex single piece of code ever written totally in Bash. Indeed, it achieves a near domain-specific quality with its powerful abstractions. Can certain of those abstractions be lifted out and implemented in another language, e.g. Python?

Architecture

Bash syntax is fairly simple (see https://wiki.bash-hackers.org/syntax/basicgrammar). The nodes of the AST are the following elements:

  • a simple command is just a command and its arguments
  • a pipeline is one or more simple command probably connected in a pipe
  • a list is one or more pipelines connected by special operators
  • a compound command is a list or a special command that forms a new meta-command
  • a function definition makes a compound command available under a new name, and a separate environment


bashlextoo is a fork of bashlex. If an ebuild is transformed or normalized via some simple semantic parsing rules, an AST can be created from it via bashlextoo. See the feast repo for an example.