https://github.com/breandan/yuri

👨‍🚀 A type-safe URI builder in Kotlin

https://github.com/breandan/yuri

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (8.5%) to scientific vocabulary

Keywords

codegen dsl gradle-plugin kotlin parser type-safety uri
Last synced: 5 months ago · JSON representation

Repository

👨‍🚀 A type-safe URI builder in Kotlin

Basic Info
  • Host: GitHub
  • Owner: breandan
  • Language: Kotlin
  • Default Branch: master
  • Homepage:
  • Size: 317 KB
Statistics
  • Stars: 20
  • Watchers: 3
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Topics
codegen dsl gradle-plugin kotlin parser type-safety uri
Created over 7 years ago · Last pushed over 3 years ago
Metadata Files
Readme

README.md

Yuri

A type-safe URI builder for Kotlin. Work in progress.

tree

All usage examples are based on the following hypothetical file tree:

localhost ├── bin │ ├── sh │ └── sh.distrib | └── sh ├── etc │ ├── vim | └── script.sh └── usr ├── bin │ └── vim └── local └── bin └── sh

import

To work properly, Yuri needs a wildcard import:

kotlin import Y.*

usage

Yuri provides compile-time URI validation with a URI-like syntax.

```kotlin listOf( // Compiles! Y.uri(localhost), Y.uri(localhost /bin), Y.uri(localhost /bin/sh), Y.uri(localhost /bin/sh.distrib), Y.uri(localhost /bin/sh.distrib/sh), Y.uri(localhost /etc), Y.uri(localhost /etc/vim), Y.uri(localhost /etc/script.sh), Y.uri(localhost /usr), Y.uri(localhost /usr/bin/vim), Y.uri(localhost /usr/local), Y.uri(localhost /usr/local/bin), Y.uri(localhost /usr/local/bin/sh),

Y.uri(projectDir),
Y.uri(projectDir /gradle),
Y.uri(projectDir /gradlew),
Y.uri(projectDir /settings_dot_gradle),
Y.uri(projectDir /src/main),
Y.uri(projectDir /src/main/kotlin)

// Does not compile!
// ,Y.uri(localhost /local)
// ,Y.uri(localhost /bin/vim)
// ,Y.uri(localhost /sh)
// ,Y.uri(localhost /bin/local)
// ,Y.uri(localhost /etc/local)
// ,Y.uri(localhost /etc/sh)
// ,Y.uri(localhost /etc/script)
// ,Y.uri(localhost /usr/local/sh)
// ,Y.uri(localhost /usr/local/bin/sh.distrib)
// ,Y.uri(projectDir /test)
// ,Y.uri(projectDir /compileKotlin)
// ,Y.uri(projectDir /kotlin)
// ,Y.uri(projectDir /production/classes/main)

).forEach { println("$it") } ```

search

You can perform Kleene-star prefix searches using Kotlin's spread-operator:

```kotlin listOf( // Compiles! *bin, *sh, *vim, *bin/sh, *bin/sh.distrib, *etc/vim, *usr/bin, *sh.distrib, *sh.distrib/sh, *script.sh, *etc/script.sh

// Does not compile!
// , *etc/bin
// , *etc/sh
// , *local/usr
// , *sh/distrib
// , *sh/sh

).forEach { path -> println("*$path -> ${Y.uris(path)}") } ```

batch

Yuri provides an extension function for batch ops over multiple files:

kotlin Y.uris(*sh) { println(it) } Y.uris(*sh) { it.createNewFile() } Y.uris(*sh) { it.appendText("Hello Yuri") } Y.uris(*sh) { it.setReadOnly() }

examples

To reproduce the example code above, run the following command from the project directory:

./gradlew run

generate

To generate the file tree, run the following command from the consumer directory:

../gradlew genSources [-Path=<absolute path to perform file tree scan>]

Unless -Path is specified, Yuri will scan the project directory. Code generation is provided by Kotlin Poet.

how?

See:

  • Y.kt, for DSL and type checking
  • Yuri.kt, for code generation

why?

  • Because Strings are error prone (FileNotFoundException, NoSuchFileException...)

  • Many filesystems can be scanned quickly and do not change

  • To stress test Kotlin's type checker

  • Real time automatic code generation is getting better

  • Abusing operator overloading is fun! Learn how a DSL works

  • Might come in handy for scripting and build automation

  • Static resource discovery, e.g. webpage crawling, IP address scanning

  • Projects freqently need to reference absolute or project-local resources

Owner

  • Name: breandan
  • Login: breandan
  • Kind: user

GitHub Events

Total
Last Year

Issues and Pull Requests

Last synced: 10 months ago

All Time
  • Total issues: 0
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 0
  • Total pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Dependencies

.github/workflows/main.yml actions
  • actions/checkout v2 composite
  • actions/setup-java v1 composite
plugin/build.gradle.kts maven
  • com.squareup:kotlinpoet 1.7.2 implementation