Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added for for triple quote indentation #133

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions inim.nim
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var

const
NimblePkgVersion {.strdefine.} = ""
# endsWith
TripleQuoteTrigger = "\"\"\""
IndentTriggers = [
",", "=", ":",
"var", "let", "const", "type", "import",
Expand Down Expand Up @@ -97,6 +97,7 @@ var
buffer: File
noiser = Noise.init()
historyFile: string
previously_triple_quoted: bool

template outputFg(color: ForegroundColor, bright: bool = false,
body: untyped): untyped =
Expand Down Expand Up @@ -332,7 +333,15 @@ proc hasIndentTrigger*(line: string): bool =
if line.len == 0:
return
for trigger in IndentTriggers:
if line.strip().endsWith(trigger):
let clean_line = line.strip()
# Triple quoted triggers need to not increase the indent further
if clean_line.contains(TripleQuoteTrigger):
# Do not indent further
if previously_triple_quoted:
return
previously_triple_quoted = true
return true
elif clean_line.endsWith(trigger):
result = true

proc doRepl() =
Expand Down Expand Up @@ -399,7 +408,9 @@ call(cmd) - Execute command cmd in current shell
discard

# Empty line: exit indent level, otherwise do nothing
if currentExpression.strip() == "" or currentExpression.startsWith("else"):
if currentExpression.strip() == "" or currentExpression.startsWith("else") or (previously_triple_quoted and currentExpression.strip() == TripleQuoteTrigger):
if currentExpression.strip() == TripleQuoteTrigger:
previously_triple_quoted = false
if indentLevel > 0:
indentLevel -= 1
elif indentLevel == 0:
Expand Down
2 changes: 1 addition & 1 deletion inim.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ bin = @["inim"]

# Dependencies

requires "cligen >= 1.5.22"
requires "cligen >= 1.5.23"

requires "noise >= 0.1.4"

Expand Down
2 changes: 1 addition & 1 deletion tests/test.nim
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ suite "INim Test Suite":
hasIndentTrigger("type") == true
hasIndentTrigger("CallbackAction* = enum ") == true
hasIndentTrigger("Response* = ref object ") == true
hasIndentTrigger("var s = \"\"\"") == true

test "Executes piped code from file":
check execCmdEx("cat tests/test_piping_file.nim | bin/inim").output.strip() == """4
Expand All @@ -43,4 +44,3 @@ suite "INim Test Suite":

test "Verify flags with '--' prefix work":
check execCmdEx("""echo 'import threadpool; echo "SUCCESS"' | bin/inim --flag=--threads:on""").output.strip() == "SUCCESS"