代码样式表:代码的CSS
Code Style Sheets: CSS for Code
AI总结:
本文提出代码样式表,借鉴CSS思想,通过选择器规则基于语义信息细粒度样式化程序文本,并设计紧凑布局算法,在Haskell子集上实现以支持多种程序呈现任务。
摘要:
程序文本以贫乏的排版样式进行渲染。除了字体选择和语法高亮颜色之外,代码编辑器及相关工具几乎不使用任何文本装饰。此外,这些有限的样式是以整体方式应用的,而不考虑手头的程序和任务。我们提出了用于样式化程序文本的代码样式表的概念。受级联样式表(CSS)用于样式化HTML文档的类比启发,代码样式表提供了定义规则以从抽象语法树(AST)中选择元素来样式化其对应视觉表示的机制。技术上,我们的选择器语言将CSS的基本构造推广到具有代数数据类型(如AST)的编程语言环境中。实际上,代码样式表允许基于语义信息(如抽象语法的结构、静态类型信息以及相应的运行时值)以及程序作者和读者的设计选择,对AST进行细粒度样式化。由于程序在结构上高度嵌套,我们设计的一个关键方面是一种布局算法,该算法比现有基于盒子的布局系统(如HTML)更紧凑地渲染嵌套的多行文本块。在本文中,我们为Haskell的一个子集设计并实现了一个代码样式表系统,并使用它来说明几个代码呈现和可视化任务。这些示例表明,代码样式表为以多种方式渲染程序提供了一个统一框架,这可用于未来基于文本和结构编辑器的设计。
英文摘要:
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.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。