ajaxorg / ajaxorg/ace

(extending syntax highlighting): (use of look behind breaks token array)

Aperta
#6,001 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
bug needs-triage
Lingua principale
JavaScript
Stelle
27.1k
Fork
5.3k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

### Describe the bug

Using the `https://ace.c9.io/tool/mode_creator.html` tool, please consider the **TestRules** mode in the reproduction part of the Issue.

When the regex in the line labelled 'problematic line' is as listed below, each of the captured groups is mapped correctly to the array of tokens in the line labelled 'token array that breaks', which can be verified by hovering over each component of one of the 'metaoptions' (eg `:second-option<<<<>>>>`)

This seems to be a bug as look ahead/behind assertions do work, but they just screw up the (documented) array mapping. (I have not investigated whether the sub-match groups can be accessed by passing the match to a subroutine. In any case, there is either a bug here, maybe some undocumented syntax to extract the subgroups).

### Expected Behavior

The regex in the line labelled 'problematic line' should generate a match object with an array of subgroups that can be mapped into the array defined in `token`.

### Current Behavior

Adding a look-behind assertion allocates the matched text to the first of element of the array.

Prepend the first group with a look-behind assertion, the whole regex match fails.

For example,
```
regex: "(?<=\\s)(\\:[a-zA-Z][a-zA-Z0-9_-]+)([<({]+)([^>)}]+)([>)}]+)", //problematic line
\\ !!!!!!!!!!!!
\\ it doesnt matter whether the look-behind is inside or outside the first group bracket
```
breaks the regex to token mapper.

If the associated token line is changed to either of the forms below, the 'metaoption' **is** matched but only the token `"nop"` is allocated to the whole matched segment.
```
token: ["nop","s_metaoption", "lbrk", "s_option_cont", "rbrk"], // token array that breaks
// or where the match is mapped to *s-metaoption*
//token: "s_metaoption", // token array that breaks
```

### Reproduction Steps

Below is the working version of the test mode without the look behind assertion in the problematic line,
and here is a line of data to apply the mode to:
```
=document vvv :one-option :second-option<<<<>>>>
```
working code
```
"use strict";

var oop = require("../lib/oop");
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;

var TestRules = function () {

var metaoption_c = {
token: ["s_metaoption", "lbrk", "s_option_cont", "rbrk"], // token array that breaks
regex: "(\\:[a-zA-Z][a-zA-Z0-9_-]+)([<({]+)([^>)}]+)([>)}]+)", //problematic line
next: "metaoptionLine"
};

this.$rules = {
"start" : [
{
token: "s_document",
regex: "=document\\b",
next: "metaoptionLine"
}
],
"metaoptionLine" : [
metaoption_c,
{
token: "invalid.illegal",
regex: "(?<=\\s)[^\\s:]\\S+(?=\\s)",
next: "metaoptionLine"
},
{
token: "text",
regex: "(\\s*)$",
next: "start"
},
]
}
};

oop.inherits(TestRules, TextHighlightRules);

exports.TestRules = TestRules;
```

### Possible Solution

The match object with a look-behind assertion is more complex than a simple array.

There is no *documented* method to access sub-matches

### Additional Information/Context

_No response_

### Ace Version / Browser / OS / Keyboard layout

Accessing https://ace.c9.io/tool/mode_creator.html using a Firefox browser.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.