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 Light)"/>
</head><body style="background-color:#ffffff;color:#1f1c1b"><pre>
<span style="color:#898887">(* ocaml test file -- a big stew of Objective Caml syntax to use to</span>
<span style="color:#898887"> test Kate's syntax highlighting. This will not run! :-) *)</span>
<span style="color:#898887">(* First a little piece of real OCaml that should look right: *)</span>
<span style="color:#006e28">#load "basic";;</span>
<span style="color:#898887">(* 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:#0057ae">string</span>) : basic_value =
<span style="font-weight:bold">assert</span> (<span style="color:#0057ae;font-style:italic">String</span>.length ident > <span style="color:#b08000">0</span>);
<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>
| <span style="color:#924c9d">'$'</span> -> <span style="font-style:italic">Str</span> <span style="color:#bf0303">""</span>
| <span style="color:#924c9d">'%'</span> -> <span style="color:#0057ae;font-style:italic">Int</span> <span style="color:#b08000">0</span>
| <span style="color:#924c9d">'!'</span> -> <span style="font-style:italic">Flt</span> <span style="color:#b08000">0.0</span>
| _ -> <span style="font-style:italic">Flt</span> <span style="color:#b08000">0.0</span>
;;
<span style="color:#898887">(* Directives: *)</span>
<span style="color:#006e28">#load "pa_o";;</span>
<span style="color:#006e28">#load "pa_o";;</span>
<span style="font-weight:bold">object</span> # meth ;; <span style="color:#898887">(* not a directive - a method call *)</span>
<span style="font-weight:bold">object</span>
# meth ;; <span style="color:#898887">(* not a directive - a method call *)</span>
<span style="color:#898887">(* 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:#898887">(* etc. there so many... *)</span>
<span style="color:#898887">(* Additional OCaml Revised Syntax keywords: *)</span>
<span style="color:#898887">(* These are in a seperate category so they can be coloured to look</span>
<span style="color:#898887"> like identifiers when ordinary OCaml syntax is being used: *)</span>
declare where value
<span style="color:#898887">(* There's no way to reliably highlight all OCaml type expressions,</span>
<span style="color:#898887"> (they can be very complex) so just the built-in type names are highlighted.*)</span>
<span style="color:#0057ae">exn</span> <span style="color:#0057ae">lazy_t</span> <span style="color:#0057ae">format</span> <span style="color:#0057ae">unit</span> <span style="color:#0057ae">int</span> <span style="color:#0057ae">float</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>
<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:#bf0303">"still an identifier"</span>
<span style="font-weight:bold">let</span> integers : <span style="color:#0057ae">int</span> <span style="color:#0057ae">list</span> = [
<span style="color:#b08000">123456789</span>; <span style="color:#898887">(* decimal *)</span>
<span style="color:#b08000">-0xabcedf0123456789</span>; <span style="color:#898887">(* hexadecimal *)</span>
<span style="color:#b08000">0xABCDEF0123456789</span>; <span style="color:#898887">(* hexadecimal *)</span>
<span style="color:#b08000">-0o1234567</span>; <span style="color:#898887">(* octal *)</span>
<span style="color:#b08000">0b01001010101010</span>; <span style="color:#898887">(* binary *)</span>
<span style="color:#b08000">-0Xabcedf0123456789</span>; <span style="color:#898887">(* hexadecimal *)</span>
<span style="color:#b08000">0XABCDEF0123456789</span>; <span style="color:#898887">(* hexadecimal *)</span>
<span style="color:#b08000">-0O1234567</span>; <span style="color:#898887">(* octal *)</span>
<span style="color:#b08000">0B01001010101010</span>; <span style="color:#898887">(* binary *)</span>
<span style="color:#b08000">-123_456_789</span>; <span style="color:#898887">(* Underscores are allowed in numeric constants. *)</span>
<span style="color:#b08000">0x123n</span>;<span style="color:#b08000">456L</span>;<span style="color:#b08000">0o77l</span>;<span style="color:#b08000">0b11l</span> <span style="color:#898887">(* int32,int64 and nativeint constants *)</span>
<span style="color:#b08000">0</span>x_abce_df01_2345_6789;
<span style="color:#b08000">-0o12_34_567</span>;
<span style="color:#b08000">0</span>b_0100_1010_1010_1101;
];;
<span style="font-weight:bold">let</span> floats : <span style="color:#0057ae">float</span> <span style="color:#0057ae">list</span> = [
<span style="color:#b08000">12345.6789</span>;
<span style="color:#b08000">-1.23456789e4</span>; <span style="color:#898887">(* All variations of the exponent form *)</span>
<span style="color:#b08000">1.23456789e+4</span>;
<span style="color:#b08000">-1.23456789e-4</span>;
<span style="color:#b08000">1.23456789E-4</span>;
<span style="color:#b08000">-1.23456789E+4</span>;
<span style="color:#b08000">12_345.6789</span>; <span style="color:#898887">(* Underscores are allowed in numeric constants. *)</span>
<span style="color:#b08000">-1.23_456_789e+4</span>;
<span style="color:#b08000">12_345.6789</span>;
<span style="color:#b08000">0x1p-52</span> <span style="color:#898887">(* hexadecimal floating-point literals *)</span>
];;
<span style="font-weight:bold">let</span> characters : <span style="color:#0057ae">char</span> <span style="color:#0057ae">list</span> = [
<span style="color:#924c9d">'a'</span>;
<span style="color:#924c9d">' '</span>;
<span style="color:#924c9d">'�'</span>;
<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>
<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>
<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>
<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>
;<span style="color:#924c9d">'\ '</span>; <span style="color:#924c9d">'\o377'</span>
];;
<span style="color:#898887">(* Quotes used to mark constants in parsers should</span>
<span style="color:#898887"> not be confused with character constant quotes.</span>
<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>
<span style="color:#898887"> 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:#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>)
| [< name = s' >] -> <span style="font-style:italic">ID</span> (s',<span style="color:#924c9d">'i'</span>)
;;
<span style="font-weight:bold">let</span> strings : <span style="color:#0057ae">string</span> <span style="color:#0057ae">list</span> = [
<span style="color:#bf0303">""</span>; <span style="color:#898887">(* Empty string *)</span>
<span style="color:#bf0303">"a"</span>; <span style="color:#bf0303">" "</span>; <span style="color:#bf0303">"�"</span>; <span style="color:#bf0303">"ab"</span>;
<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>
<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>
<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>
<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>
<span style="color:#bf0303">"A multiline</span><span style="color:#924c9d">\</span>
<span style="color:#bf0303"> string"</span>;
<span style="color:#bf0303">"</span><span style="color:#924c9d">\u{207A}</span><span style="color:#bf0303">"</span>; <span style="color:#898887">(* Unicode escapes *)</span>
<span style="color:#bf0303">{|Simple quoted string, we can have " and ' inside, and even {|}</span>;
<span style="color:#bf0303">{another|quoted string|another}</span>;
<span style="color:#bf0303">{foo|More complicated quoted string where we can have {| inside|foo}</span>
];
<span style="font-weight:bold">let</span> camlp4_quotations = [
<span style="color:#bf0303"><<A Camlp4 source code quotation.>></span> ;
<span style="color:#bf0303"><: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:#b08000">-1</span> identifier.)>> ;
<span style="color:#bf0303"><< A quote with an escape: </span><span style="color:#924c9d">\>></span><span style="color:#bf0303"> (end-quote symbol) >></span> ;
<span style="color:#bf0303"><< A quote with an escape: </span><span style="color:#924c9d">\<<</span><span style="color:#bf0303"> (plain start quote-symbol) >></span> ;
<span style="color:#bf0303"><< A quote with an escape: \<:Trouv�< (labelled start-quote symbol) >></span> ;
];;
<span style="color:#898887">(* end *)</span>
</pre></body></html>
|