`
yangzb
  • 浏览: 3506960 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Customizing the new FitNesse parser

阅读更多
FitNesse began its life using the 'simplest thing that works' to parse wiki markup and render it as HTML: a set of regular expressions. Over the years, FitNesse functionality has grown, and the regex-based parser has had to support more and more complex tasks.  More and more hacks have been added to work around regex limitations and performance has suffered as bigger and more complex wiki pages have been thrown at it. So last spring, I started on a project to re-write the entire FitNesse parser, using classic grammar theory approaches.

Although the realities of earning a living slowed progress at times, and the challenges of replicating all the quirks of the original parser tested my resolve, we have finally merged the new parser into the main code base.  Thanks to a number of beta users, it has been tested on some major FitNesse test suites and the next FitNesse release, coming soon, will use the new parser.

One of the features of the original parser was the ability to extend the wiki syntax by plugging in your own custom wiki 'widgets'. This is described here : you write a class that extends WikiWidget and you add a line to a plugins.properties file.

WikiWidgets=className

James Carr wrote a nice post describing a detailed example of this.

The new parser also has this feature, but the plug-in class that you write is different. I'm going to show a very simple example here. Let's imagine we want to write !pi in our wiki pages and have it rendered with the value of pi in the HTML.

public class PiSymbolType extends SymbolType implements Translation {
    public PiSymbolType () {
        super ( "Pi" );
        wikiMatcher ( new Matcher (). string ( "!pi" ));
        htmlTranslation ( this );
    }
    public String toTarget ( Translator translator , Symbol symbol ) {
        return Double . toString ( Math . PI );
    }
}

The plug-in class must extend SymbolType . A plug-in class can specify up to four pieces of information for the parser. Our simple example only needs to supply three of these.

The first is a name, specified in the super constructor. The name is just used for error reporting and debugging and so it can be any descriptive string.

The second is the wikiMatcher . This is an object that knows how to identify the symbol type in the source string. The Matcher class provides a lot of common matching behavior, so we can just tell it that our symbol type is recognized by the string "!pi". You can look at the Matcher source to find other matching behavior.

The third is the wikiRule , which our symbol type doesn't require. This is an object that implements a grammar production rule if our symbol type is composed of other symbol types (a non-terminal, in grammar-speak). Our symbol type is a terminal so we don't need a production rule. Look at the fitnesse.wikitext.parser package to see examples of how production rule classes are written.

The fourth is the htmlTranslation . This is an object that renders the symbol type as a string in the HTML output. We can implement the Translation interface and specify this as our translation object. The toTarget method renders our output, a string containing the value of pi.

We add a line to the plugins.properties file.

SymbolTypes=PiSymbolType


That's it!
分享到:
评论

相关推荐

    Customizing the Microsoft dot NET Framework Common Language Runtime

    Customizing the Microsoft dot NET Framework Common Language Runtime

    Wiley - RibbonX Customizing the Office 2007 Ribbon (Jan 2008)

    本书《RibbonX: Customizing the Office 2007 Ribbon》由Wiley Publishing, Inc.出版,作者包括Robert Martin、Ken Puls以及Teresa Hennig,其主要内容围绕着如何定制Office 2007中的Ribbon界面。Ribbon界面自Office...

    Programming and customizing the PIC microcontroller

    普雷德科已经出版了多部畅销书籍,包括《数字电子学入门》(Digital Electronics Demystified)和《邪恶天才的123个机器人实验》(123 Robotics Experiments for the Evil Genius),这些书籍深受读者喜爱。...

    Customizing the Microsoft dot NET Framework Common Language

    .Net的进阶图书

    Customizing the Operating System Design

    ### 定制操作系统设计 #### 一、定制操作系统设计的重要性 在部署Windows Embedded CE 6.0 R2到目标设备时,必须使用包含必要操作系统(OS)组件、特性、驱动程序以及配置设置的运行时镜像。运行时镜像是操作系统...

    定制通用的打印对话框Customizing the Common Print Dialog

    "定制通用的打印对话框Customizing the Common Print Dialog"这一主题就是关于如何扩展和修改系统提供的标准打印对话框,以实现更丰富的功能或提供更个性化的用户体验。 在Windows API中,通用的打印对话框(Common...

    Customizing the 2007 Office Fluent Ribbon for Developers

    本文将详细介绍如何定制2007 Office Fluent用户界面(UI),并介绍Microsoft Visual Studio 2005 Tools for the 2007 Microsoft Office System中支持的新功能,这些新功能能够帮助开发者快速地开发出Ribbon自定义...

    Visual QuickProject Guide: Customizing Windows XP

    Customizing Windows XP <br> By John Rizzo Publisher: Peachpit Press Pub Date: March 03, 2005 ISBN: 0-321-32124-3 Pages: 144 <br> Every new PC sold comes installed ...

    Customizing_the_Java_Viewer

    ### 定制 Java 观测器 #### 什么是 Java 观测器? Java 观测器是 ESRI 开发的一款基于 Java 的地理信息系统 (GIS) 应用程序,主要用于查看和交互式操作由 ArcIMS(一种用于发布地理信息的服务)提供的地图服务。...

    ERP系统信息化资料:SAP专业培训教材NEW Customizing(Update 06-19).ppt

    ERP系统信息化资料:SAP专业培训教材NEW Customizing(Update 06-19).ppt

    SAP Customizing Documentation

    【SAP Customizing Documentation】是SAP系统实施过程中的一个重要环节,主要涉及到对SAP系统的配置和定制,以适应企业的具体业务需求。SAP作为全球领先的企业资源规划(ERP)软件,提供了广泛的模块来覆盖不同行业...

    Embedded Android - Porting, Extending and Customizing

    综上所述,《嵌入式Android - Porting, Extending and Customizing》这本书不仅深入浅出地讲解了如何将Android系统移植到各种嵌入式设备上,还提供了大量的实践案例和实用技巧,对于希望在这个领域有所作为的专业...

    Your.UNIX.Linux.The.Ultimate.Guide.3rd.Ed

    Chapter 8 The Shell—Customizing the Environment Chapter 9 Simple Filters Chapter 10 Filters Using Regular Expressions—grep and sed Chapter 11 Networking Tools PART II UNIX for the Programmer ...

    LO650 Cross-Functional Customizing in SD

    总之,《LO650 Cross-Functional Customizing in SD》是SAP专业人士不可或缺的知识点集合,它将帮助企业构建一个高效、灵活且适应性强的销售与分销环境,以支持其业务的持续发展。通过深入学习和实践,学员不仅可以...

    Embedded Android Porting, Extending, and Customizing 2013最新版

    ### 嵌入式Android移植、扩展与定制 #### 知识点概览 1. **嵌入式Android概述** 2. **移植Android系统至不同硬件平台** 3. **定制化Android系统的方法** 4. **扩展Android功能的技术** 5. **Android构建系统的深入...

    LWUIT1.2(20090715)

    * Support for setUIID in Component allows customizing the component style selector * More options for background painting (gradients, tiling hints, centering). * Support for more elaborate scrolling...

    Expression.Blend.2.基本教程 示例代码

    - Find out secrets for customizing the controls and working with resources. - Learn all about the breadcrumb bar, and how it makes control customization easier. - Uncover how to edit drawing brushes...

Global site tag (gtag.js) - Google Analytics