[Geany-Devel] Interested making a patch to add QML support

Matthew Brush mbrush at xxxxx
Fri Sep 20 20:18:18 UTC 2013

On 13-09-20 12:00 PM, Tory Gaurnier wrote:
> [...]
> Well, it's actually proving more difficult then I thought to get the ID,
> what I was planning on doing is when my function finds a valid Object,
> it would store the name and continue to loop through the lines until it
> either finds an ID or '}' (unless of course another '{' was found, for
> instance if for some reason someone put a function before an ID
> declaration in an Item/Component, I was prepared for this stuff ;] ),
> and in the mean time while it was scanning it would still be on the
> lookout for Javascript functions and add them when it sees them, then
> when it was ready (found ID or end of Object), it would create the tag,
> however, I reallized that it's probably getting the line # to point at
> from the current line number in File when you actually create the tag,
> so I traced down the functions, and it appears to be the case, so with
> that method it would most definitely not be pointing at the correct line
> for the tag.

I've never written a CTags parser, but writing other parsers, a common 
technique is to use a stack data structure and each time you encounter a 
`{`, you push a new "scope" onto the stack and each time you encounter a 
`}`, you pop the top "scope" off of the stack. This way when you 
encounter an `id:` token, you go (in pseudo-code):

     if (iHaveFoundAnId)

And you'll always be putting the id on the right thing. It also works 
good for scoping sub-objects or whatever else too:

     if (iHaveFoundASubObjectDecl) {
         // Add theObject to the current scope

I'm not sure this is at all relevant in the context of a CTags parser, 
but maybe it'll give some ideas.

Matthew Brush

More information about the Devel mailing list