about summary refs log tree commit diff stats
path: root/src/config
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-04-16 15:08:44 +0200
committerbptato <nincsnevem662@gmail.com>2024-04-17 23:19:09 +0200
commit66b9574b165be62e76c7397cf0eaa8d229d42675 (patch)
treeadb8a9719cc70f2b577706aaa4e30bb0d5d629a6 /src/config
parentd86f1939204eee771a30f47e4cbe71fd8d9a4f5f (diff)
downloadchawan-66b9574b165be62e76c7397cf0eaa8d229d42675.tar.gz
Update code style
* separate params with ; (semicolon) instead of , (colon)
* reduce screaming snake case use
* wrap long lines
Diffstat (limited to 'src/config')
-rw-r--r--src/config/chapath.nim114
-rw-r--r--src/config/config.nim2
-rw-r--r--src/config/mimetypes.nim2
-rw-r--r--src/config/toml.nim23
4 files changed, 69 insertions, 72 deletions
diff --git a/src/config/chapath.nim b/src/config/chapath.nim
index 57a8a853..8bab5070 100644
--- a/src/config/chapath.nim
+++ b/src/config/chapath.nim
@@ -28,29 +28,28 @@ type
     terminal: Option[char]
 
   UnquoteState = enum
-    STATE_NORMAL, STATE_TILDE, STATE_DOLLAR, STATE_IDENT, STATE_BSLASH,
-    STATE_CURLY_START, STATE_CURLY, STATE_CURLY_HASH, STATE_CURLY_PERC,
-    STATE_CURLY_COLON, STATE_CURLY_EXPAND, STATE_DONE
+    usNormal, usTilde, usDollar, usIdent, usBslash, usCurlyStart, usCurly,
+    usCurlyHash, usCurlyPerc, usCurlyColon, usCurlyExpand, usDone
 
   ChaPathError = string
 
   ChaPathResult[T] = Result[T, ChaPathError]
 
 proc unquote*(p: ChaPath): ChaPathResult[string]
-proc unquote(p: string, starti: var int, terminal: Option[char]):
+proc unquote(p: string; starti: var int; terminal: Option[char]):
     ChaPathResult[string]
 
-proc stateNormal(ctx: var UnquoteContext, c: char) =
+proc stateNormal(ctx: var UnquoteContext; c: char) =
   case c
-  of '$': ctx.state = STATE_DOLLAR
-  of '\\': ctx.state = STATE_BSLASH
+  of '$': ctx.state = usDollar
+  of '\\': ctx.state = usBslash
   of '~':
     if ctx.i == 0:
-      ctx.state = STATE_TILDE
+      ctx.state = usTilde
     else:
       ctx.s &= c
   elif ctx.terminal.isSome and ctx.terminal.get == c:
-    ctx.state = STATE_DONE
+    ctx.state = usDone
   else:
     ctx.s &= c
 
@@ -62,9 +61,9 @@ proc flushTilde(ctx: var UnquoteContext) =
     if p != nil:
       ctx.s &= $p.pw_dir
     ctx.identStr = ""
-  ctx.state = STATE_NORMAL
+  ctx.state = usNormal
 
-proc stateTilde(ctx: var UnquoteContext, c: char) =
+proc stateTilde(ctx: var UnquoteContext; c: char) =
   if c != '/':
     ctx.identStr &= c
   else:
@@ -73,30 +72,30 @@ proc stateTilde(ctx: var UnquoteContext, c: char) =
 # Kind of a hack. We special case `\$' (backslash-dollar) in TOML, so that
 # it produces itself in dquote strings.
 # Thus by applying stateBSlash we get '\$' -> "$", but also "\$" -> "$".
-proc stateBSlash(ctx: var UnquoteContext, c: char) =
+proc stateBSlash(ctx: var UnquoteContext; c: char) =
   if c != '$':
     ctx.s &= '\\'
   ctx.s &= c
-  ctx.state = STATE_NORMAL
+  ctx.state = usNormal
 
-proc stateDollar(ctx: var UnquoteContext, c: char): ChaPathResult[void] =
+proc stateDollar(ctx: var UnquoteContext; c: char): ChaPathResult[void] =
   # $
   case c
   of '$':
     ctx.s &= $getCurrentProcessId()
-    ctx.state = STATE_NORMAL
+    ctx.state = usNormal
   of '0':
     # Note: we intentionally use getAppFileName so that any symbolic links
     # are resolved.
     ctx.s &= getAppFileName()
-    ctx.state = STATE_NORMAL
+    ctx.state = usNormal
   of '1'..'9':
     return err("Parameter substitution is not supported")
   of AsciiAlpha:
     ctx.identStr = $c
