GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Mon Nov 24, 2014 1:16 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: GtkSourceView .lang file Period in Regular Expression
PostPosted: Mon Jan 13, 2014 6:22 pm 
Offline

Joined: Mon Sep 02, 2013 10:02 pm
Posts: 4
I would appreciate some help with a regex in a .lang file. I am writing a gedit syntax highlighter for the Atmel AVR assembly language. In this language, assembler directives all begin with a period, for example: .BYTE

I would like to instruct gedit 1) only to highlight these directives if they start with a period, and 2) to include the period in the highlighting. My test .lang file is:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!-- TODO Add Author and Licence -->
<language id="assembler-avr" _name="Assembler (Atmel AVR)" version="2.0" _section="Sources">
  <metadata>
    <property name="mimetypes">text/x-asm</property>
    <property name="globs">*.asm</property>
  </metadata>

  <styles>
    <style id="directive" _name="Assembler-directive" map-to="def:preprocessor"/>
  </styles>
 
  <default-regex-options case-sensitive="false"/>

  <definitions>
    <context id="assembler-avr" class="no-spell-check">
      <include>
        <!-- Assembler Directives -->
        <context id="directive" style-ref="directive">
          <keyword>BYTE</keyword>
        </context>
      </include>
    </context>
  </definitions>
</language>


<keyword>BYTE</keyword> highlights 'BYTE', but ignores the period: .BYTE

<keyword>.BYTE</keyword> highlights 'aBYTE' as expected (match any single character): aBYTE but not '.BYTE'

<keyword>\.BYTE</keyword> fails to highlights 'BYTE' or '.BYTE' but works if (spurious) characters are added: aa.BYTE

What expression do I need? or is the problem with how word boundaries are defined? I admit to being a noob at regular expressions, and if this is the wrong list, please advise.


Top
 Profile  
 
 Post subject: Re: GtkSourceView .lang file Period in Regular Expression
PostPosted: Wed Jan 15, 2014 9:12 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 778
Location: UK
Hello,

I have not tried any of this.

The period '.' is a meta character that is used to match any character. It is not used as a meta character inside a character class so I would expect the following to work. A character class being within square brackets. Or the escape character may need to be doubled up
Code:
<keyword>[.]BYTE</keyword>
Or the escape character may need to be doubled up
Code:
<keyword>\\.BYTE</keyword>

_________________
E.


Top
 Profile  
 
 Post subject: Re: GtkSourceView .lang file Period in Regular Expression
PostPosted: Wed Jan 15, 2014 3:46 pm 
Offline

Joined: Mon Sep 02, 2013 10:02 pm
Posts: 4
<keyword>\\.BYTE</keyword> does not work at all

<keyword>[.]BYTE</keyword> has the same behaviour as I noticed with <keyword>\.BYTE</keyword>, ie it will highlight the period and BYTE, but only when preceeded by spurious characters, viz: aa.BYTE


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group