zoukankan      html  css  js  c++  java
  • [笔记]How To Create a Gherkin Syntax Highlighter In gedit

    How To Create a Gherkin Syntax Highlighter In gedit

    Filed under: Uncategorized — Tags: BDDBehatCucumberFreshenGeditGherkin — ranskills @ 8:29 am

    So, I woke up today and did a little bit of surfing, like I always do, and came across Cucumber, a Behaviour-Driven Development (BDD) framework in Ruby and I bought into the idea as it focuses on the behavioural aspects of the system by allowing you to describe and test the system’s behavior. Well, like a typical PHP junkie, I had to look for alternatives in PHP and luckily my search lead me to Behat, a BDD framework in PHP and inspired by Ruby’s Cucumber. Python’s users of Freshen may also find this informative since it uses the same syntax.

    I decided to try out the examples only to realize that Gherkin, the Domain-Specific Language (DSL) used to describe the features to be tested in the features file, had no syntax highlighting in gedit, the official text editor of the GNOME desktop environment.

    These are steps required to provide a basic gherkin syntax highlighting.

    Steps

    一、Locate the directory where all the language files used for source code highlighting are kept, i.e. the language-specs directory.

      Linux

        1、Type the command below to help us locate the language-specs directory.

        

    locate gtksourceview | grep 'javascript.lang$' 

        2、The outcome of the above command is shown below with /usr/share/gtksourceview-2.0/language-specs/as the directory of interest to us.

    /usr/share/gtksourceview-2.0/language-specs/javascript.lang 

      Windows

        The location is going to be either one of these, provided gedit was installed on drive C:\.

        C:\Program Files (x86)\gedit\share\gtksourceview-2.0\language-specs (if on Windows 7)

        OR

        C:\Program Files\gedit\share\gtksourceview-2.0\language-specs

    二、Create a gherkin.lang file into the language-specs directory with the content below.

    <?xml version="1.0" encoding="UTF-8"?>
    <!-- Author: 2011 Ransford Okpoti -->
    <language id="gherkin" _name="Gherkin" version="2.0" _section="Scripts">
          <metadata>
                <property name="mimetypes">text/x-feature</property>
                <property name="globs">*.feature</property>
          </metadata>
          <styles>
                <style id="keyword"     _name="Keyword"        map-to="def:keyword"/>
                <style id="feature"     _name="Feature"        map-to="def:type"/>
                <style id="steps_keywords"     _name="Steps Keywords"    map-to="def:keyword"/>
                <style id="constructors"     _name="Constructors"    map-to="def:type"/>
                <style id="variables"     _name="Variables"    map-to="def:comment"/>
                <style id="comments"     _name="Comments"    map-to="def:comment"/>
          </styles>
          <definitions>
                <context id="gherkin" class="no-spell-check">
                      <include>
                            <!-- Keywords -->
                            <context id="steps_keywords" style-ref="steps_keywords">
                                  <keyword>Given</keyword>
                                  <keyword>When</keyword>
                                  <keyword>Then</keyword>
                                  <keyword>And</keyword>
                                  <keyword>But</keyword>
                            </context>
    
                            <context id="comments" style-ref="comments" end-at-line-end="true">
                                  <start>#</start>
                                  <end>\n</end>
                            </context>
    
                            <context id="feature" style-ref="feature">
                                  <keyword>Feature</keyword>
                            </context>
    
                            <context id="constructors" style-ref="constructors">
                                  <keyword>Scenario</keyword>
                                  <keyword>Scenarios</keyword>
                                  <keyword>Outline</keyword>
                                  <keyword>Background</keyword>
                            </context>
    
                            <context id="variables" style-ref="variables">
                                  <match>(&lt;)(\w+)(&gt;)</match>
                            </context>
    
                            <context id="arguments" end-at-line-end="true">
                                  <start>\|</start>
                                  <end>\n</end>
                                  <include>
                                        <context ref="def:decimal" />
                                        <context ref="def:float" />
                                        <context ref="def:string" />
                                        <context id="table_headings">
                                              <match>\w+</match>
                                        </context>
                                  </include>
                            </context>
                      </include>
                </context>
          </definitions>
    </language>

    三、We are done, close gedit, if you have it opened, and open a gherkin source file with the extension .feature to see the beauty of our work.

    NOTE: On line 3, the _section attribute was set to Scripts indicating that the Gherkin menu item can be located from the program’s menu navigation: View -> Highlight Mode -> Scripts -> Gherkin.

    参考文档:

  • 相关阅读:
    idea2021.2安装后不能打开如何解决?(附无限试用方法)
    Linux驱动实践:一起来梳理中断的前世今生(附代码)
    Linux驱动实践:带你一步一步编译内核驱动程序
    Linux驱动实践:驱动程序如何发送【信号】给应用程序?
    Linux驱动实践:如何编写【 GPIO 】设备的驱动程序?
    Linux驱动实践:你知道【字符设备驱动程序】的两种写法吗?
    【无源物联网】物联网的下一个风口?
    分辨率并不是越高越好,因为人眼分辨能力存在极限
    如何判断一个哈希函数的好坏
    常用设计模式单例模式
  • 原文地址:https://www.cnblogs.com/lizhishugen/p/2825335.html
Copyright © 2011-2022 走看看