question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Monarch grammar: Regex starting with ^ should only match start of source line, but it does not.

See original GitHub issue

monaco-editor version: 0.19.3 Browser: Chrome 79 OS: macOS Playground code that reproduces the issue:

According to the Monarch docs:

If it starts with a ^ character, the expression only matches at the start of a source line.

I have tried both specifying a regex literal /^!/ as well as a string "^!", but neither works.

You can reproduce the issue on the special Monarch playground at https://microsoft.github.io/monaco-editor/monarch.html. In the Language syntax definition, specify:

return {
  // The main tokenizer for our languages
  tokenizer: {
    root: [
      [/^\!/, {token: 'delimiter.curly', next: 'jsonInBang', nextEmbedded: 'json'}],
    ],
    jsonInBang: [
      [/^\!/, {token: 'delimiter.curly', next: '@pop', nextEmbedded: '@pop'}],
    ],
  },
};

And then in the Language editor, specify:

!
  {
    "foo": "bar",
    "baz": 42,
    "quux": [
      {
        "foo": "bar!",
      }
    ],
    "quux2": [
      {
        "foo": "bar",
      }
    ]
  }
!

If you look carefully, the JSON inside the ! starts out being highlighted correctly, but after the ! in the string literal "bar!", it stops working. It appears the /^\!/ has matched it even though it is not the start of a source code line, which is not what the docs claim should happen.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
alexdimacommented, Feb 10, 2020

For testing changes like that, I typically use one of the generated files like at http://127.0.0.1:8080/monaco-editor/test/playground.generated/extending-language-services-custom-languages.html

and just edit the .html to contain the Monarch definition I want and the content I want and then just reload…

1reaction
bolinfestcommented, Feb 10, 2020

@alexdima I had that working for the establish test pages, but it did not seem to be working for the playground (which I cared about because I didn’t see a good test page for grammars, so I wanted to use monarch.html). Should the fast edit/refresh cycle be working for the playground, too?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Monaco Editor Monarch - Microsoft Open Source
If it starts with a ^ character, the expression only matches at the start of a source line. The $ can be used...
Read more >
Regular expression to stop at first match - regex - Stack Overflow
i.e specify a character class which excludes the starting and ending delimiiters. In the more general case, you can painstakingly construct an expression...
Read more >
Regex Tutorial - Start and End of String or Line Anchors
In a regular expression, the caret matches the concept “start of string”, while the dollar sign matches “end of string”
Read more >
Optimizations in Syntax Highlighting, a Visual Studio Code Story
This is a technique used by many tokenization engines, including TextMate grammars, that allows an editor to retokenize only a small subset of ......
Read more >
Everything you need to know about Regular Expressions
The above pattern matches foo.csv , but does not match bar.txt or my_csv_file . ... They match the beginning and end of a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found