-    ctx.state = STATE_IDENT
+    ctx.state = usIdent
   of '{':
-    ctx.state = STATE_CURLY_START
+    ctx.state = usCurlyStart
   else:
     # > If an unquoted '$' is followed by a character that is not one of
     # > the following: [...] the result is unspecified.
@@ -110,35 +109,35 @@ proc flushIdent(ctx: var UnquoteContext) =
 
 const BareChars = AsciiAlphaNumeric + {'_'}
 
-proc stateIdent(ctx: var UnquoteContext, c: char) =
+proc stateIdent(ctx: var UnquoteContext; c: char) =
   # $ident
   if c in BareChars:
     ctx.identStr &= c
   else:
     ctx.flushIdent()
     dec ctx.i
-    ctx.state = STATE_NORMAL
+    ctx.state = usNormal
 
-proc stateCurlyStart(ctx: var UnquoteContext, c: char): ChaPathResult[void] =
+proc stateCurlyStart(ctx: var UnquoteContext; c: char): ChaPathResult[void] =
   # ${
   case c
   of '#':
-    ctx.state = STATE_CURLY_HASH
+    ctx.state = usCurlyHash
   of '%':
-    ctx.state = STATE_CURLY_PERC
+    ctx.state = usCurlyPerc
   of BareChars:
-    ctx.state = STATE_CURLY
+    ctx.state = usCurly
     dec ctx.i
   else:
     return err("unexpected character in substitution: '" & c & "'")
   return ok()
 
-proc stateCurly(ctx: var UnquoteContext, c: char): ChaPathResult[void] =
+proc stateCurly(ctx: var UnquoteContext; c: char): ChaPathResult[void] =
   # ${ident
   case c
   of '}':
     ctx.s &= $getEnv(ctx.identStr)
-    ctx.state = STATE_NORMAL
+    ctx.state = usNormal
     return ok()
   of '$': # allow $ as first char only
     if ctx.identStr.len > 0:
@@ -149,10 +148,10 @@ proc stateCurly(ctx: var UnquoteContext, c: char): ChaPathResult[void] =
     if ctx.identStr.len > 0:
       return err("substitution without parameter name")
     if c == ':':
-      ctx.state = STATE_CURLY_COLON
+      ctx.state = usCurlyColon
     else:
       ctx.subChar = c
-      ctx.state = STATE_CURLY_EXPAND
+      ctx.state = usCurlyExpand
     return ok()
   of '1'..'9':
     return err("Parameter substitution is not supported")
@@ -162,13 +161,13 @@ proc stateCurly(ctx: var UnquoteContext, c: char): ChaPathResult[void] =
   else:
     return err("unexpected character in substitution: '" & c & "'")
 
-proc stateCurlyHash(ctx: var UnquoteContext, c: char): ChaPathResult[void] =
+proc stateCurlyHash(ctx: var UnquoteContext; c: char): ChaPathResult[void] =
   # ${#ident
   if c == '}':
     let s = getEnv(ctx.identStr)
     ctx.s &= $s.len
     ctx.identStr = ""
-    ctx.state = STATE_NORMAL
+    ctx.state = usNormal
     return ok()
   if c == '$': # allow $ as first char only
     if ctx.identStr.len > 0:
@@ -179,7 +178,7 @@ proc stateCurlyHash(ctx: var UnquoteContext, c: char): ChaPathResult[void] =
   ctx.identStr &= c
   return ok()
 
-proc stateCurlyPerc(ctx: var UnquoteContext, c: char): ChaPathResult[void] =
+proc stateCurlyPerc(ctx: var UnquoteContext; c: char): ChaPathResult[void] =
   # ${%ident
   if c == '}':
     if ctx.identStr == "CHA_BIN_DIR":
@@ -189,23 +188,23 @@ proc stateCurlyPerc(ctx: var UnquoteContext, c: char): ChaPathResult[void] =
     else:
       return err("Unknown internal variable " & ctx.identStr)
     ctx.identStr = ""
-    ctx.state = STATE_NORMAL
+    ctx.state = usNormal
     return ok()
   if c notin BareChars:
     return err("unexpected character in substitution: '" & c & "'")
   ctx.identStr &= c
   return ok()
 
-proc stateCurlyColon(ctx: var UnquoteContext, c: char): ChaPathResult[void] =
+proc stateCurlyColon(ctx: var UnquoteContext; c: char): ChaPathResult[void] =
   # ${ident:
   if c notin {'-', '?', '+'}: # Note: we don't support `=' (assign)
     return err("unexpected character after colon: '" & c & "'")
   ctx.hasColon = true
   ctx.subChar = c
-  ctx.state = STATE_CURLY_EXPAND
+  ctx.state = usCurlyExpand
   return ok()
 
