Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5944065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:29:05+00:00 2026-05-22T16:29:05+00:00

I am trying to understand how I should implement live syntax highlight when processing

  • 0

I am trying to understand how I should implement live syntax highlight when processing a very big string. I’m quite confused. This is what I know:

(Supposing I have the function parsedString parseString(rawString))

  1. Call parseString(entireText) and replace the current string with the returned parsed (and styled, etc.) string on every text change. This seems a bad approach when handling big data.

  2. Someone suggested to analyze the edited range, and replace the current raw edited string with the parsed string parseString(editedRange).

Method (1) is clear enough. What I cannot understand is (2). When typing, for each character added to the string, the notification is fired, and a single character is being parsed (and returned as it is).

For example, if I want red selectors when parsing a .css file, how I can understand when there’s a completed selector followed by a { that should be colored? I suppose there is some way to delay the parsing until there is a match. How do you implement this?

I’m not looking for a working application. A good explanation would be useful as well.

Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T16:29:05+00:00Added an answer on May 22, 2026 at 4:29 pm

    To re-parse incremental changes, you’ll need a lower-level API to your parser.

    A parser has a state that changes as it processes the input. For example, first the parser might be skipping spaces, now it might be reading a number, later it might be building an abstract syntax tree for an expression. If you could take a snapshot of all that parser state information at milestone points in the input, then you could reparse an incremental change by starting at the last milestone before the change (and possibly stopping earlier if the state is identical at a milestone beyond that change).

    For simple syntax highlighting, like many programmers editors do, this is the approach. Syntax highlighting requires little more than tokenization, so there isn’t much state to capture. And many programming languages have plenty of opportunities for milestones, e.g., at the beginning of a new line. In those cases, you might not even need to actually save the parser state, as you might know that it’s always the same at the beginning of a line.

    So you need an API like:

    parsedString parseIncrementally(parserState, rawString);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to better understand when I should and should not use Iterators.
Trying to understand Ruby a bit better, I ran into this code surfing the
I trying to understand if a isset is required during form processing when i
I'm currently trying to understand how to implement a 2-dimensional array of struct in
I m trying to understand Interfaces so that I can implement them in my
I am trying to understand how to implement MVC in winforms so I have
I'm trying to understand lists in prolog when I stumbpled over this problem: there's
I'm trying to implement a findall predicate in Prolog (yes I know it's built
I'm trying to implement block sorting. This is from the Burrows Wheeler paper .
I'm trying to understand how to implement replaceable components, or a service provider interface,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.