multiline string regex for nanorc syntax not proper even with start/end keywords
For some basic editing on the server in PHP, using most common php.nanorc's, for multiline strings with lots of concatenation of strings and variables, the color highlighting in nano breaks down.
Example code: Code:
$foo = '<table width="100%" cellpadding="1" cellspacing="1" class="class1"> '. Code:
color yellow "('[^\']*')|(\"[^\"]*\")" Code:
color yellow start="\"" end="\"" Code:
color yellow "<[^= ]*>" ""(\.|[^"])*"" Now this type of code is common and needed in PHP scripting. With the start/end approach I tried to see if it works matching double quotes with double quotes and single with single, so that at least there would be some uniformity. But it turns out that if the start and end characters are the same, as I tried, it simply takes the character as the start every time and thus I get one never ending string right to the end of the file. Shouldn't this behave in a stack kind of way - if it encounters a start quote, and then a next quote, then it is taken as an end quote, and so on? Any regex that fixes this? |
You're doing serious editing in nano? Not to start a flame war of any kind, but... I would seriously use either emacs or vim, or another editor. I personally don't like emacs that much, but it has far more editing features that nano, and both vim and emacs have proper syntax highlighting (and automatic indenting and lots of other features that nano doesn't have)
|
Well, actually I use nano mainly to make one-line changes on files on the server occasionally. But even so the default white on black / black on white was a bit too bland for my liking. So I did some digging about nanorc, and then some experimenting.
For web development proper, since I come from a Windows background, I use Eclipse PDT with its Remote System plugin or sometimes just Konqueror (with its built-in FTP) + Kate, or Geany. Emacs is on my to-do list, but it seems to take some getting used to. |
Could you explain or display exactly how it "breaks down"? And how you want it to behave? Perhaps by posting the code with some color tags. A few extra examples might help too.
If I'm understanding your description, the issue is related to nested quotes and/or tags, and nesting is one thing that regex just isn't capable of handling easily. It may be difficult or even impossible to design a rule that can work in all instances. I also assume that nanorc doesn't treat newlines as special for the purposes of syntax highlighting? |
2 Attachment(s)
First of all, thanks for the reply!
Quote:
There are all manners of quoting, escaping quotes, double + single alternated, etc. It's manageable when the entire thing is on one line. But the moment you split the SQL over multiple lines, all the highlighting goes haywire. This also happens with the tagsoup that is HTML + JS + CSS + PHP-tags (eg <?=$foo['this']['that'];?> ) Quote:
The other part is that it doesnt treat a string as a single string when it is spread over multiple lines. Quote:
Nor in ~/.nanorc or anywhere as such. Code:
# PHP Syntax Highlighting |
Sorry, I don't know much about php syntax, and your screenshots aren't helping to make it clearer. AFAICT, the highlighting in them seems reasonably good. What exactly are the starting and ending points, or keywords, or whatever, that are not being detected correctly?
Please give me a relatively simple example of code where the highlighting goes wrong, and how you actually want your rule to highlight it. You can use your original example above with some color tags around them, if you want. Reading through man nanorc, it appears that you have to use the separate start= and end= flags for a rule to span multiple lines. |
Thanks for your reply.
Here is a fair attempt at showing the colours except for the background color of the editor (which is white in my nano) ... The query-string formation statement when on a single line is like this: Code:
$updateQuestion = mysql_query("UPDATE d3_boxes SET content='".$_POST['content']."', cat_id='".$cat_id."' WHERE box_id='".$_POST['q_id']." Code:
$updateQuestion = mysql_query("UPDATE d3_boxes Quote:
From http://man.he.net/man5/nanorc (and from man nanorc) Code:
color fgcolor,bgcolor start="sr" end="er" |
All times are GMT -5. The time now is 12:11 AM. |