-proc flushCurlyExpand(ctx: var UnquoteContext, word: string):
+proc flushCurlyExpand(ctx: var UnquoteContext; word: string):
     ChaPathResult[void] =
   case ctx.subChar
   of '-':
@@ -238,41 +237,40 @@ proc flushCurlyExpand(ctx: var UnquoteContext, word: string):
   ctx.hasColon = false
   return ok()
 
-proc stateCurlyExpand(ctx: var UnquoteContext, c: char): ChaPathResult[void] =
+proc stateCurlyExpand(ctx: var UnquoteContext; c: char): ChaPathResult[void] =
   # ${ident:-[word], ${ident:=[word], ${ident:?[word], ${ident:+[word]
   # word must be unquoted too.
   let word = ?unquote(ctx.p, ctx.i, some('}'))
   return ctx.flushCurlyExpand(word)
 
-proc unquote(p: string, starti: var int, terminal: Option[char]):
+proc unquote(p: string; starti: var int; terminal: Option[char]):
     ChaPathResult[string] =
   var ctx = UnquoteContext(p: p, i: starti, terminal: terminal)
   while ctx.i < p.len:
     let c = p[ctx.i]
     case ctx.state
-    of STATE_NORMAL: ctx.stateNormal(c)
-    of STATE_TILDE: ctx.stateTilde(c)
-    of STATE_BSLASH: ctx.stateBSlash(c)
-    of STATE_DOLLAR: ?ctx.stateDollar(c)
-    of STATE_IDENT: ctx.stateIdent(c)
-    of STATE_CURLY_START: ?ctx.stateCurlyStart(c)
-    of STATE_CURLY: ?ctx.stateCurly(c)
-    of STATE_CURLY_HASH: ?ctx.stateCurlyHash(c)
-    of STATE_CURLY_PERC: ?ctx.stateCurlyPerc(c)
-    of STATE_CURLY_COLON: ?ctx.stateCurlyColon(c)
-    of STATE_CURLY_EXPAND: ?ctx.stateCurlyExpand(c)
-    of STATE_DONE: break
+    of usNormal: ctx.stateNormal(c)
+    of usTilde: ctx.stateTilde(c)
+    of usBslash: ctx.stateBSlash(c)
+    of usDollar: ?ctx.stateDollar(c)
+    of usIdent: ctx.stateIdent(c)
+    of usCurlyStart: ?ctx.stateCurlyStart(c)
+    of usCurly: ?ctx.stateCurly(c)
+    of usCurlyHash: ?ctx.stateCurlyHash(c)
+    of usCurlyPerc: ?ctx.stateCurlyPerc(c)
+    of usCurlyColon: ?ctx.stateCurlyColon(c)
+    of usCurlyExpand: ?ctx.stateCurlyExpand(c)
+    of usDone: break
     inc ctx.i
   case ctx.state
-  of STATE_NORMAL, STATE_DONE: discard
-  of STATE_TILDE: ctx.flushTilde()
-  of STATE_BSLASH: ctx.s &= '\\'
-  of STATE_DOLLAR: ctx.s &= '$'
-  of STATE_IDENT: ctx.flushIdent()
-  of STATE_CURLY_START, STATE_CURLY, STATE_CURLY_HASH, STATE_CURLY_PERC,
-      STATE_CURLY_COLON:
+  of usNormal, usDone: discard
+  of usTilde: ctx.flushTilde()
+  of usBslash: ctx.s &= '\\'
+  of usDollar: ctx.s &= '$'
+  of usIdent: ctx.flushIdent()
+  of usCurlyStart, usCurly, usCurlyHash, usCurlyPerc, usCurlyColon:
     return err("} expected")
-  of STATE_CURLY_EXPAND:
+  of usCurlyExpand:
     ?ctx.flushCurlyExpand("")
   starti = ctx.i
   return ok(ctx.s)
@@ -281,7 +279,7 @@ proc unquote(p: string): ChaPathResult[string] =
   var dummy = 0
   return unquote(p, dummy, none(char))
 
-proc toJS*(ctx: JSContext, p: ChaPath): JSValue =
+proc toJS*(ctx: JSContext; p: ChaPath): JSValue =
   toJS(ctx, $p)
 
 proc fromJSChaPath*(ctx: JSContext; val: JSValue): JSResult[ChaPath] =
diff --git a/src/config/config.nim b/src/config/config.nim
index 4f28f4e5..63bc50ab 100644
--- a/src/config/config.nim
+++ b/src/config/config.nim
@@ -244,7 +244,7 @@ proc delete(a: ptr ActionMap; k: string): bool {.jsdelprop.} =
   a[].t.del(k)
   return ina
 
