SYSTEM WARNING: Creating default object from empty value

SYSTEM WARNING: Creating default object from empty value

GeSHi Bug Tracker - GeSHi
Viewing Issue Advanced Details
85 core feature N/A 06-06-06 05:26 09-13-06 12:56
BenBE  
nigel  
low  
assigned  
open  
none    
none  
0000085: Preview and Postview Functions for Code Parsers
In some (rare) cases it might be useful to have the opportunity for the CodeParser to "preview" the source it has to highlight.

This should be realized by letting the CP preview the source it's going to highlight in an order simular to this:
--- Example source ---

function Test(argname: argtype): Foo;
begin
    asm
        DEC DWIRD PTR [argname]
        CMP DWORD PTR [argname], $00000000
        JZ @@Finish
        CALL Test
@@Finish:
    end;

    Result := 0;

    asm
        DEC DWIRD PTR [argname]
        CMP DWORD PTR [argname], $00000000
        JZ @@Finish
        CALL Test
@@Finish:
    end;
end;
--- Example Call Order ---

CP_preview(delphi/delphi) //Introduce the top-most context
CP_parsedata(delphi/delphi) //Process all data up to the first subcontext
CP_preview(delphi/asm) //Introduce the first ASM Block
CP_parsedata(delphi/asm) //Process the first ASM Block
CP_postview(delphi/asm) //Remove the context data of the ASM block
CP_parsedata(delphi/delphi) //Process all data up to the second subcontext
CP_preview(delphi/asm) //Introduce the second ASM Block
CP_parsedata(delphi/asm) //Process the second ASM Block
CP_postview(delphi/asm) //Remove the context data of the ASM block
CP_postview(delphi/delphi) //Remove the context data of the topmost block
--- Example End ---

Within the iterator subcontexts are returned unparsed, i.e. if there was an ASM block or another context that needs subdividing, the preview function would see it as a single string.

This feature then could easily be used to prepare highlighting of source, e.g. to detect variable names or the exact context of tokens that were contextually ambiguous otherwise (cf. the example below).
Any source were the use of a variable preceeds its declaration:

e.g. this (common) example in the header files for Delphi (and CPP)
---

{line 190}
type
  LONGLONG = Int64;
  {$EXTERNALSYM LONGLONG}
  PSID = Pointer;
  {$EXTERNALSYM PSID}
  PLargeInteger = ^TLargeInteger;
  _LARGE_INTEGER = record
    case Integer of
    0: (
      LowPart: DWORD;
      HighPart: Longint);
    1: (
      QuadPart: LONGLONG);
  end;
  {$EXTERNALSYM _LARGE_INTEGER}
  {$NODEFINE TLargeInteger}
  TLargeInteger = Int64;
  LARGE_INTEGER = _LARGE_INTEGER;
  {$EXTERNALSYM LARGE_INTEGER}

  ULARGE_INTEGER = record
    case Integer of
    0: (
      LowPart: DWORD;
      HighPart: DWORD);
    1: (
      QuadPart: LONGLONG);
  end;
  {$EXTERNALSYM ULARGE_INTEGER}
  PULargeInteger = ^TULargeInteger;
  TULargeInteger = ULARGE_INTEGER;
---
This feature would require the token iterator of 0000084 or at least could be based on that feature.

An example where "look-behind highlighting" along wont do is the following Delphi source:

---

type TSomeProcType = Procedure;
//...
const Ptr: TSomeProcType = @Foo;
//...
procedure Foo;
---

with //... being loads of source. If this source was highlighted using simple look-behind highlighting (as the current CP could do) you would have to store nearly all information of the source snippet on the highlighting stack before you knew that Foo in the const declaration was a procedure name instead of a simple variable. TSomeProcType is a type declaration, not a procedure name and Ptr a variable name (Procedure reference, but no procedure!).

If you could skim over the source before going to highlight it, the CP could extract such information beforehand and handle them correctly.
related to 0000081closed nigel Source preprocessing may come in handy for some highlighting difficulties 
parent of 0000084assigned nigel Provide access to tokens through an iterator 
child of 0000033assigned BenBE Highlight Labels after certain instructions 
Not all the children of this issue are yet resolved or closed.

There are no notes attached to this issue.