[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kwrite-devel
Subject:    Re: Syntax highlighting for nroff/man
From:       Matthew Woehlke <mwoehlke () tibco ! com>
Date:       2006-10-18 23:16:48
Message-ID: eh6cl5$na8$1 () sea ! gmane ! org
[Download RAW message or body]

Andriy Lesyuk wrote:
> Hi
> 
> I have created simple syntax highlighting file for nroff/man language. 
> This syntax file is based on nroff.syntax from midnight commander plus 
> some enhancements.
> 
> Unfortunately I don't know nroff well that's why I can't be sure that 
> syntax file was written correctly. It would be good if someone who knows
> nroff better would look at it...
> 
> Home in future this file can be added to katepart.

I'm attaching my own mandoc highlighter (complete) and the beginnings of 
a roff highlighter (keyword lists are as of yet 99.9% unpopulated). The 
mandoc highlighter relies on the roff highlighter, but ultimately both 
rely on the patch in http://bugs.kde.org/show_bug.cgi?id=135844 (which I 
just posted like 30 minutes ago).

I think this is a better solution because it generalizes the roff 
highlighting into a re-usable .xml, and the mandoc highlighter just adds 
the andoc.tmac stuff to the underlying roff highlighter. With this 
system it would be very easy to add highlighters for other standard 
macro packages, and they would be equally small.

Compared to yours, the mandoc highlighting is less sophisticated 
(though, per my other comments, I think it is more in line in terms of 
typical highlighters and correct functionality). The roff highlighter on 
the other hand is much more sophisticated, and includes folding and 
generic recognition of special markups (registers, strings, escapes, 
fonts, and glyphs), and will be improving as I continue work on it.

The kateversion tags needs to change, though, since these rely on new 
functionality. (BTW, WHERE do I find the kate version in katepart?)

-- 
Matthew
Don't use a hippo to... what was I saying?

["mandoc.xml" (text/xml)]

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE language SYSTEM "language.dtd">
<language name="Troff Mandoc" section="Markup" version="0.11" kateversion="2.4" \
extensions="*.1;*.2;*.3;*.4;*.5;*.6;*.7;*.8;*.1m;*.3x;*.tmac" mimetype="" \
author="Matthew Woehlke (mw_triad@sourceforge.net)" license="GPL">

  <highlighting>

    <list name="headings">
      <item>SH</item>
      <item>SS</item>
      <item>TH</item>
    </list>

    <list name="paragraph">
      <item>HP</item>
      <item>IP</item>
      <item>LP</item>
      <item>P</item>
      <item>PD</item>
      <item>PP</item>
      <item>RE</item>
      <item>RS</item>
      <item>TP</item>
    </list>

    <list name="formatting">
      <item>B</item>
      <item>BI</item>
      <item>BR</item>
      <item>I</item>
      <item>IB</item>
      <item>IR</item>
      <item>RB</item>
      <item>RI</item>
      <item>SM</item>
      <item>SB</item>
    </list>

    <list name="others">
      <item>DT</item>
    </list>

    <contexts>

      <!-- root context -->
      <context name="Normal" attribute="Normal Text" lineEndContext="#stay">
        <RegExpr attribute="Comment" context="Comment" String="\.\s*\\&quot;" \
                column="0"/>
        <DetectChar attribute="Macros" context="DetectDirective" char="." \
column="0"/>  <IncludeRules context="DetectOthers##Roff"/>
      </context>

      <!-- directive start -->
      <context name="DetectDirective" attribute="Macros" lineEndContext="#pop">
        <keyword attribute="Headings" context="Directive" String="headings"/>
        <keyword attribute="Paragraphs" context="Directive" String="paragraph"/>
        <keyword attribute="Formatting" context="Directive" String="formatting"/>
        <keyword attribute="Other Macros" context="Directive" String="others"/>
        <IncludeRules context="DetectDirective##Roff"/>
      </context>

      <context name="Directive" attribute="Identifier" lineEndContext="#pop">
        <IncludeRules context="Directive##Roff"/>
      </context>

      <!-- comment -->
      <context name="Comment" attribute="Comment" lineEndContext="#pop">
        <IncludeRules context="##Alerts"/>
      </context>

    </contexts>

    <itemDatas>
      <itemData name="Normal Text"    defStyleNum="dsNormal"/>
      <itemData name="Comment"        defStyleNum="dsComment"/>
      <itemData name="Macros"         defStyleNum="dsFunction"/>
      <itemData name="Headings"       defStyleNum="dsKeyword"/>
      <itemData name="Paragraphs"     defStyleNum="dsDataType"/>
      <itemData name="Formatting"     defStyleNum="dsKeyword"/>
      <itemData name="Other Macros"   defStyleNum="dsFunction"/>
      <itemData name="Identifier"     defStyleNum="dsString"/>
    </itemDatas>

  </highlighting>

  <general>

    <comments>
      <comment name="singleLine" start=".\&quot;" />
    </comments>

    <keywords casesensitive="1"/>

  </general>

</language>


