I am writing an automatic parenthesis completion function for a text editor, my current approach is to call the parenthesis matching procedure (suppose it is correct and efficient) on each new line, where the last character entered is an open bracket, starting with the new line (with this last printed open bracket at the top of the stack) until either stack is empty or it reaches the end of the source without finding a suitable skog.
However, this method seems slow for large source files (> 1 MB), especially when a new line is added in the first half of the original lines (new line in the first line = worst case = all text is scanned). Some IDEs have this feature and can quickly deal with it, so they should use a different approach. So, I would like to know which algorithm they are using or some other approach is better than mine.
source
share