emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] let octave-mode understand single-quoted strings


From: Eric M. Ludlam
Subject: Re: [PATCH] let octave-mode understand single-quoted strings
Date: Tue, 05 Oct 2010 19:57:41 -0400
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.3a1pre) Gecko/20091222 Shredder/3.1a1pre

The matlab mode that I support can be found here:

http://matlab-emacs.cvs.sourceforge.net/viewvc/matlab-emacs/matlab-emacs/

It has had many contributors so it couldn't be a part of emacs, but the string & comment font locking I wrote wholly myself as far as I remember. If you would like to use it for octave I'm sure that could be arranged.

If not, the basic idea behind it is to use font-lock's functional matching stuff. Look to these functions:

matlab-font-lock-string-match-normal
matlab-font-lock-string-match-unterminated
matlab-font-lock-comment-match

The strings and comments have to be done together, so you end up having to use these functions in a particular order, checking to see what faces are left behind while looking at comment chars to make sure it isn't in a string.

Eric

On 10/05/2010 04:28 AM, John W. Eaton wrote:
On  3-Sep-2010, Stefan Monnier wrote:

|>>  I just implemented the single-quote string support based
|>>  on code I previously wrote for perl-mode, where it's used for
|>>  string-like thingies that often span multiple lines.  I.e. it came "for
|>>  free".

In Octave and Matlab, character strings can't span multiple lines.

| BTW, where can I find a definition of the syntax of single-quoted
| strings (i.e. how does Octave distinguish a transpose from a single-quote
| starting a string)?
| The Octave docs I have don't say anything about it, AFAICT.

It's messy.

A single-quote character is recognized as a transpose operator if it

* Follows a ), ], or } character

     ( .. )'     =>  tranpose expression
     [ .. ]'     =>  tranpose matrix expression
     { .. }'     =>  tranpose cell array expression

* Follows a literal double-quoted string, or a literal single-quoted
   string if there is a space between the transpose operator and the
   final single-quote character that delimits the string.  For example

     "string"'   =>  transpose the character array 'string'
     'string' '  =>  transpose the character array 'string'
     'string''   =>  unterminated string constant
     'a''b'      =>  1x3 character array containing the characters a'b

* Follows an identifier (variable or function name) unless the
   identifier could be a "command".  For example

     pwd '       =>  unterminated string constant
     (pwd)'      =>  transpose the output from the pwd function
     dir 'foo'   =>  list contents of the directory foo

* Follows an expression that references a structure element:

     a.b'        =>  return the transpose of a.b

   The Octave manual has a more complete description of how
   "command-style" parsing works (yes, this is ugly; it was implemented
   because it is required for compatibility with Matlab).

Does that help?

jwe





reply via email to

[Prev in Thread] Current Thread [Next in Thread]