-
Notifications
You must be signed in to change notification settings - Fork 161
Expand file tree
/
Copy pathSourceCode.fs
More file actions
114 lines (100 loc) · 4.15 KB
/
SourceCode.fs
File metadata and controls
114 lines (100 loc) · 4.15 KB
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
// --------------------------------------------------------------------------------------
// F# CodeFormat (SourceCode.fs)
// (c) Tomas Petricek, 2012, Available under Apache 2.0 license.
// --------------------------------------------------------------------------------------
namespace rec FSharp.Formatting.CodeFormat
open FSharp.Formatting.CodeFormat.Constants
// --------------------------------------------------------------------------------------
// Abstract Syntax representation of formatted source code
// --------------------------------------------------------------------------------------
/// A tool tip consists of a list of items reported from the compiler
type ToolTipSpans = ToolTipSpan list
/// A tool tip span can be emphasized text, plain text Literal or a line brak
type ToolTipSpan =
| Emphasis of ToolTipSpans
| Literal of string
| HardLineBreak
/// Classifies tokens reported by the FCS
[<RequireQualifiedAccess; Struct>]
type TokenKind =
| Keyword
| String
| Comment
| Identifier
| Inactive
| Number
| Operator
| Punctuation
| Preprocessor
| Module
| ReferenceType
| ValueType
| Interface
| TypeArgument
| Property
| Enumeration
| UnionCase
| Function
| Pattern
| MutableVar
| Disposable
| Printf
| Escaped
| Default
/// Represents a kind of error reported from the F# compiler (warning or error)
[<RequireQualifiedAccess; Struct>]
type ErrorKind =
| Error
| Warning
/// A token in a parsed F# code snippet. Aside from standard tokens reported from
/// the compiler (Token), this also includes Error (wrapping the underlined
/// tokens), Omitted for the special [omit:...] tags and Output for the special [output:...] tag
[<RequireQualifiedAccess>]
type TokenSpan =
| Token of kind: TokenKind * body: string * tip: ToolTipSpans option
| Error of kind: ErrorKind * message: string * body: TokenSpans
| Omitted of body: string * hidden: string
| Output of string
/// A type alias representing a list of TokenSpan values
type TokenSpans = TokenSpan list
/// Represents a line of source code as a list of TokenSpan values. This is
/// a single case discriminated union with Line constructor.
type Line = Line of originalLine: string * tokenSpans: TokenSpans
/// An F# snippet consists of a snippet title and a list of lines
type Snippet = Snippet of title: string * lines: Line list
/// Error reported from the F# compiler consists of location (start and end),
/// error kind and the message (wrapped in a single case discriminated union
/// with constructor SourceError)
type SourceError =
/// Error reported from the F# compiler consists of location (start and end),
/// error kind and the message
| SourceError of start: (int * int) * finish: (int * int) * errorKind: ErrorKind * message: string
/// Internal helpers for mapping TokenKind values to CSS class names.
module internal CodeFormatHelper =
/// Map a TokenKind to the corresponding CSS class name string using the default CSS class map.
let defaultTokenMap kind =
match kind with
| TokenKind.Comment -> CSS.Comment
| TokenKind.Default -> CSS.Default
| TokenKind.Identifier -> CSS.Identifier
| TokenKind.Inactive -> CSS.Inactive
| TokenKind.Keyword -> CSS.Keyword
| TokenKind.Number -> CSS.Number
| TokenKind.Operator -> CSS.Operator
| TokenKind.Preprocessor -> CSS.Preprocessor
| TokenKind.String -> CSS.String
| TokenKind.Module -> CSS.Module
| TokenKind.ReferenceType -> CSS.ReferenceType
| TokenKind.ValueType -> CSS.ValueType
| TokenKind.Function -> CSS.Function
| TokenKind.Pattern -> CSS.Pattern
| TokenKind.MutableVar -> CSS.MutableVar
| TokenKind.Printf -> CSS.Printf
| TokenKind.Escaped -> CSS.Escaped
| TokenKind.Disposable -> CSS.Disposable
| TokenKind.TypeArgument -> CSS.TypeArgument
| TokenKind.Punctuation -> CSS.Punctuation
| TokenKind.Enumeration -> CSS.Enumeration
| TokenKind.Interface -> CSS.Interface
| TokenKind.Property -> CSS.Property
| TokenKind.UnionCase -> CSS.UnionCase