-
Notifications
You must be signed in to change notification settings - Fork 797
/
Copy pathprim-lexing.fsi
183 lines (130 loc) · 7.18 KB
/
prim-lexing.fsi
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
// LexBuffers are for use with automatically generated lexical analyzers,
// in particular those produced by 'fslex'.
namespace FSharp.Compiler.Text
/// Represents an input to the F# compiler
type ISourceText =
/// Gets a character in an input based on an index of characters from the start of the file
abstract Item: index: int -> char with get
/// Gets a line of an input by index
abstract GetLineString: lineIndex: int -> string
/// Gets the count of lines in the input
abstract GetLineCount: unit -> int
/// Gets the last character position in the input, returning line and column
abstract GetLastCharacterPosition: unit -> int * int
/// Gets a section of the input
abstract GetSubTextString: start: int * length: int -> string
/// Checks if a section of the input is equal to the given string
abstract SubTextEquals: target: string * startIndex: int -> bool
/// Gets the total length of the input in characters
abstract Length: int
/// Checks if one input is equal to another
abstract ContentEquals: sourceText: ISourceText -> bool
/// Copies a section of the input to the given destination ad the given index
abstract CopyTo: sourceIndex: int * destination: char[] * destinationIndex: int * count: int -> unit
/// Gets a section of the input based on a given range.
/// <exception cref="System.ArgumentException">Throws an exception when the input range is outside the file boundaries.</exception>
abstract GetSubTextFromRange: range: range -> string
/// Just like ISourceText, but with a checksum. Added as a separate type to avoid breaking changes.
type ISourceTextNew =
inherit ISourceText
abstract GetChecksum: unit -> System.Collections.Immutable.ImmutableArray<byte>
/// Functions related to ISourceText objects
module SourceText =
/// Creates an ISourceText object from the given string
val ofString: string -> ISourceText
module SourceTextNew =
val ofString: string -> ISourceTextNew
val ofISourceText: ISourceText -> ISourceTextNew
//
// NOTE: the code in this file is a drop-in replacement runtime for Lexing.fsi from the FsLexYacc repository
// and is referenced by generated code for the three FsLex generated lexers in the F# compiler.
// The underlying table format interpreted must precisely match the format generated by FsLex.
namespace Internal.Utilities.Text.Lexing
open System.Collections.Generic
open FSharp.Compiler.Text
open FSharp.Compiler.Features
/// Position information stored for lexing tokens
[<Struct>]
type internal Position =
/// The file index for the file associated with the input stream, use <c>fileOfFileIndex</c> to decode
val FileIndex: int
/// The line number in the input stream, assuming fresh positions have been updated
/// for the new line by modifying the EndPos property of the LexBuffer.
val Line: int
/// The line number for the position in the input stream, assuming fresh positions have been updated
/// using for the new line.
val OriginalLine: int
/// The character number in the input stream.
val AbsoluteOffset: int
/// Return absolute offset of the start of the line marked by the position.
val StartOfLineAbsoluteOffset: int
/// Return the column number marked by the position,
/// i.e. the difference between the <c>AbsoluteOffset</c> and the <c>StartOfLineAbsoluteOffset</c>
member Column: int
/// Given a position just beyond the end of a line, return a position at the start of the next line.
member NextLine: Position
/// Given a position at the start of a token of length n, return a position just beyond the end of the token.
member EndOfToken: n: int -> Position
/// Gives a position shifted by specified number of characters.
member ShiftColumnBy: by: int -> Position
/// Same line, column -1.
member ColumnMinusOne: Position
/// Apply a #line directive.
member ApplyLineDirective: fileIdx: int * line: int -> Position
/// Get an arbitrary position, with the empty string as file name.
static member Empty: Position
static member FirstLine: fileIdx: int -> Position
/// Input buffers consumed by lexers generated by <c>fslex.exe</c>.
/// The type must be generic to match the code generated by FsLex and FsYacc (if you would like to
/// fix this, please submit a PR to the FsLexYacc repository allowing for optional emit of a non-generic type reference).
[<Sealed>]
type internal LexBuffer<'Char> =
/// The start position for the lexeme.
member StartPos: Position with get, set
/// The end position for the lexeme.
member EndPos: Position with get, set
/// The currently matched text as a Span, it is only valid until the lexer is advanced
member LexemeView: System.ReadOnlySpan<'Char>
/// Get single character of matched string
member LexemeChar: int -> 'Char
/// Determine if Lexeme contains a specific character
member LexemeContains: 'Char -> bool
/// Fast helper to turn the matched characters into a string, avoiding an intermediate array.
static member LexemeString: LexBuffer<char> -> string
/// Dynamically typed, non-lexically scoped parameter table.
member BufferLocalStore: IDictionary<string, obj>
/// True if the refill of the buffer ever failed , or if explicitly set to True.
member IsPastEndOfStream: bool with get, set
/// Determines if the parser can report FSharpCore library-only features.
member ReportLibraryOnlyFeatures: bool
/// Get the language version being supported
member LanguageVersion: LanguageVersion
/// True if the specified language feature is supported.
member SupportsFeature: LanguageFeature -> bool
member StrictIndentation: bool option
/// Logs a recoverable error if a language feature is unsupported, at the specified range.
member CheckLanguageFeatureAndRecover: LanguageFeature -> range -> unit
/// Create a lex buffer suitable for Unicode lexing that reads characters from the given array.
/// Important: does take ownership of the array.
static member FromChars:
reportLibraryOnlyFeatures: bool * langVersion: LanguageVersion * strictIndentation: bool option * char[] ->
LexBuffer<char>
/// Create a lex buffer that reads character or byte inputs by using the given function.
static member FromFunction:
reportLibraryOnlyFeatures: bool *
langVersion: LanguageVersion *
strictIndentation: bool option *
('Char[] * int * int -> int) ->
LexBuffer<'Char>
/// Create a lex buffer backed by source text.
static member FromSourceText:
reportLibraryOnlyFeatures: bool * langVersion: LanguageVersion * strictIndentation: bool option * ISourceText ->
LexBuffer<char>
/// The type of tables for an unicode lexer generated by <c>fslex.exe</c>.
[<Sealed>]
type internal UnicodeTables =
/// Create the tables from raw data
static member Create: uint16[][] * uint16[] -> UnicodeTables
/// Interpret tables for a unicode lexer generated by <c>fslex.exe</c>.
member Interpret: initialState: int * LexBuffer<char> -> int