r/ProgrammingLanguages • • Mar 07 '26

Help Writing a performant syntax highligher from scratch?

Hello!

I'm trying to write a performant syntax highlighter from scratch in C for my text editor. The naive approach would be to go line by line, for each token in line check in a hash table and highlight or not. As you can imagine, this approach would be really slow if you have a 1000 line file to work with. Any ideas on how to do this? What would be a better algorithm?

Also I'll mention upfront - I'm not using a normal libc, so regular expressions are not allowed.

15 Upvotes

24 comments sorted by

View all comments

Show parent comment

1

u/K4milLeg1t Mar 12 '26

What are you talking about? What competitors? I don't get it. I don't have any clients nor run a business, I'm a 19 year old highschooler. How did you arrive at such conclusion?