-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParser.fs
More file actions
24 lines (21 loc) · 891 Bytes
/
Parser.fs
File metadata and controls
24 lines (21 loc) · 891 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
module LspExample.Parser
open System
open LspExample.Types.DemoLang
open Types
let private parseLine (line: string) =
match Double.TryParse(line.AsSpan()) with
| Success parsedNumber -> Value.Number parsedNumber
| Nothing when String.IsNullOrWhiteSpace line -> Value.Empty line
| Nothing -> Value.Text line
/// <summary>
/// Parse an entire file into structured data.
/// </summary>
/// <param name="contents">The entire contents of a file</param>
/// <remarks>For large files and complex languages you should consider caching AST results and using incremental updated
/// instead of reparsing the full file update from the client every time something changes.</remarks>
let ParseFile (contents: string) : Line[] =
contents.Split('\n')
|> Array.mapi (fun line contents ->
{ Line = line
Contents = contents
Value = parseLine contents })