Search code examples
prologletters

SWI-prolog not able to handle swedish letters


I have a file that is called syntax.pl. This is an excerpt from it:

% ---------- %


allowed_char( C ) :-
  number( C ),
  ( C >= 97, C =< 122 ) ;
  ( C >= 65, C =< 90 ) ;
  ( C >= 48, C =< 57 ) ;
  C = 39 ;
  C = 40 ;
  C = 41 ;
  C = 44 ;
  C = 196 ;
  C = 197 ;
  C = 214 ;
  C = 228 ;
  C = 229 ;
  C = 246 ;
  % Wide characters
  C = 195 ;
  C = 165 ; % å
  C = 164 ; % ä
  C = 182 ; % ö
  C = 133 ; % Å
  C = 132 ; % Ä
  C = 150.  % Ö

I run SWI-prolog version 7.2.3. I run the following command:

?- [syntax].

I get the following error message:

ERROR: /Users/sahandz/.Trash/syntax/syntax.pl:185:97: Syntax error: Unexpected end of file

My suspection is that this is because of the swedish letters in the end of the excerpt that I posted. I believe so because line 185 is the first line where a Swedish letter appears (see the error message).

What can I do about this?

EDIT:

Upon removing the Swedish letters (they were after all in a comment) I still get the same error.


Solution

  • Two solutions (that don't exclude each other):

    1. Save the file with UTF-8 encoding and a BOM.

    2. Use an encoding/1 directive as the first term, in the first line, of your Prolog files. In this case, you still need to save the file with UTF-8 encoding but a BOM will not be necessary:

      :- endcoding(utf8).