Skip to content

Commit

Permalink
Support echo char types shortcut (issue #12), v0.2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiRegiani committed May 11, 2018
1 parent 3b7c62a commit f7df997
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Runs in the current directory: `import` your local modules (access to exported* symbols)
* Preload existing source code (access to non-exported* symbols): `inim example.nim`
* Colorized output (red for errors, cyan for results)
* Shortcut to print values of discarded symbols: ```>>> x```
* Prints out value and type of discarded expressions: ```>>> x```

## Contributing
Pull requests and suggestions are welcome.
2 changes: 1 addition & 1 deletion inim.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "0.2.4"
version = "0.2.5"
author = "Andrei Regiani"
description = "Interactive Nim Shell / REPL / Playground"
license = "MIT"
Expand Down
15 changes: 10 additions & 5 deletions src/inim.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os, osproc, rdstdin, strutils, terminal, times

const
INimVersion = "0.2.4"
INimVersion = "0.2.5"
indentSpaces = " "
indentTriggers = [",", "=", ":", "var", "let", "const", "type", "import",
"object", "enum"] # endsWith
Expand Down Expand Up @@ -67,13 +67,18 @@ proc showError(output: string) =

# Discarded error: shortcut to print values: >>> foo
if message.endsWith("discarded"):
# Remove text until we can split by single-quote: foo'int
# Remove text bloat to result into: foo'int
message = message.replace("Error: expression '")
message = message.replace(" is of type '")
message = message.replace("' and has to be discarded")
let message_seq = message.split("'")
let symbol_identifier = message_seq[0] # foo
let symbol_type = message_seq[1] # int

# Make split char to be a semicolon instead of a single-quote
# To avoid char type conflict having single-quotes
message[message.rfind("'")] = ';' # last single-quote

let message_seq = message.split(";") # foo;int | 'a';char
let symbol_identifier = message_seq[0] # foo
let symbol_type = message_seq[1] # int
let shortcut = "echo " & symbol_identifier & ", \" : " & symbol_type & "\""

buffer.writeLine(shortcut)
Expand Down

0 comments on commit f7df997

Please sign in to comment.