https://github.com/oscarmarcusson/whitespacenet
A C# utility for scanning the significant whitespace hierarchy of a string
https://github.com/oscarmarcusson/whitespacenet
csharp hierarchy-structure indentation-depth indentation-parsing parser whitespace
Last synced: about 2 months ago
JSON representation
A C# utility for scanning the significant whitespace hierarchy of a string
- Host: GitHub
- URL: https://github.com/oscarmarcusson/whitespacenet
- Owner: OscarMarcusson
- License: mit
- Created: 2023-12-16T07:37:23.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-12-16T19:26:51.000Z (over 1 year ago)
- Last Synced: 2025-01-30T04:42:56.941Z (4 months ago)
- Topics: csharp, hierarchy-structure, indentation-depth, indentation-parsing, parser, whitespace
- Language: C#
- Homepage: https://www.nuget.org/packages/WhitespaceNET
- Size: 111 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# WhitespaceNET
This utility enables easy parsing of significant whitespace text, like python or yaml files. It is a useful base for creating custom file formats or programming languages that utilises indentation for scope.
## Full text scan
```csharp
var doc = Hierarchy.FromString(@"
example: yaml
with-hierarchy:
a: 3
b: Example
");
Console.WriteLine(doc.Length); // 2
Console.WriteLine(doc[0].text); // example: yaml
Console.WriteLine(doc[1].text); // width-hierarchy:
Console.WriteLine(doc[1].content.Count); // 2
Console.WriteLine(doc[1].content[0].text); // a: 3
Console.WriteLine(doc[1].content[1].text); // b: Example
```## Indentation of a single line
```csharp
var indentation = WhitespaceReader.IndentationOf("\t\tHello World");
Console.WriteLine(indentation); // 2
```It is also possible to supply custom parsing rules with the settings class:
```csharp
var indentation = WhitespaceReader.IndentationOf(" Hello World", new Settings
{
tabSizeInSpaces = 2
});
Console.WriteLine(indentation); // 3
```