Results 1 to 9 of 9

Thread: syntax...

  1. #1

    Thread Starter
    Addicted Member Virtual24's Avatar
    Join Date
    May 2001
    Posts
    228

    Arrow syntax...

    I am playing around with making a java editor with syntax highlighting. I got everything to work ok however, when the file gets very large, there is a major speed issue. Anyone have any ideas on how to optimize this? ( the current syntax highlighter is re-highlighting the entire file every time text is inserted or removed. )
    To protect time is to protect everything...

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Maybe a way to split the file in parts that can be independently reparsed. Then only reparse the part where the eit occurred.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    How is the highlighting mechanism implemented? Do you have a file filled with predefined keywords that are matched to what the user types?

  4. #4

    Thread Starter
    Addicted Member Virtual24's Avatar
    Join Date
    May 2001
    Posts
    228
    Its an interface, actually, with all the java keywords, and operators, created as static final strings. As the user types int the JTextPane, the text is inserted, and then the entire text is searched for occurences of the keywords, operators, comments, quotations, and so on... The only problem is that this process gets too slow once the file reaches larger sizes ( more than a couple of pages ). I thought of trying to make a separate thread to do the highlighting, but for some reason, it even slower then...
    To protect time is to protect everything...

  5. #5
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Are you searcing the whole text all the time? Or just the word that was just written? It can't take that much time to check the last word that was typed....

  6. #6
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    I don't see why it would be necessary to check the whole file everytime a keyword is entered.

    Why don't you try opening the file for RandomAccess and position the file pointer to where a word is being typed or retyped?

  7. #7
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403
    The other suggestions are good ones. Color only the current word, or my favorite, only the visible area.
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

  8. #8

    Thread Starter
    Addicted Member Virtual24's Avatar
    Join Date
    May 2001
    Posts
    228
    Granted, highlighting only the line affected by the change would be the ideal thing. However, what about quotes and multi-line comments? Those two parts of highlighting affect more than one line, and therefore you wouldn't be able to only check the line of the change. I would love to incorporate a system to only check the visible text, but, I can't figure out how to do that. If you know, please share...
    To protect time is to protect everything...

  9. #9
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    If you go by the swing.text model, your document is already divided into areas of coloring: string literals, comments, keywords etc. A whole tree.
    Any change would just need to check the current area for changes, if it ends it etc.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width