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