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