author | wenzelm |
Wed, 09 Mar 2022 16:21:14 +0100 | |
changeset 75252 | 41dfe941c3da |
parent 75248 | b57efe7fe1d3 |
permissions | -rw-r--r-- |
75240 | 1 |
/* Author: Makarius |
2 |
||
75246
f32e5d4cf1a3
patch for vscode encoding "UTF-8-Isabelle": clone of "utf8", no symbols yet;
wenzelm
parents:
75245
diff
changeset
|
3 |
UTF-8-Isabelle symbol encoding: for use inside VSCode. |
75240 | 4 |
*/ |
5 |
||
6 |
'use strict'; |
|
7 |
||
75245 | 8 |
import { TextEncoder, TextDecoder } from 'util' // VSCODE: REMOVE |
9 |
||
75240 | 10 |
|
11 |
/* defined symbols */ |
|
12 |
||
75245 | 13 |
export interface Symbol_Entry { |
14 |
symbol: string; |
|
15 |
name: string; |
|
16 |
code: number; |
|
17 |
abbrevs: string[]; |
|
75240 | 18 |
} |
19 |
||
75252
41dfe941c3da
inline Isabelle symbols into source text, so that "isabelle vscode" can start up properly without access to process.env or fs;
wenzelm
parents:
75248
diff
changeset
|
20 |
export const static_symbols: Symbol_Entry[] = [/*symbols*/]; |
75240 | 21 |
|
22 |
export const symbols_decode: Map<string, string> = |
|
75252
41dfe941c3da
inline Isabelle symbols into source text, so that "isabelle vscode" can start up properly without access to process.env or fs;
wenzelm
parents:
75248
diff
changeset
|
23 |
new Map(static_symbols.map((s: Symbol_Entry) => [s.symbol, String.fromCharCode(s.code)])); |
75240 | 24 |
|
25 |
export const symbols_encode: Map<string, string> = |
|
75252
41dfe941c3da
inline Isabelle symbols into source text, so that "isabelle vscode" can start up properly without access to process.env or fs;
wenzelm
parents:
75248
diff
changeset
|
26 |
new Map(static_symbols.map((s: Symbol_Entry) => [String.fromCharCode(s.code), s.symbol])); |
75240 | 27 |
|
28 |
||
29 |
/* encoding */ |
|
30 |
||
75246
f32e5d4cf1a3
patch for vscode encoding "UTF-8-Isabelle": clone of "utf8", no symbols yet;
wenzelm
parents:
75245
diff
changeset
|
31 |
export const ENCODING = 'utf8isabelle'; |
f32e5d4cf1a3
patch for vscode encoding "UTF-8-Isabelle": clone of "utf8", no symbols yet;
wenzelm
parents:
75245
diff
changeset
|
32 |
export const LABEL = 'UTF-8-Isabelle'; |
75240 | 33 |
|
34 |
export interface Options { |
|
35 |
stripBOM?: boolean; |
|
36 |
addBOM?: boolean; |
|
37 |
defaultEncoding?: string; |
|
38 |
} |
|
39 |
||
75245 | 40 |
export interface IEncoderStream { |
41 |
write(input: string): Uint8Array; |
|
42 |
end(): Uint8Array | undefined; |
|
75240 | 43 |
} |
44 |
||
75245 | 45 |
export interface IDecoderStream { |
46 |
write(input: Uint8Array): string; |
|
47 |
end(): string | undefined; |
|
75240 | 48 |
} |
49 |
||
75246
f32e5d4cf1a3
patch for vscode encoding "UTF-8-Isabelle": clone of "utf8", no symbols yet;
wenzelm
parents:
75245
diff
changeset
|
50 |
export function getEncoder(): IEncoderStream { |
75245 | 51 |
const utf8_encoder = new TextEncoder(); |
52 |
return { |
|
53 |
write(input: string): Uint8Array { |
|
54 |
return utf8_encoder.encode(input); |
|
55 |
}, |
|
56 |
end(): Uint8Array | undefined { |
|
57 |
return utf8_encoder.encode(); |
|
58 |
} |
|
59 |
}; |
|
75240 | 60 |
} |
61 |
||
75246
f32e5d4cf1a3
patch for vscode encoding "UTF-8-Isabelle": clone of "utf8", no symbols yet;
wenzelm
parents:
75245
diff
changeset
|
62 |
export function getDecoder(): IDecoderStream { |
75245 | 63 |
const utf8TextDecoder = new TextDecoder(); |
64 |
return { |
|
65 |
write(input: Uint8Array): string { |
|
66 |
return utf8TextDecoder.decode(input, { stream: true }); |
|
67 |
}, |
|
68 |
end(): string | undefined { |
|
69 |
return utf8TextDecoder.decode(); |
|
70 |
} |
|
71 |
}; |
|
75240 | 72 |
} |