["roff.xml" (text/xml)]

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE language SYSTEM "language.dtd"
[
  <!ENTITY roffid "([a-zA-Z]|\([a-zA-Z]{2}|\[[^]]+\])">
]>
<language name="Roff" section="Markup" version="0.11" kateversion="2.4" \
author="Matthew Woehlke (mw_triad@sourceforge.net)" license="GPL">

  <highlighting>

    <list name="layout">
      <item>br</item>
      <item>sp</item>
    </list>

    <list name="formatting">
    </list>

    <list name="gnuext">
    </list>

    <contexts>

      <!-- root context -->
      <context name="Normal" attribute="Normal Text" lineEndContext="#stay">
        <RegExpr attribute="Comment" context="Comment" String="\.\s*\\&quot;" \
                column="0"/>
        <DetectChar attribute="Other Macros" context="DetectDirective" char="." \
column="0"/>  <IncludeRules context="DetectOthers"/>
      </context>

      <!-- catch glyphc, registers, strings, etc -->
      <context name="DetectOthers" attribute="Normal Text" lineEndContext="#stay">
        <RegExpr attribute="Register" context="#stay" String="\\[n*]&roffid;"/>
        <RegExpr attribute="Font" context="#stay" String="\\f&roffid;"/>
        <RegExpr attribute="Escape" context="#stay" \
String="\\[-%\\|^{}'`_!?@)/,&amp;:~0acdeEprtu]"/>  <RegExpr attribute="Glyph" \
context="#stay" String="\\&roffid;"/>  <DetectChar attribute="String" \
context="String" char="&quot;"/>  </context>

      <!-- directive start -->
      <context name="DetectDirective" attribute="Other Macros" lineEndContext="#pop">
        <keyword attribute="Layout Macros" context="Directive" String="layout"/>
        <keyword attribute="Format Macros" context="Directive" String="formatting"/>
        <keyword attribute="GNU Macros" context="Directive" String="gnuext"/>
        <RegExpr attribute="Other Macros" context="dsDirective" String="\s*ds\b" \
                column="1"/>
        <RegExpr attribute="Other Macros" context="deDirective" String="\s*de\b" \
                column="1" beginRegion="de"/>
        <RegExpr attribute="Other Macros" context="Directive" \
                String="\s*di\s+[A-Za-z]+" column="1" beginRegion="di"/>
        <RegExpr attribute="Other Macros" context="Directive" String="\s*di\b" \
                column="1" endRegion="di"/>
        <RegExpr attribute="Other Macros" context="Directive" String="\s*[A-Za-z]+\b" \
column="1"/>  </context>

      <!-- comment -->
      <context name="Comment" attribute="Comment" lineEndContext="#pop">
        <IncludeRules context="##Alerts"/>
      </context>

      <!-- generic directive -->
      <context name="Directive" attribute="Identifier" lineEndContext="#pop">
        <Float attribute="Number" context="#stay"/>
        <Int attribute="Number" context="#stay"/>
        <Detect2Chars attribute="Comment" context="Comment" char="\\" \
char1="&quot;"/>  <IncludeRules context="DetectOthers"/>
      </context>

      <!-- quoted string -->
      <context name="String" attribute="String" lineEndContext="#pop">
        <Detect2Chars attribute="Escape" context="#stay" char="\\" char1="&quot;"/>
        <DetectChar attribute="String" context="#pop" char="&quot;"/>
        <IncludeRules context="DetectOthers"/>
      </context>

      <!-- .de directive -->
      <context name="deDirective" attribute="Identifier" lineEndContext="deBody"/>
      <context name="deBody" attribute="Normal Text" lineEndContext="#stay">
        <Detect2Chars attribute="Other Macros" context="#pop#pop" char="." char1="." \
column="0" endRegion="de"/>  <IncludeRules context="Normal"/>
      </context>

      <!-- .ds directive -->
      <context name="dsDirective" attribute="Identifier" lineEndContext="#pop">
        <Int attribute="Number" context="#stay"/>
        <Float attribute="Number" context="#stay"/>
        <Detect2Chars attribute="Comment" context="Comment" char="\\" \
char1="&quot;"/>  <DetectChar attribute="String" context="dsString" char="&quot;"/>
        <IncludeRules context="DetectOthers"/>
      </context>

      <!-- .ds quoted value -->
      <context name="dsString" attribute="String" lineEndContext="#pop">
        <Detect2Chars attribute="Comment" context="Comment" char="\\" \
char1="&quot;"/>  <IncludeRules context="DetectOthers"/>
      </context>

    </contexts>

    <itemDatas>
      <itemData name="Normal Text"    defStyleNum="dsNormal"/>
      <itemData name="Comment"        defStyleNum="dsComment"/>
      <itemData name="Layout Macros"  defStyleNum="dsKeyword"/>
      <itemData name="Format Macros"  defStyleNum="dsKeyword"/>
      <itemData name="GNU Macros"     defStyleNum="dsDataType"/>
      <itemData name="Other Macros"   defStyleNum="dsFunction"/>
      <itemData name="Identifier"     defStyleNum="dsString"/>
      <itemData name="Number"         defStyleNum="dsDecVal"/>
      <itemData name="Register"       defStyleNum="dsOthers"/>
      <itemData name="Font"           defStyleNum="dsOthers"/>
      <itemData name="Glyph"          defStyleNum="dsOthers"/>
      <itemData name="Escape"         defStyleNum="dsChar"/>
      <itemData name="String"         defStyleNum="dsString"/>
    </itemDatas>

  </highlighting>

  <general>

    <comments>
      <comment name="singleLine" start=".\&quot;" />
    </comments>

    <keywords casesensitive="1"/>

  </general>

</language>



_______________________________________________
KWrite-Devel mailing list
KWrite-Devel@kde.org
https://mail.kde.org/mailman/listinfo/kwrite-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic