> From: bill lam
> 
> Could you also add an 'error' style for unbalanced
> quote for string constants outside context of comment or noundef, if
> that is still missing?

I think this j.lang does the job.
I've also added a customized version of edit.xml below to complete the example.

The main thing I'd still like to see added is support for parentheses inside 
explicit definitions. Currently adding parens in the expdef context causes 
problems with parsing the start/end of expdef. Any ideas?


==============system/config/j.lang ==============
<?xml version="1.0" encoding="UTF-8"?>
<!-- Authors: Jsoftware -->
<language id="j" _name="J" version="2.0" _section="Sources">
    <metadata>
      <property name="mimetypes">text/x-j;text/x-jsrc</property>
      <property name="globs">*.ijs</property>
      <property name="line-comment-start">NB\.</property>
    </metadata>

    <styles>
      <style id="comment"   _name="Comment"           />
      <style id="control"   _name="Control"           />
      <style id="error"     _name="Error"             />      
      <style id="global"    _name="Global"            />
      <style id="local"     _name="Local"             />
      <style id="noundef"   _name="Noun Definition"   />
      <style id="number"    _name="Number"            />
      <style id="parens"    _name="Parens"            />
      <style id="primitive" _name="Primitive"         />
      <style id="string"    _name="String"            />
    </styles>

    <definitions>

        <!-- problems/shortcomings
          primitives other than =: =.
          
          parens inside expdef
          
          matched vs unmatched parens coloring

          marking matching paren might be nice but how to
          do () and not {} and [] -->

        <!-- NB. -->
          <context id="comment" style-ref="comment" end-at-line-end="true">
            <start>\%[NB\.</start>
          </context>

        <!-- 'abcde' -->  
          <context id="string" style-ref="string" end-at-line-end="true">
            <start>L?'</start><end>'</end>
          </context>

        <!-- Unbalanced single quotes -->
          <context id="error" style-ref="error">
            <match>'[^']*?$</match>
          </context>
          
        <!-- 2.34 -->
          <context id="number" style-ref="number">
            <match extended="true">\%[[_0-9][_0-9\.a-zA-Z]*\%]</match>
          </context>

        <!-- () -->
          <context id="parens" style-ref="parens">
            <match>[\(\)]</match>
          </context>

          <define-regex id="valid-name">[a-zA-Z][a-zA-Z0-9_]*\.</define-regex>
          <define-regex id="close-expdef">^\s*\)\s*$</define-regex>

        <!-- if. do. end. -->
          <context id="control" style-ref="control">
            <prefix>\%[</prefix>
            <suffix></suffix>
            <keyword>assert\.</keyword>
            <keyword>break\.</keyword>
            <keyword>continue\.</keyword>
            <keyword>do\.</keyword>
            <keyword>for\.</keyword>
            <keyword>if\.</keyword>
            <keyword>else\.</keyword>
            <keyword>elseif\.</keyword>
            <keyword>end\.</keyword>            
            <keyword>return\.</keyword>
            <keyword>select\.</keyword>
            <keyword>case\.</keyword>
            <keyword>fcase\.</keyword>
            <keyword>throw\.</keyword>                                          
                              
            <keyword>try\.</keyword>
            <keyword>catch\.</keyword>
            <keyword>catchd\.</keyword>
            <keyword>catcht\.</keyword>
            <keyword>while\.</keyword>
            <keyword>whilst\.</keyword>                                         
                               
            <keyword>for_\%{valid-name}</keyword>
            <keyword>goto_\%{valid-name}</keyword>
            <keyword>label_\%{valid-name}</keyword>                             
                                           
          </context>
          
        <!-- explicit definition -->
          <context id="expdef" style-inside="true">
            
<start>\%[(([1-4]|13)\s+:\s*0)|((adverb|conjunction|verb|monad|dyad)\s+define)\%]</start>
            <end>\%{close-expdef}</end>
            <include>
              <context ref="comment"/>
              <context ref="error"/>              
              <context ref="string"/>
              <context ref="number"/>
              <context ref="control"/>              
            </include>
          </context>

        <!-- explicit noun definition -->
          <context id="noundef" style-ref="noundef" style-inside="true">
            <start>\%[(0\s+:\s*0|noun\s+define)\%].*$</start>
            <end>\%{close-expdef}</end>
          </context>

        <!-- Note (multiline comment) -->
          <context id="note" style-ref="comment" style-inside="true">
            <start>\%[Note\%].*$</start>
            <end>\%{close-expdef}</end>
          </context>

        <!-- =: -->
          <context id="global" style-ref="global">
            <match>=:</match>
          </context>

        <!-- =. -->
          <context id="local" style-ref="local">
            <match>=\.</match>
          </context>

      <context id="j">
        <include>
           <context ref="comment"/>
           <context ref="error"/>           
           <context ref="string"/>
           <context ref="expdef"/>
           <context ref="noundef"/>
           <context ref="note"/>
           <context ref="parens"/>
           <context ref="number"/>
           <context ref="global"/>
           <context ref="local"/>
        </include>
      </context>
    </definitions>
</language>



==============system/config/edit.xml==============

<?xml version="1.0" encoding="UTF-8"?>

 <!-- editor -->

<style-scheme id="edit" _name="edit" version="1.0">

  <_description>Jstandard scheme</_description>

  <color name="bordeaux"    value="#A52A2A"/>
  <color name="cyan"        value="#008A8C"/>
  <color name="gray"        value="#777777"/>
  <color name="green"       value="#2E8B57"/>
  <color name="light green" value="#DDFCDE"/>  
  <color name="high"        value="#e4e4d4"/>
  <color name="purple"      value="#A020F0"/>
  <color name="violet"      value="#6A5ACD"/>
  <color name="yellow"      value="#FFFF00"/>
  
  <style name="text"        foreground="#black" background="light green"/>
  <style name="selection"   foreground="#white" background="#lightblue"/>
  <style name="current-line"   background="high"/>
  
  <style name="j:comment"   foreground="gray" italic="true" />
  <style name="j:control"   foreground="#red"/>
  <style name="j:error"     foreground="#magenta"/>
  <style name="j:global"    foreground="bordeaux"/>
  <style name="j:local"     foreground="purple"/>
  <style name="j:noundef"   foreground="#blue"/>
  <style name="j:number"    foreground="purple"/>
  <style name="j:parens"    foreground="green" bold="true"/>
  <style name="j:primitive" foreground="cyan"/>
  <style name="j:string"    foreground="#blue"/>
  

  <!-- Bracket Matching -->
  <style name="bracket-match"    foreground="#white" background="#gray" 
bold="true"/>
  <style name="bracket-mismatch" foreground="#white" background="#red" 
bold="true"/>

  <!-- Search Matching -->
  <style name="search-match"     background="#yellow"/>  

</style-scheme>

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to