| 1 |
<!DOCTYPE html> |
| 2 |
<html><head> |
| 3 |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> |
| 4 |
<title>highlight_ocaml.ml</title> |
| 5 |
<meta name="generator" content="KF5::SyntaxHighlighting - Definition (Objective Caml) - Theme (Breeze Dark)"/> |
| 6 |
</head><body style="background-color:#232629;color:#cfcfc2"><pre> |
| 7 |
<span style="color:#7a7c7d;">(* ocaml test file -- a big stew of Objective Caml syntax to use to</span> |
| 8 |
<span style="color:#7a7c7d;"> test Kate's syntax highlighting. This will not run! :-) *)</span> |
| 9 |
|
| 10 |
<span style="color:#7a7c7d;">(* First a little piece of real OCaml that should look right: *)</span> |
| 11 |
|
| 12 |
<span style="color:#27ae60;">#load "basic";;</span> |
| 13 |
<span style="color:#7a7c7d;">(* Return a default value for a BASIC variable given its identifer. *)</span> |
| 14 |
<span style="font-weight:bold;">let</span> default_value (ident : <span style="color:#2980b9;">string</span>) : basic_value = |
| 15 |
<span style="font-weight:bold;">assert</span> (<span style="color:#2980b9;font-style:italic;">String</span>.length ident > <span style="color:#f67400;">0</span>); |
| 16 |
<span style="font-weight:bold;">match</span> ident.[<span style="color:#2980b9;font-style:italic;">String</span>.length ident - <span style="color:#f67400;">1</span>] <span style="font-weight:bold;">with</span> |
| 17 |
| <span style="color:#3daee9;">'$'</span> -> <span style="font-style:italic;">Str</span> <span style="color:#f44f4f;">""</span> |
| 18 |
| <span style="color:#3daee9;">'%'</span> -> <span style="font-style:italic;">Int</span> <span style="color:#f67400;">0</span> |
| 19 |
| <span style="color:#3daee9;">'!'</span> -> <span style="font-style:italic;">Flt</span> <span style="color:#f67400;">0.0</span> |
| 20 |
| _ -> <span style="font-style:italic;">Flt</span> <span style="color:#f67400;">0.0</span> |
| 21 |
;; |
| 22 |
|
| 23 |
<span style="color:#7a7c7d;">(* Directives: *)</span> |
| 24 |
<span style="color:#27ae60;">#load "pa_o";;</span> |
| 25 |
<span style="color:#27ae60;">#load "pa_o";;</span> |
| 26 |
<span style="font-weight:bold;">object</span> # meth ;; <span style="color:#7a7c7d;">(* not a directive - a method call *)</span> |
| 27 |
<span style="font-weight:bold;">object</span> |
| 28 |
# meth ;; <span style="color:#7a7c7d;">(* not a directive - a method call *)</span> |
| 29 |
|
| 30 |
<span style="color:#7a7c7d;">(* OCaml keywords: *)</span> |
| 31 |
<span style="font-weight:bold;">and</span> <span style="font-weight:bold;">as</span> <span style="font-weight:bold;">assert</span> <span style="font-weight:bold;">asr</span> <span style="color:#7a7c7d;">(* etc. there so many... *)</span> |
| 32 |
|
| 33 |
<span style="color:#7a7c7d;">(* Additional OCaml Revised Syntax keywords: *)</span> |
| 34 |
<span style="color:#7a7c7d;">(* These are in a seperate category so they can be coloured to look</span> |
| 35 |
<span style="color:#7a7c7d;"> like identifiers when ordinary OCaml syntax is being used: *)</span> |
| 36 |
declare where value |
| 37 |
|
| 38 |
<span style="color:#7a7c7d;">(* There's no way to reliably highlight all OCaml type expressions,</span> |
| 39 |
<span style="color:#7a7c7d;"> (they can be very complex) so just the built-in type names are highlighted.*)</span> |
| 40 |
<span style="color:#2980b9;">exn</span> <span style="color:#2980b9;">lazy_t</span> format <span style="color:#2980b9;">unit</span> <span style="color:#2980b9;">int</span> <span style="color:#2980b9;">real</span> <span style="color:#2980b9;">char</span> <span style="color:#2980b9;">string</span> <span style="color:#2980b9;">ref</span> <span style="color:#2980b9;">array</span> <span style="color:#2980b9;">bool</span> <span style="color:#2980b9;">list</span> <span style="color:#2980b9;">option</span> |
| 41 |
|
| 42 |
|
| 43 |
<span style="font-weight:bold;">let</span> integers : <span style="color:#2980b9;">int</span> <span style="color:#2980b9;">list</span> = [ |
| 44 |
<span style="color:#f67400;">123456789</span>; <span style="color:#7a7c7d;">(* decimal *)</span> |
| 45 |
<span style="color:#f67400;">-0xabcedf0123456789</span>; <span style="color:#7a7c7d;">(* hexadecimal *)</span> |
| 46 |
<span style="color:#f67400;">0xABCDEF0123456789</span>; <span style="color:#7a7c7d;">(* hexadecimal *)</span> |
| 47 |
<span style="color:#f67400;">-0o1234567</span>; <span style="color:#7a7c7d;">(* octal *)</span> |
| 48 |
<span style="color:#f67400;">0b01001010101010</span>; <span style="color:#7a7c7d;">(* binary *)</span> |
| 49 |
<span style="color:#f67400;">-0Xabcedf0123456789</span>; <span style="color:#7a7c7d;">(* hexadecimal *)</span> |
| 50 |
<span style="color:#f67400;">0XABCDEF0123456789</span>; <span style="color:#7a7c7d;">(* hexadecimal *)</span> |
| 51 |
<span style="color:#f67400;">-0O1234567</span>; <span style="color:#7a7c7d;">(* octal *)</span> |
| 52 |
<span style="color:#f67400;">0B01001010101010</span>; <span style="color:#7a7c7d;">(* binary *)</span> |
| 53 |
<span style="color:#f67400;">-123_456_789</span>; <span style="color:#7a7c7d;">(* Underscores are allowed in numeric constants. *)</span> |
| 54 |
<span style="color:#f67400;">0x_abce_df01_2345_6789</span>; |
| 55 |
<span style="color:#f67400;">-0o12_34_567</span>; |
| 56 |
<span style="color:#f67400;">0b_0100_1010_1010_1101</span>; |
| 57 |
];; |
| 58 |
|
| 59 |
<span style="font-weight:bold;">let</span> floats : <span style="color:#2980b9;">real</span> <span style="color:#2980b9;">list</span> = [ |
| 60 |
<span style="color:#f67400;">12345.6789</span>; |
| 61 |
<span style="color:#f67400;">-1.23456789e4</span>; <span style="color:#7a7c7d;">(* All variations of the exponent form *)</span> |
| 62 |
<span style="color:#f67400;">1.23456789e+4</span>; |
| 63 |
<span style="color:#f67400;">-1.23456789e-4</span>; |
| 64 |
<span style="color:#f67400;">1.23456789E-4</span>; |
| 65 |
<span style="color:#f67400;">-1.23456789E+4</span>; |
| 66 |
<span style="color:#f67400;">12_345.6789</span>; <span style="color:#7a7c7d;">(* Underscores are allowed in numeric constants. *)</span> |
| 67 |
<span style="color:#f67400;">-1.23_456_789e+4</span>; |
| 68 |
<span style="color:#f67400;">12_345.6789</span>; |
| 69 |
];; |
| 70 |
|
| 71 |
<span style="font-weight:bold;">let</span> characters : <span style="color:#2980b9;">char</span> <span style="color:#2980b9;">list</span> = [ |
| 72 |
<span style="color:#3daee9;">'a'</span>; |
| 73 |
<span style="color:#3daee9;">' '</span>; |
| 74 |
<span style="color:#3daee9;">'�'</span>; |
| 75 |
<span style="color:#3daee9;">'\n'</span>; <span style="color:#3daee9;">'\r'</span>; <span style="color:#3daee9;">'\t'</span>; <span style="color:#3daee9;">'\b'</span>; <span style="color:#7a7c7d;">(* Control characters. Only these four: not the full C-language range. *)</span> |
| 76 |
<span style="color:#3daee9;">'\000'</span>; <span style="color:#3daee9;">'\128'</span>; <span style="color:#7a7c7d;">(* Decimal character codes. These are always 3 digits. *)</span> |
| 77 |
<span style="color:#3daee9;">'\x02'</span>; <span style="color:#3daee9;">'\xff'</span>; <span style="color:#3daee9;">'\xFF'</span>; <span style="color:#7a7c7d;">(* Hexadecimal character codes. These are always 3 digits. *)</span> |
| 78 |
<span style="color:#3daee9;">'\\'</span>; <span style="color:#3daee9;">'\''</span>; <span style="color:#3daee9;">'\"'</span>; <span style="color:#3daee9;">'"'</span> <span style="color:#7a7c7d;">(* Quote character escapes. *)</span> |
| 79 |
];; |
| 80 |
|
| 81 |
<span style="color:#7a7c7d;">(* Quotes used to mark constants in parsers should</span> |
| 82 |
<span style="color:#7a7c7d;"> not be confused with character constant quotes.</span> |
| 83 |
<span style="color:#7a7c7d;"> </span><span style="color:#7a7c7d;font-weight:bold;">"Ticks"</span><span style="color:#7a7c7d;"> at the end of identifiers should</span> |
| 84 |
<span style="color:#7a7c7d;"> not be confused with character constant quotes. *)</span> |
| 85 |
<span style="font-weight:bold;">let</span> basic_identifier = |
| 86 |
<span style="font-weight:bold;">parser</span> |
| 87 |
[< '<span style="color:#3daee9;">'F'</span>; '<span style="color:#3daee9;">'N'</span>; name = s >] -> <span style="font-style:italic;">ID</span> (s, <span style="color:#3daee9;">'f'</span>) |
| 88 |
| [< name = s' >] -> <span style="font-style:italic;">ID</span> (s',<span style="color:#3daee9;">'i'</span>) |
| 89 |
;; |
| 90 |
|
| 91 |
<span style="font-weight:bold;">let</span> strings : <span style="color:#2980b9;">string</span> <span style="color:#2980b9;">list</span> = [ |
| 92 |
<span style="color:#f44f4f;">""</span>; <span style="color:#7a7c7d;">(* Empty string *)</span> |
| 93 |
<span style="color:#f44f4f;">"a"</span>; <span style="color:#f44f4f;">" "</span>; <span style="color:#f44f4f;">"�"</span>; <span style="color:#f44f4f;">"ab"</span>; |
| 94 |
<span style="color:#f44f4f;">"A</span><span style="color:#3daee9;">\n</span><span style="color:#f44f4f;">B"</span>; <span style="color:#f44f4f;">"A</span><span style="color:#3daee9;">\r</span><span style="color:#f44f4f;">B"</span>; <span style="color:#f44f4f;">"A</span><span style="color:#3daee9;">\t</span><span style="color:#f44f4f;">B"</span>; <span style="color:#f44f4f;">"A</span><span style="color:#3daee9;">\b</span><span style="color:#f44f4f;">B"</span>; <span style="color:#7a7c7d;">(* Control characters. Only these four: not the full C-language range. *)</span> |
| 95 |
<span style="color:#f44f4f;">"A</span><span style="color:#3daee9;">\000</span><span style="color:#f44f4f;">B"</span>; <span style="color:#f44f4f;">"A</span><span style="color:#3daee9;">\128</span><span style="color:#f44f4f;">B"</span>; <span style="color:#7a7c7d;">(* Decimal character codes. These are always 3 digits. *)</span> |
| 96 |
<span style="color:#f44f4f;">"A</span><span style="color:#3daee9;">\x02</span><span style="color:#f44f4f;">B"</span>; <span style="color:#f44f4f;">"A</span><span style="color:#3daee9;">\xff</span><span style="color:#f44f4f;">B"</span>; <span style="color:#f44f4f;">"A</span><span style="color:#3daee9;">\xFF</span><span style="color:#f44f4f;">B"</span>; <span style="color:#7a7c7d;">(* Hexadecimal character codes. These are always 3 digits. *)</span> |
| 97 |
<span style="color:#f44f4f;">"A</span><span style="color:#3daee9;">\\</span><span style="color:#f44f4f;">B"</span>; <span style="color:#f44f4f;">"A</span><span style="color:#3daee9;">\'</span><span style="color:#f44f4f;">B"</span>; <span style="color:#f44f4f;">"A'B"</span>; <span style="color:#f44f4f;">"A</span><span style="color:#3daee9;">\"</span><span style="color:#f44f4f;">B"</span>; <span style="color:#7a7c7d;">(* Quote character escapes. *)</span> |
| 98 |
<span style="color:#f44f4f;">"A multiline</span><span style="color:#3daee9;">\</span> |
| 99 |
<span style="color:#f44f4f;"> string"</span>; |
| 100 |
]; |
| 101 |
|
| 102 |
<span style="font-weight:bold;">let</span> camlp4_quotations = [ |
| 103 |
<span style="color:#f44f4f;"><<A Camlp4 source code quotation.>></span> ; |
| 104 |
<span style="color:#f44f4f;"><:QUOTE<A labelled Camlp4 source code quotation.>></span> ; |
| 105 |
<:<span style="font-style:italic;">QU</span>�<span style="font-style:italic;">T</span>�<<span style="font-style:italic;">A</span> labelled <span style="font-style:italic;">Camlp4</span> source code quotation. (<span style="font-style:italic;">Latin</span><span style="color:#f67400;">-1</span> identifier.)>> ; |
| 106 |
<span style="color:#f44f4f;"><< A quote with an escape: </span><span style="color:#3daee9;">\>></span><span style="color:#f44f4f;"> (end-quote symbol) >></span> ; |
| 107 |
<span style="color:#f44f4f;"><< A quote with an escape: </span><span style="color:#3daee9;">\<<</span><span style="color:#f44f4f;"> (plain start quote-symbol) >></span> ; |
| 108 |
<span style="color:#f44f4f;"><< A quote with an escape: \<:Trouv�< (labelled start-quote symbol) >></span> ; |
| 109 |
];; |
| 110 |
|
| 111 |
<span style="color:#7a7c7d;">(* end *)</span> |
| 112 |
</pre></body></html> |