.inc file support

Issue #69 open
Mr Bee created an issue

Hi,

Finding method fails when the method is in an include (.inc) file. And FPC has tons of include files.

Thank you.

~Bee

Comments (5)

  1. Christopher Wosinski repo owner
    • changed status to open

    Please provide more detailed information about the code you are working with. Include files are supported and do work fine in general. But OmniPascal can't parse all FPC related units since FPC has tons of different syntactic language constructs which are not worth to reimplement in OmniPascal by now. This can lead to missing items in code completion and incomplete go-to-definition-support for FPC base classes. Delphi is the only language mode OmniPascal attempts to support entirely.

  2. Mr Bee reporter

    test.pas main program:

    program test;
    
    uses CRT;
    
    var s: string;
    
    begin
      s := ask('Type your name: ');
      writeln('Hello, ',s);
    end.
    

    unit1.pas unit:

    unit unit1;
    
    interface
    
    function ask(q: string): string;
    
    implementation
    
    {$I unit1.inc}
    
    end.
    

    OmniPascal gives warning: "implementation is missing for ask (5,1)".

    unit1.inc include file:

    function ask(q: string): string;
    begin
      write(q);
      readln(Result);
    end;
    

    OmniPascal gives error: "unit name must be unit1 (1,6)".

    Of course FPC (v.3.0 64-bit on Mac) compiles program test just fine without any errors or warnings.

  3. Christopher Wosinski repo owner

    Thanks for the files and sorry for the very late answer. I tested your code against the current master which will be the upcoming version of OmniPascal.

    You show two errors here. The first one can't be reproduced with the current master. Since I've changed a lot of stuff regarding warnings and errors I assume I've fixed it by accident. I don't know how to handle the second error in a good way. When an .inc file is opened in an editor then OmniPascal has no information about the location(s) where it's included. So OmniPascal treats it like a a Pascal source file: And these files never start with function. That's why the parser produces errors in these cases. This won't be fixed soon.

  4. Bee Jay

    Although it's not considered as a good practice, syntactically speaking, a Pascal program is allowed to be started with function or procedure keyword. For example, below code can be compiled just fine, at least using FPC.

    function f: string;
    begin
      result := 'function';
    end;
    
    begin
      writeln(f);
    end.
    

    Also the Pascal program name (after the program keyword) doesn't have to be exactly equal to the actual program file name. It's fine to have a program Fibonacci; while the actual program file name is fibo.pas. 😊

  5. mapes

    Hi, my inc file is like

    {.$DEFINE NOSCRIPT}

    {$IFDEF SUPERADMIN} {$IFDEF MSWINDOWS} {$DEFINE SM_DEBUG} {$ENDIF}

    which is perfectly valid in both Delphi and FPC and have the same (1,6) error

  6. Log in to comment