I am trying to write a very generic editor, and wanted to highlight any known keywords, no context awareness required.
I created the following regex
var commonAttributes = ["var", "val", "let", "if", "else", "export", "import", "return", "static", "fun", "function", "func", "class", "open", "new", "as", "where", "select", "delete", "add", "limit", "update", "insert"]
let standalonePrefix = "(?<=[\\s]|^|[\\(,:])"
let standaloneSuffix = "(?=[\\s\\?\\!,:\\)\\();]|$)"
and the following state.
{
regex: new RegExp(standalonePrefix+"("+commonAttributes.join("|")+")"+standaloneSuffix, "i"),
token: "keyword"
},
I understand that to match at line beginning , I would have to use sol: true, as ^ has no meaning in our context. But this causes problems for me. without sol: true, writing
let leaflet let
will highlight all lets. with sol: true, only first let will match
let leaflet let
My desired outcome is that i get,
let leaflet let
How can I do so?
Since I couldnt find anything to work around this, I ended up using a workaround.
I removed ^ from my prefixes, and created another state with ^ and sol: true.