Skip to content

Commit

Permalink
Added for for triple quote indentation
Browse files Browse the repository at this point in the history
Upgraded pinned cligen version
  • Loading branch information
Ryan Cotter committed Apr 4, 2022
1 parent 1426527 commit a87cfdf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
19 changes: 15 additions & 4 deletions inim.nim
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ var

const
NimblePkgVersion {.strdefine.} = ""
# endsWith
TripleQuoteTrigger = "\"\"\""
IndentTriggers = [
",", "=", ":",
",", "=", ":", TripleQuoteTrigger,
"var", "let", "const", "type", "import",
"object", "RootObj", "enum"
]
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 line.endsWith(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"

0 comments on commit a87cfdf

Please sign in to comment.