-func names(ctx: JSContext, a: ptr ActionMap): JSPropertyEnumList
+func names(ctx: JSContext; a: ptr ActionMap): JSPropertyEnumList
     {.jspropnames.} =
   let L = uint32(a[].t.len)
   var list = newJSPropertyEnumList(ctx, L)
diff --git a/src/config/mimetypes.nim b/src/config/mimetypes.nim
index e8a0fd07..f247822e 100644
--- a/src/config/mimetypes.nim
+++ b/src/config/mimetypes.nim
@@ -12,7 +12,7 @@ proc hasKeyOrPut*(mimeTypes: var MimeTypes; k, v: string): bool {.borrow.}
 
 # Add mime types found in stream to mimeTypes.
 # No error handling for now.
-proc parseMimeTypes*(mimeTypes: var MimeTypes, stream: Stream) =
+proc parseMimeTypes*(mimeTypes: var MimeTypes; stream: Stream) =
   var line: string
   while stream.readLine(line):
     if line.len == 0:
diff --git a/src/config/toml.nim b/src/config/toml.nim
index 760f335d..f28c4916 100644
--- a/src/config/toml.nim
+++ b/src/config/toml.nim
@@ -114,38 +114,38 @@ func `$`*(val: TomlValue): string =
       result &= ','
     result &= ']'
 
-func `[]`*(val: TomlValue, key: string): TomlValue =
+func `[]`*(val: TomlValue; key: string): TomlValue =
   return val.tab.map[key]
 
 iterator pairs*(val: TomlValue): (string, TomlValue) {.inline.} =
   for k, v in val.tab.map:
     yield (k, v)
 
-func contains*(val: TomlValue, key: string): bool =
+func contains*(val: TomlValue; key: string): bool =
   return key in val.tab.map
 
 const ValidBare = AsciiAlphaNumeric + {'-', '_'}
 
-func peek(state: TomlParser, i: int): char =
+func peek(state: TomlParser; i: int): char =
   return state.buf[state.at + i]
 
-template err(state: TomlParser, msg: string): untyped =
+template err(state: TomlParser; msg: string): untyped =
   err(state.filename & "(" & $state.line & "):" & msg)
 
 proc consume(state: var TomlParser): char =
   result = state.buf[state.at]
   inc state.at
 
-proc seek(state: var TomlParser, n: int) =
+proc seek(state: var TomlParser; n: int) =
   state.at += n
 
 proc reconsume(state: var TomlParser) =
   dec state.at
 
-proc has(state: var TomlParser, i: int = 0): bool =
+proc has(state: var TomlParser; i: int = 0): bool =
   return state.at + i < state.buf.len
 
-proc consumeEscape(state: var TomlParser, c: char): Result[Rune, TomlError] =
+proc consumeEscape(state: var TomlParser; c: char): Result[Rune, TomlError] =
   var len = 4
   if c == 'U':
     len = 8
@@ -171,8 +171,7 @@ proc consumeEscape(state: var TomlParser, c: char): Result[Rune, TomlError] =
   else:
     return state.err("invalid escaped codepoint: " & $c)
 
-proc consumeString(state: var TomlParser, first: char):
-    Result[string, string] =
+proc consumeString(state: var TomlParser; first: char): Result[string, string] =
   var multiline = false
   if first == '"' and state.has(1) and state.peek(0) == '"' and
       state.peek(1) == '"':
@@ -232,7 +231,7 @@ proc consumeString(state: var TomlParser, first: char):
       res &= c
   return ok(res)
 
-proc consumeBare(state: var TomlParser, c: char): Result[string, TomlError] =
+proc consumeBare(state: var TomlParser; c: char): Result[string, TomlError] =
   var res = $c
   while state.has():
     let c = state.consume()
@@ -392,7 +391,7 @@ proc consumeNoState(state: var TomlParser): Result[bool, TomlError] =
 type ParsedNumberType = enum
   NUMBER_INTEGER, NUMBER_FLOAT, NUMBER_HEX, NUMBER_OCT
 
-proc consumeNumber(state: var TomlParser, c: char): TomlResult =
+proc consumeNumber(state: var TomlParser; c: char): TomlResult =
   var repr = ""
   var numType = NUMBER_INTEGER
   if c == '0' and state.has():
@@ -568,7 +567,7 @@ proc consumeValue(state: var TomlParser): TomlResult =
     return ok(TomlValue(t: tvtString, s: ""))
   return state.err("unexpected end of file")
 
-proc parseToml*(inputStream: Stream, filename = "<input>", laxnames = false):
+proc parseToml*(inputStream: Stream; filename = "<input>"; laxnames = false):
     TomlResult =
   var state = TomlParser(
     buf: inputStream.readAll(),