简体   繁体   中英

Loading a text file in to memory and analyze its contents

For educational purposes, I would like to build an IDE for PHP coding.

I made a form app and added OpenFileDialog ..(my c# knowledge was useful, because it was easy ... even though without intelisense!)

Loading a file and reading lines from it is basically the same in every language (even PERL).

But my goal is to write homemade intelisense. I don't need info on the richtextBox and the events it generates, endline, EOF, etc, etc.

The problem I have is, how do I handle the data? line for line?

  • a struct for each line of text file?
  • looping all the structs in a linked list? ...
  • while updating the richtextBox?
  • searching for opening and closing brackets, variables, etc, etc

I think Microsoft stores a SQL type of database in the app project folders. But how would you keep track of the variables and simulate them in some sort of form?

I would like to know how to handle this efficiently on dynamic text.

Having never thought this through before, it sounds like an interesting challenge.

Personally, I think you'll have to implement a lexical scanner, tokenizing the entire source file into a source tree, with each token also having information about it mapping the token to a line/character inside of the source file.

From there you can see how far you want to go with it - when someone hovers over a token, it can use the context of the code around it to be more intelligent about the "intellisense" you are providing.

Hovering over something would map back to your source tree, which (as you are building it) you would load up with any information that you want to display.

Maybe it's overkill, but it sounds like a fun project.

This sounds to be related to this question: https://softwareengineering.stackexchange.com/questions/189471/how-do-ide-s-provide-auto-completion-instant-error-checking-and-debugging

The accepted answer of that question recommends this link which I found very interesting:

http://msdn.microsoft.com/en-us/magazine/cc163781.aspx

In a nutshell, most IDEs generate the parse tree from the code and that is what they stores and manage.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM