Tuesday, December 20, 2011

Re: sh (bash) syntax for here-document strings: embedding other languages

Andy Spencer <andy753421 <at> gmail.com> writes:

>
> On 2011-12-19 14:00, Timothy Madden wrote:
> > I find this everything-everyore-must-be-a-simple-RE design (for vim
> > syntax highlighting) insufficient to describe the syntax of a language.
> >
> > More high-level features like followed-by, containing and contained
> > regions should be present, but with the ability to add alternatives for
> > the following and previous regions, to search only in a region as one
> > would search in a file, to add names to any regions in order to search
> > or extract data from it later or in other places, or to be used in some
> > kind of group_exists('name') macro, and some other high-level
> > conditionals, using defines or flags declared when matching regions of
> > text like defining them from within the REs used for a match.
>
> For followed-by, containing, and contained, is that that just nextgroup
> and contained/contains/containedin?
>
> You can use nextgroup to do some of the stuff you want, but it's a bit of a
> hack (the keepend part of the hdBody line is important):
>
> unlet! b:current_syntax | syn include @awkSyntax syntax/awk.vim
> unlet! b:current_syntax | syn include @phpSyntax syntax/php.vim
>
> syn region hdBody matchgroup=shRedir contains=hdStart keepend
> \ start="<<-\?["']\?\z(.*\)['"]\?" end="\z1"
> syn match hdStart "\%(<<.*\n\)\@<=" contained nextgroup=@hdLang
>
> syn cluster hdLang contains=hdAwk,hdPhp
> syn region hdAwk start="\%(.*\n\)\{0,4}.*ft=awk" end="\#$" contained
contains=@awksyntax
> syn region hdPhp start="\%(.*\n\)\{0,4}.*ft=php" end="\#$" contained
contains=@phpSyntax

What is "\#$" ? Did you mean "\%$" for the end-of-file, knowing that the
containing group (hdBody) has 'keepend' set ?

I believe my problem lays in the fact that neither \zs nor #re#,ms=s+n can
really set the start of match on a different line than where the pattern
actually starts to match ... maybe nextgroup will help me, as you said.

Nice example, but I wold still like to use the shHereDoc group /aready defined/
in the provided $VIMRUNTIME/syntax/sh.vim, and only write an
~/.vim/after/syntax/sh.vim ... otherwise it starts to feel like I am writing the
sh syntax file myself (the entire file).

Which, after days of struggling with the ubiquitous REs, I might just be able to
do ... the only problem is I would not be satisfied with it no matter how much I
tweak the REs; they can not correctly express here-document identifier quoting
in the shell command language.

Which brings me to another problem: do the ^ and $ (zero-width begin-of-line,
end-of-line anchors) have a problem in vim regexp ? I know I have this tendency
to blame obscure bugs for what does not work, but it can not be a coincidence
that if I replace ^ and $ (at the beginning and end of my large REs) with \n,
than my REs match, while with ^ and $, no match ...

By the way, can you just build your BNF parser to produce REs suitable for vim
"lexical" highlighting ? That would be fun ... !

Thank you,
Timothy Madden


--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment