mirror of
				https://github.com/KevinMidboe/linguist.git
				synced 2025-10-29 17:50:22 +00:00 
			
		
		
		
	Add the Mercury language to linguist
lib/linguist/languages.yml:
    Add the declaration for the language.
samples/Mercury:
    Add samples for the classifier as Mercury shares it's filename extension
    with several other languages.
			
			
This commit is contained in:
		| @@ -846,6 +846,14 @@ Max: | ||||
|   - .maxhelp | ||||
|   - .maxpat | ||||
|  | ||||
| Mercury: | ||||
|   type: programming | ||||
|   # This is the background colour on the web page. | ||||
|   color: "#abcdef" | ||||
|   primary_extension: .m | ||||
|   # Mercury's syntax is not prolog syntax, but they do share the lexer | ||||
|   lexer: Prolog | ||||
|  | ||||
| MiniD: # Legacy | ||||
|   searchable: false | ||||
|   primary_extension: .minid # Dummy extension | ||||
|   | ||||
							
								
								
									
										4843
									
								
								samples/Mercury/code_info.m
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4843
									
								
								samples/Mercury/code_info.m
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										14
									
								
								samples/Mercury/hello.m
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								samples/Mercury/hello.m
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,14 @@ | ||||
| % "Hello World" in Mercury. | ||||
|  | ||||
| % This source file is hereby placed in the public domain.  -fjh (the author). | ||||
|  | ||||
| :- module hello. | ||||
| :- interface. | ||||
| :- import_module io. | ||||
|  | ||||
| :- pred main(io::di, io::uo) is det. | ||||
|  | ||||
| :- implementation. | ||||
|  | ||||
| main(!IO) :- | ||||
| 	io.write_string("Hello, world\n", !IO). | ||||
							
								
								
									
										5884
									
								
								samples/Mercury/options.m
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5884
									
								
								samples/Mercury/options.m
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										4637
									
								
								samples/Mercury/polymorphism.m
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4637
									
								
								samples/Mercury/polymorphism.m
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										58
									
								
								samples/Mercury/rot13_concise.m
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								samples/Mercury/rot13_concise.m
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,58 @@ | ||||
| % File: rot13_concise.m | ||||
| % Main authors: Warwick Harvey <wharvey@cs.monash.edu.au> | ||||
| %               Fergus Henderson <fjh@cs.mu.oz.au> | ||||
| % | ||||
| % rot13_concise: | ||||
| % | ||||
| % Program to read its input, apply the rot13 algorithm, and write it out | ||||
| % again. | ||||
| % | ||||
| % This version is more concise (but less efficient) than its companion, | ||||
| % rot13_verbose. | ||||
| % | ||||
| % Key features: | ||||
| % - is independent of character set (e.g. ASCII, EBCDIC) | ||||
| % - has proper error handling | ||||
| % | ||||
|  | ||||
| :- module rot13_concise. | ||||
|  | ||||
| :- interface. | ||||
| :- import_module io. | ||||
|  | ||||
| :- pred main(state, state). | ||||
| :- mode main(di, uo) is det. | ||||
|  | ||||
| :- implementation. | ||||
| :- import_module char, int, string. | ||||
|  | ||||
| % The length of `alphabet' should be a multiple of `cycle'. | ||||
| alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ". | ||||
| cycle = 26. | ||||
|  | ||||
| rot_n(N, Char) = RotChar :- | ||||
| 	char_to_string(Char, CharString), | ||||
| 	( if sub_string_search(alphabet, CharString, Index) then | ||||
| 		NewIndex = (Index + N) mod cycle + cycle * (Index // cycle), | ||||
| 		index_det(alphabet, NewIndex, RotChar) | ||||
| 	else | ||||
| 		RotChar = Char | ||||
| 	). | ||||
|  | ||||
| rot13(Char) = rot_n(13, Char). | ||||
|  | ||||
| main --> | ||||
| 	read_char(Res), | ||||
| 	( { Res = ok(Char) }, | ||||
| 		print(rot13(Char)), | ||||
| 		main | ||||
| 	; { Res = eof } | ||||
| 	; { Res = error(ErrorCode) }, | ||||
| 		{ error_message(ErrorCode, ErrorMessage) }, | ||||
| 		stderr_stream(StdErr), | ||||
| 		print(StdErr, "rot13: error reading input: "), | ||||
| 		print(StdErr, ErrorMessage), | ||||
| 		nl(StdErr) | ||||
| 	). | ||||
|  | ||||
|  | ||||
							
								
								
									
										50
									
								
								samples/Mercury/rot13_ralph.m
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								samples/Mercury/rot13_ralph.m
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,50 @@ | ||||
| % ---------------------------------------------------------------------------- % | ||||
| % rot13_ralph.m | ||||
| % Copyright (C) 2001 Ralph Becket <rbeck@microsoft.com> | ||||
| % Tue Jan  9 18:10:44 GMT 2001 | ||||
| % vim: ts=4 sw=4 et tw=0 wm=0 ff=unix ft=mercury | ||||
| % | ||||
| % Short and sweet. | ||||
| % | ||||
| % ---------------------------------------------------------------------------- % | ||||
|  | ||||
| :- module rot13_ralph. | ||||
|  | ||||
| :- interface. | ||||
|  | ||||
| :- import_module io. | ||||
|  | ||||
|  | ||||
|  | ||||
| :- pred main(io__state::di, io__state::uo) is det. | ||||
|  | ||||
| % ---------------------------------------------------------------------------- % | ||||
| % ---------------------------------------------------------------------------- % | ||||
|  | ||||
| :- implementation. | ||||
|  | ||||
| :- import_module int, require. | ||||
|  | ||||
| % ---------------------------------------------------------------------------- % | ||||
|  | ||||
| main --> | ||||
|     io__read_byte(Result), | ||||
|     (   { Result = ok(X) },         io__write_byte(rot13(X)), main | ||||
|     ;   { Result = eof } | ||||
|     ;   { Result = error(ErrNo)},   { error(io__error_message(ErrNo)) } | ||||
|     ). | ||||
|  | ||||
| % ---------------------------------------------------------------------------- % | ||||
|  | ||||
| :- func rot13(int) = int. | ||||
|  | ||||
| rot13(X) = | ||||
|     (      if 0'a =< X, X =< 0'z then Rot13(X, 0'a) | ||||
|       else if 0'A =< X, X =< 0'Z then Rot13(X, 0'A) | ||||
|       else X | ||||
|     ) | ||||
|  :- | ||||
|     Rot13 = ( func(C, A) = ((13 + C - A) `rem` 26) + A ). | ||||
|  | ||||
| % ---------------------------------------------------------------------------- % | ||||
| % ---------------------------------------------------------------------------- % | ||||
							
								
								
									
										116
									
								
								samples/Mercury/rot13_verbose.m
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										116
									
								
								samples/Mercury/rot13_verbose.m
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,116 @@ | ||||
| % File: rot13_verbose.m | ||||
| % Main author: Warwick Harvey <wharvey@cs.monash.edu.au> | ||||
| % Additional input: Fergus Henderson <fjh@cs.mu.oz.au> | ||||
|  | ||||
| % | ||||
| % rot13_verbose: | ||||
| % | ||||
| % Program to read its input, apply the rot13 algorithm, and write it out | ||||
| % again. | ||||
| % | ||||
| % This version is more verbose (and more efficient) than its companion, | ||||
| % rot13_concise. | ||||
| % | ||||
| % Key features: | ||||
| % - is independent of character set (e.g. ASCII, EBCDIC) | ||||
| % - has proper error handling | ||||
| % - reasonably efficient (uses a table to do the rotation) | ||||
| % | ||||
|  | ||||
| :- module rot13_verbose. | ||||
|  | ||||
| :- interface. | ||||
| :- import_module io. | ||||
|  | ||||
| :- pred main(io__state, io__state). | ||||
| :- mode main(di, uo) is det. | ||||
|  | ||||
| :- implementation. | ||||
| :- import_module char, int, require. | ||||
|  | ||||
| 	% rot13a/2 | ||||
| 	% A table to map the alphabetic characters to their rot13 equivalents | ||||
| 	% (fails if the input is not alphabetic). | ||||
| :- pred rot13a(char, char). | ||||
| :- mode rot13a(in, out) is semidet. | ||||
|  | ||||
| rot13a('a', 'n'). | ||||
| rot13a('b', 'o'). | ||||
| rot13a('c', 'p'). | ||||
| rot13a('d', 'q'). | ||||
| rot13a('e', 'r'). | ||||
| rot13a('f', 's'). | ||||
| rot13a('g', 't'). | ||||
| rot13a('h', 'u'). | ||||
| rot13a('i', 'v'). | ||||
| rot13a('j', 'w'). | ||||
| rot13a('k', 'x'). | ||||
| rot13a('l', 'y'). | ||||
| rot13a('m', 'z'). | ||||
| rot13a('n', 'a'). | ||||
| rot13a('o', 'b'). | ||||
| rot13a('p', 'c'). | ||||
| rot13a('q', 'd'). | ||||
| rot13a('r', 'e'). | ||||
| rot13a('s', 'f'). | ||||
| rot13a('t', 'g'). | ||||
| rot13a('u', 'h'). | ||||
| rot13a('v', 'i'). | ||||
| rot13a('w', 'j'). | ||||
| rot13a('x', 'k'). | ||||
| rot13a('y', 'l'). | ||||
| rot13a('z', 'm'). | ||||
| rot13a('A', 'N'). | ||||
| rot13a('B', 'O'). | ||||
| rot13a('C', 'P'). | ||||
| rot13a('D', 'Q'). | ||||
| rot13a('E', 'R'). | ||||
| rot13a('F', 'S'). | ||||
| rot13a('G', 'T'). | ||||
| rot13a('H', 'U'). | ||||
| rot13a('I', 'V'). | ||||
| rot13a('J', 'W'). | ||||
| rot13a('K', 'X'). | ||||
| rot13a('L', 'Y'). | ||||
| rot13a('M', 'Z'). | ||||
| rot13a('N', 'A'). | ||||
| rot13a('O', 'B'). | ||||
| rot13a('P', 'C'). | ||||
| rot13a('Q', 'D'). | ||||
| rot13a('R', 'E'). | ||||
| rot13a('S', 'F'). | ||||
| rot13a('T', 'G'). | ||||
| rot13a('U', 'H'). | ||||
| rot13a('V', 'I'). | ||||
| rot13a('W', 'J'). | ||||
| rot13a('X', 'K'). | ||||
| rot13a('Y', 'L'). | ||||
| rot13a('Z', 'M'). | ||||
|  | ||||
| 	% rot13/2 | ||||
| 	% Applies the rot13 algorithm to a character. | ||||
| :- pred rot13(char, char). | ||||
| :- mode rot13(in, out) is det. | ||||
|  | ||||
| rot13(Char, RotChar) :- | ||||
| 	( if rot13a(Char, TmpChar) then | ||||
| 		RotChar = TmpChar | ||||
| 	else | ||||
| 		RotChar = Char | ||||
| 	). | ||||
|  | ||||
| main --> | ||||
| 	io__read_char(Res), | ||||
| 	( { Res = ok(Char) }, | ||||
| 		{ rot13(Char, RotChar) }, | ||||
| 		io__write_char(RotChar), | ||||
| 		main | ||||
| 	; { Res = eof } | ||||
| 	; { Res = error(ErrorCode) }, | ||||
| 		{ io__error_message(ErrorCode, ErrorMessage) }, | ||||
| 		io__stderr_stream(StdErr), | ||||
| 		io__write_string(StdErr, "rot13: error reading input: "), | ||||
| 		io__write_string(StdErr, ErrorMessage), | ||||
| 		io__nl(StdErr) | ||||
| 	). | ||||
|  | ||||
		Reference in New Issue
	
	Block a user