[m-rev.] for review: allow windows files to be compiled on unix
Ian MacLarty
maclarty at cs.mu.OZ.AU
Wed Sep 7 17:15:04 AEST 2005
For review by anyone.
Estimated hours taken: 1
Branches: main and 0.12
Allow Mercury programs written with a Windows application (like edit)
to be compiled on a unix system.
Previously Mercury gave "illegal character" errors.
library/lexer.m:
Replace checks for space, tab or newline characters with a call
to char.is_whitespace. char.is_whitespace also checks for
carriage returns and linefeeds.
Allow a carriage return character to appear before a newline
when checking for `\' at the end of a line.
tests/hard_coded/Mmakefile:
tests/hard_coded/dos.exp:
tests/hard_coded/dos.m:
Test that a Windows format source file compiles.
Index: library/lexer.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/lexer.m,v
retrieving revision 1.41
diff -u -r1.41 lexer.m
--- library/lexer.m 16 Jun 2005 04:08:02 -0000 1.41
+++ library/lexer.m 7 Sep 2005 05:37:42 -0000
@@ -317,7 +317,7 @@
Token = eof
;
Result = ok(Char),
- ( ( Char = ' ' ; Char = '\t' ; Char = '\n' ) ->
+ ( char__is_whitespace(Char) ->
lexer__get_token_2(Token, Context, !IO)
; ( char__is_upper(Char) ; Char = '_' ) ->
lexer__get_context(Context, !IO),
@@ -368,7 +368,7 @@
lexer__string_get_token(String, Len, Token, Context, !Posn) :-
Posn0 = !.Posn,
( lexer__string_read_char(String, Len, Char, !Posn) ->
- ( ( Char = ' ' ; Char = '\t' ; Char = '\n' ) ->
+ ( char__is_whitespace(Char) ->
lexer__string_get_token_2(String, Len, Token, Context,
!Posn)
; ( char__is_upper(Char) ; Char = '_' ) ->
@@ -441,7 +441,7 @@
Token = eof
;
Result = ok(Char),
- ( ( Char = ' ' ; Char = '\t' ; Char = '\n' ) ->
+ ( char__is_whitespace(Char) ->
lexer__get_token_2(Token, Context, !IO)
; ( char__is_upper(Char) ; Char = '_' ) ->
lexer__get_context(Context, !IO),
@@ -488,7 +488,7 @@
lexer__string_get_token_2(String, Len, Token, Context, !Posn) :-
Posn0 = !.Posn,
( lexer__string_read_char(String, Len, Char, !Posn) ->
- ( ( Char = ' ' ; Char = '\t' ; Char = '\n' ) ->
+ ( char__is_whitespace(Char) ->
lexer__string_get_token_2(String, Len, Token, Context,
!Posn)
; ( char__is_upper(Char) ; Char = '_' ) ->
@@ -619,10 +619,10 @@
:- pred lexer__whitespace_after_dot(char::in) is semidet.
-lexer__whitespace_after_dot(' ').
-lexer__whitespace_after_dot('\t').
-lexer__whitespace_after_dot('\n').
-lexer__whitespace_after_dot('%').
+lexer__whitespace_after_dot(Char) :-
+ ( char__is_whitespace(Char)
+ ; Char = '%'
+ ).
%-----------------------------------------------------------------------------%
@@ -921,6 +921,11 @@
Result = ok(Char),
( Char = '\n' ->
lexer__get_quoted_name(QuoteChar, Chars, Token, !IO)
+ ; Char = '\r' ->
+ % Files created on Windows may have an extra
+ % return character.
+ lexer__get_quoted_name_escape(QuoteChar, Chars, Token,
+ !IO)
; lexer__escape_char(Char, EscapedChar) ->
Chars1 = [EscapedChar | Chars],
lexer__get_quoted_name(QuoteChar, Chars1, Token, !IO)
@@ -944,6 +949,11 @@
( Char = '\n' ->
lexer__string_get_quoted_name(String, Len, QuoteChar,
Chars, Posn0, Token, Context, !Posn)
+ ; Char = '\r' ->
+ % Files created on Windows may have an extra
+ % return character.
+ lexer__string_get_quoted_name_escape(String, Len,
+ QuoteChar, Chars, Posn0, Token, Context, !Posn)
; lexer__escape_char(Char, EscapedChar) ->
Chars1 = [EscapedChar | Chars],
lexer__string_get_quoted_name(String, Len, QuoteChar,
Index: tests/hard_coded/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/Mmakefile,v
retrieving revision 1.265
diff -u -r1.265 Mmakefile
--- tests/hard_coded/Mmakefile 5 Sep 2005 02:29:58 -0000 1.265
+++ tests/hard_coded/Mmakefile 7 Sep 2005 04:45:37 -0000
@@ -44,6 +44,7 @@
deforest_cc_bug \
det_in_semidet_cntxt \
division_test \
+ dos \
dot_separator \
dst_test \
dupcall_impurity \
Index: tests/hard_coded/dos.exp
===================================================================
RCS file: tests/hard_coded/dos.exp
diff -N tests/hard_coded/dos.exp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/dos.exp 7 Sep 2005 05:51:31 -0000
@@ -0,0 +1,4 @@
+multi
+ line string
+should be all on one line
+'escaped functor'
\ No newline at end of file
Index: tests/hard_coded/dos.m
===================================================================
RCS file: tests/hard_coded/dos.m
diff -N tests/hard_coded/dos.m
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/dos.m 7 Sep 2005 06:03:55 -0000
@@ -0,0 +1,23 @@
+% Test compilation of a file with MS DOS style newlines.
+%
+
+:- module dos.
+
+:- interface.
+
+:- import_module io.
+
+:- pred main(io::di, io::uo) is det. % A comment
+
+:- implementation.
+
+:- type t --->
+ 'escaped functor'.
+
+main(!IO) :-
+ io.write_string("multi
+ line string\n", !IO),
+ io.write_string("should be all on one \
+line\n", !IO),
+ io.write('escaped fu\
+nctor', !IO).
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list