Skip to content

Instantly share code, notes, and snippets.

@jessiejs
Created June 23, 2023 14:37
Show Gist options
  • Save jessiejs/d4ccc25358d750dc1d99a159d050bd25 to your computer and use it in GitHub Desktop.
Save jessiejs/d4ccc25358d750dc1d99a159d050bd25 to your computer and use it in GitHub Desktop.
Super simple paths!

Jessie's Simple Paths

Foreword

This standard will specify a common path format, similar to other formats, that is not very difficult to implement, primarily so you don't have to write out your entire path format in the documentation, and instead you can just link to this.

I'm not sure if there's already a format for this, but this is probably easier to understand.

Fundamentals

A path is considered to be a list of segments seperated by path seperators. It can also start or end with path seperators.

A path seperator is either \ or /, as in, both work. When emmitting output, it is reccomended that you add an option to change the output path seperator, but the default should be a forward slash /.

There are three different types of path segments:

* Empty: Path segments that are exclusively whitespace characters.
Path segments with no contents are empty as there is no non-whitespace characters.
A whitespace character is one of the following:
	* a newline `\n`
	* a tab `\t`
	* a carridge return `\r`
	* a space ` `
* Current Directory: This is a path segment that exclusively consists of the content `.`.
* Backup: This is a path segment that exclusively consists of the content `..`.
* Default: Anything else

To resolve a path into one with only default segments, run the following algorithm:

  1. Let the output be an empty array of strings
  2. Iterate through all the segments
    • If the segment is empty or a current directory do nothing
    • If you encounter a backup, pop the item from the top of the output
    • If you encounter a default, push the path segment to the output array

You have now resolved the path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment