Skip to content

Commit

Permalink
Adds configuration object for Shell, adds CLI note, and updates synta…
Browse files Browse the repository at this point in the history
…x file
  • Loading branch information
johnedquinn committed Jun 16, 2022
1 parent 101e048 commit e0411cf
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions cli/resources/org/partiql/cli/syntax/PartiQL.nanorc
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ syntax "PartiQL" "\.pql$"
color magenta "([0-9]+(\.)?[0-9]*|[0-9]*(\.)?[0-9]+)([eE][+-]?[0-9]+)*"

# PartiQL Data Types
icolor green "\<(smallint|integer2|int2|integer4|int4|integer8|int8|char|character|time)\>"
icolor green "\<(int|smallint|bigint|integer|integer2|int2|integer4|int4|integer8|int8|char|character|time)\>"
icolor green "\<(bool|boolean|string|symbol|clob|blob|struct|list|sexp|bag)\>"
icolor green "\<(varchar|date|smallint|int|integer|bigint|float|double|decimal)\>"
icolor green "\<(varchar|date|float|double|decimal)\>"
icolor green "\<(timestamp|time)\>"

# PartiQL Keywords (Non Data Types)
Expand Down
5 changes: 3 additions & 2 deletions cli/src/org/partiql/cli/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import org.partiql.lang.eval.ExprValueFactory
import org.partiql.lang.eval.TypingMode
import org.partiql.lang.syntax.SqlParser
import org.partiql.shell.Shell
import org.partiql.shell.Shell.ShellConfiguration
import java.io.File
import java.io.FileInputStream
import java.io.FileOutputStream
Expand Down Expand Up @@ -197,8 +198,8 @@ fun main(args: Array<String>) = try {
}

private fun runShell(environment: Bindings<ExprValue>, optionSet: OptionSet, compilerPipeline: CompilerPipeline) {
val isMonochrome = optionSet.has(monochromeOpt)
Shell(valueFactory, System.out, parser, compilerPipeline, environment, isMonochrome).start()
val config = ShellConfiguration(isMonochrome = optionSet.has(monochromeOpt))
Shell(valueFactory, System.out, parser, compilerPipeline, environment, config).start()
}

private fun runCli(environment: Bindings<ExprValue>, optionSet: OptionSet, compilerPipeline: CompilerPipeline) {
Expand Down
9 changes: 6 additions & 3 deletions cli/src/org/partiql/shell/Shell.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class Shell(
private val parser: Parser,
private val compiler: CompilerPipeline,
private val initialGlobal: Bindings<ExprValue>,
private val isMonochrome: Boolean = false
private val config: ShellConfiguration = ShellConfiguration()
) {

private val homeDir: Path = Paths.get(System.getProperty("user.home"))
Expand Down Expand Up @@ -125,9 +125,10 @@ class Shell(
private fun run(exiting: AtomicBoolean) = TerminalBuilder.builder().build().use { terminal ->
val userSyntaxFile = homeDir.resolve(".nano/PartiQL.nanorc")
val highlighter = when {
this.isMonochrome -> null
this.config.isMonochrome -> null
userSyntaxFile.toFile().exists() -> ShellHighlighter(userSyntaxFile.toUri())
else -> ShellHighlighter(Shell::class.java.classLoader.getResource("org/partiql/cli/syntax/PartiQL.nanorc").toURI())
else -> Shell::class.java.classLoader.getResource("org/partiql/cli/syntax/PartiQL.nanorc")
?.let { ShellHighlighter(it.toURI()) }
}
val reader = LineReaderBuilder.builder()
.terminal(terminal)
Expand Down Expand Up @@ -268,6 +269,8 @@ class Shell(
}
}
}

class ShellConfiguration(val isMonochrome: Boolean = false)
}

/**
Expand Down
6 changes: 5 additions & 1 deletion docs/user/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ To start an interactive read, eval, print loop (REPL) execute:
> Note that running directly with Gradle will eat arrow keys and control sequences due to the Gradle daemon.
```shell
./cli/shell
./cli/shell.sh
```

You will see a prompt that looks as follows:
Expand Down Expand Up @@ -97,6 +97,10 @@ PartiQL> SELECT id FROM `[{id: 5, name:"bill"}, {id: 6, name:"bob"}]` WHERE name
>>
```

**Note on Syntax Highlighting**: You'll notice that the PartiQL REPL supports PartiQL syntax highlighting on input
queries. Internally, the REPL uses `.nanorc` files to specify syntax, and you can override the default highlights
by providing an override file at `~/.nano/PartiQL.nanorc`.

The result of the previous expression is stored in the variable named `_`, so you can then run subsequent
expressions based on the last one.

Expand Down

0 comments on commit e0411cf

Please sign in to comment.