paperbot · PL 论文追踪

全部论文 待读 收藏

P2 Code Style Sheets: CSS for Code

代码样式表:面向代码的 CSS
OOPSLA 9(OOPSLA1)2025匹配度 2/10 · 该论文属于程序语言与开发者工具方向,关注用 CSS 式选择器对 AST 进行样式化和代码可视化,与用户核心的静态分析、LLM/Agent、浮点程序分析及贝叶斯程序分析均无直接关联;仅因涉及 AST 与 DSL 有微弱交集。引用 4 inbox
Sam Cohen, Ravi Chugh
crossref: 2026-09-10

AI 速览

一句话:提出“代码样式表”,将 CSS 式选择器推广到 AST,按语义信息对不同粒度的代码显示进行样式化。

程序文本的排版样式很有限:编辑器通常只有字体和语法高亮,且不区分程序与任务。受 CSS 启发,本文提出代码样式表,用规则从抽象语法树(AST)选择元素,再样式化其可视化表示。选择器语言将 CSS 核心构造推广到含代数数据类型的编程语言环境;针对程序高度嵌套的特点,设计比 HTML 盒式布局更紧凑的多行嵌套块布局算法。作者为 Haskell 子集实现该系统,并通过多种代码呈现与可视化任务表明:代码样式表能依据 AST 结构、静态类型、运行时值及作者/读者偏好,细粒度且统一地渲染程序,可用于未来文本与结构编辑器。

问题
程序文本的排版样式贫乏且应用方式单一,缺乏按程序语义和任务需求进行细粒度样式化的机制。
方法
受 CSS 启发,设计代码样式表:将 CSS 选择器推广到 AST,支持基于代数数据类型、静态类型与运行时值选择元素,并实现紧凑的多行嵌套布局算法;在 Haskell 子集上实现。
评估
通过多个代码呈现与可视化任务展示系统能力,说明其可作为统一框架支持文本与结构编辑器中的多样程序渲染。
原文摘要(Abstract)

Program text is rendered using impoverished typographic styles. Beyond choice of fonts and syntax-highlighting colors, code editors and related tools utilize very few text decorations. These limited styles are, furthermore, applied in monolithic fashion, regardless of the programs and tasks at hand. We present the notion of code style sheets for styling program text. Motivated by analogy to cascading style sheets (CSS) for styling HTML documents, code style sheets provide mechanisms for defining rules to select elements from an abstract syntax tree (AST) in order to style their corresponding visual representation. Technically, our selector language generalizes essential constructs from CSS to a programming-language setting with algebraic data types (such as ASTs). Practically, code style sheets allow ASTs to be styled granularly, based on semantic information—such as the structure of abstract syntax, static type information, and corresponding run-time values—as well as design choices on the part of authors and readers of a program. Because programs are heavily nested in structure, a key aspect of our design is a layout algorithm that renders nested, multiline text blocks more compactly than in existing box-based layout systems such as HTML. In this paper, we design and implement a code style sheets system for a subset of Haskell, using it to illustrate several code presentation and visualization tasks. These examples demonstrate that code style sheets provide a uniform framework for rendering programs in multivarious ways, which could be employed in future designs for text-based as well as structure editors.

链接与引用

DOI 原文 · PDF(开放获取) ·

BibTeX
@article{paperbot3180,
  title = {Code Style Sheets: CSS for Code},
  author = {Sam Cohen and Ravi Chugh},
  journal = {Proceedings of the ACM on Programming Languages},
  volume = {9},
  number = {OOPSLA1},
  year = {2025},
  doi = {10.1145/3720421}
}