Ticket #4252 (closed defect: wontfix)

Opened 4 years ago

Last modified 3 years ago

MCEdit: incorrect syntax detection

Reported by: andrew_b Owned by:
Priority: major Milestone:
Component: mcedit Version: master
Keywords: Cc: TerraTech@…
Blocked By: Blocking:
Branch state: no branch Votes for changeset:

Description

From ticket:4246#comment:6

There are two conditions are used to detect syntax highlighting type:

  • a file name matched to the specified regular expression;
  • a first line of file matched to the specified regular expression (for example, a shebang in shell scripts).

Current implementation is an OR logic: if one of those conditions is met, the rule is considered found (see src/editor/syntax.c).

   1327             q = mc_search (args[1], DEFAULT_CHARSET, editor_file, MC_SEARCH_T_REGEX);
   1328             /* does filename match arg 1 ? */
   1329             if (!q && args[3] != NULL)
   1330             {
   1331                 /* does first line match arg 3 ? */
   1332                 q = mc_search (args[3], DEFAULT_CHARSET, first_line, MC_SEARCH_T_REGEX);
   1333             }
   1334             if (q)
   1335             {
   1336                 int line_error;
   1337                 char *syntax_type;
   1338 
   1339               found_type:
   1340                 syntax_type = args[2];

It is suggested to use AND logic: both regexps must be matched (if the first line regexp is present, of course) to detect the syntax highlighting type:

  • src/editor/syntax.c

    diff --git a/src/editor/syntax.c b/src/editor/syntax.c
    index e271641a1..6c7ede76a 100644
    a b edit_read_syntax_file (WEdit * edit, GPtrArray * pnames, const char *syntax_file 
    13261326 
    13271327            q = mc_search (args[1], DEFAULT_CHARSET, editor_file, MC_SEARCH_T_REGEX); 
    13281328            /* does filename match arg 1 ? */ 
    1329             if (!q && args[3] != NULL) 
     1329            if (q && args[3] != NULL) 
    13301330            { 
    13311331                /* does first line match arg 3 ? */ 
    13321332                q = mc_search (args[3], DEFAULT_CHARSET, first_line, MC_SEARCH_T_REGEX); 

Change History

comment:1 Changed 4 years ago by TerraNova

  • Cc TerraTech@… added

comment:2 follow-up: ↓ 3 Changed 4 years ago by ossi

you can't make it AND, because that would defeat the idea that scripts without a file extension are detected solely by their shebang.

if openrc scripts have no extension "by definition", then their file name pattern must not match anything - either via a special value which makes it explicit, or by an arbitrary "impossible" file name, say n0eXt3ns10n (yeah, that looks stupid).

comment:3 in reply to: ↑ 2 ; follow-up: ↓ 4 Changed 4 years ago by andrew_b

Replying to ossi:

you can't make it AND, because that would defeat the idea that scripts without a file extension are detected solely by their shebang.

This is an argument.

if openrc scripts have no extension "by definition", then their file name pattern must not match anything - either via a special value which makes it explicit, or by an arbitrary "impossible" file name, say n0eXt3ns10n (yeah, that looks stupid).

What about creating of a random file name, like

dd if=/dev/urandom bs=64 count=1 2>/dev/null | md5sum | cut -d' ' -f 1

comment:4 in reply to: ↑ 3 Changed 4 years ago by andrew_b

Replying to andrew_b:

What about creating of a random file name

Or use ^$ pattern as it was in the first version of patch (ticket:4246#comment:1).

comment:5 Changed 4 years ago by ossi

the random pattern would be just as cryptic, even if a bit less stupid-looking.
yeah, the empty pattern does seem like a good idea - after all, the actual file name can't be empty by definition.

comment:6 Changed 4 years ago by andrew_b

  • Status changed from new to closed
  • Resolution set to wontfix

comment:7 Changed 3 years ago by zaytsev

  • Milestone Future Releases deleted
Note: See TracTickets for help on using tickets.