Skip to content

Commit

Permalink
Merge pull request #19 from bung87/syntax-operators
Browse files Browse the repository at this point in the history
operators syntax highlight
  • Loading branch information
levovix0 authored Apr 3, 2024
2 parents bdec350 + b519a86 commit ada26cb
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/syntax_highlighting.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import sequtils, unicode, streams
import pixie
import text

const
OpChars = ['+', '-', '*', '/', '\\', '<', '>', '!', '?', '^', '.',
'|', '=', '%', '&', '$', '@', '~', ':']

type
CodeKind* = enum
sText
Expand Down Expand Up @@ -38,7 +42,7 @@ type
proc parseNimCode*(s: Text, state: NimParseState, len = 100): tuple[segments: seq[CodeKind], state: NimParseState] =
result.state = state
result.segments = newSeq[CodeKind](len)

let opRunes = OpChars.toRunes
proc parseNext(s: Text, state: var NimParseState, res: var seq[CodeKind]) =
template rune(s: string): Rune = static(s.runeAt(0))
template runes(s: string): seq[Rune] = static(s.toRunes)
Expand Down Expand Up @@ -327,17 +331,16 @@ proc parseNimCode*(s: Text, state: NimParseState, len = 100): tuple[segments: se
elif r == rune"'": chr
elif r == rune"#": comment
elif r in "0123456789".runes: number

elif r in opRunes:
add sOperator, 1

elif r == "\"".rune and peek(1) == r and peek(2) == r:
multilineStr

elif r == "\"".rune: str
else:
add sText

# todo: operators


for _ in 1..len:
if result.state.pos > s.high: return
s.parseNext(result.state, result.segments)

0 comments on commit ada26cb

Please sign in to comment.