Skip to content

Add Position on line in error messages #18

Description

@electric-socket

Knowing exactly where on a line an error was discovered is extra helpful, and I recommend adding it. I'll even tell how. These changes are given in reverse order, bottom to top so a reference to a line number will remain the same after a change was made.

In scanner.pas, six changes.

  1. Insert the Following procedure of 4 lines starting at line 697:
function ScannerPos: Integer;
begin
      Result := ScannerState.Position;
end; 
  1. After line 186 insert one line:
    inc(ScannerState.Position);

  2. Replace line 179
    if ScannerState.ch = #10 then Inc(ScannerState.Line);
    With the following five lines:

if ScannerState.ch = #10 then   // End of line found         '
  begin 
     Inc(ScannerState.Line);  
     Scannerstate.Position  := 0; 
  end;   
  1. After line 98 insert one line:
    Position := 0;

  2. After line 46 insert one line:
    Position,

  3. After line 29 insert one line:
    function ScannerPos: Integer;

In file XDPW._PAS two changes:

  1. Line 72, replace one line:
    Notice(ScannerFileName + ' (' + IntToStr(ScannerLine) + ') Error: ' + Msg)
    with the following split line:
  Notice(ScannerFileName + ' (' + IntToStr(ScannerLine) + 
              ':' + IntToStr(ScannerPos)  + ') Error: ' + Msg)  
  1. Line 61 replace one line:
    Notice(ScannerFileName + ' (' + IntToStr(ScannerLine) + ') Warning: ' + Msg)
    with the following split line:
  Notice(ScannerFileName + ' (' + IntToStr(ScannerLine) + ' 
             ':' + IntToStr(ScannerPos) +  ') Warning: ' + Msg) 
  1. Optional Change to Common.Pas, change line 14 from:
    VERSION = '0.12';
    to
    VERSION = '0.13';

To confirm the change for anyone using it. I've compiled it and tried it and it's sweet, if you feed it a file with an error it now shows both line number and position on the line where the error was detected. I think it would be useful and I recommend its inclusion.

Paul.

Paul Robinson paul@paul-robinson.us
"The lessons of history teach us - if they teach us anything - that no one learns the lessons that history teaches us."

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions