configuration system supports %= to access environment variables
This commit is contained in:
parent
1314e91ef5
commit
0b5c42f405
4 changed files with 20 additions and 12 deletions
|
|
@ -52,7 +52,7 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo)
|
||||||
|
|
||||||
const
|
const
|
||||||
HelpMessage = "Nim Compiler Version $1 (" & CompileDate & ") [$2: $3]\n" &
|
HelpMessage = "Nim Compiler Version $1 (" & CompileDate & ") [$2: $3]\n" &
|
||||||
"Copyright (c) 2006-2014 by Andreas Rumpf\n"
|
"Copyright (c) 2006-2015 by Andreas Rumpf\n"
|
||||||
|
|
||||||
const
|
const
|
||||||
Usage = slurp"doc/basicopt.txt".replace("//", "")
|
Usage = slurp"doc/basicopt.txt".replace("//", "")
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
llstream, nversion, commands, os, strutils, msgs, platform, condsyms, lexer,
|
llstream, nversion, commands, os, strutils, msgs, platform, condsyms, lexer,
|
||||||
options, idents, wordrecg
|
options, idents, wordrecg, strtabs
|
||||||
|
|
||||||
# ---------------- configuration file parser -----------------------------
|
# ---------------- configuration file parser -----------------------------
|
||||||
# we use Nim's scanner here to safe space and work
|
# we use Nim's scanner here to safe space and work
|
||||||
|
|
@ -82,17 +82,17 @@ proc doElif(L: var TLexer, tok: var TToken) =
|
||||||
proc jumpToDirective(L: var TLexer, tok: var TToken, dest: TJumpDest) =
|
proc jumpToDirective(L: var TLexer, tok: var TToken, dest: TJumpDest) =
|
||||||
var nestedIfs = 0
|
var nestedIfs = 0
|
||||||
while true:
|
while true:
|
||||||
if (tok.ident != nil) and (tok.ident.s == "@"):
|
if tok.ident != nil and tok.ident.s == "@":
|
||||||
ppGetTok(L, tok)
|
ppGetTok(L, tok)
|
||||||
case whichKeyword(tok.ident)
|
case whichKeyword(tok.ident)
|
||||||
of wIf:
|
of wIf:
|
||||||
inc(nestedIfs)
|
inc(nestedIfs)
|
||||||
of wElse:
|
of wElse:
|
||||||
if (dest == jdElseEndif) and (nestedIfs == 0):
|
if dest == jdElseEndif and nestedIfs == 0:
|
||||||
doElse(L, tok)
|
doElse(L, tok)
|
||||||
break
|
break
|
||||||
of wElif:
|
of wElif:
|
||||||
if (dest == jdElseEndif) and (nestedIfs == 0):
|
if dest == jdElseEndif and nestedIfs == 0:
|
||||||
doElif(L, tok)
|
doElif(L, tok)
|
||||||
break
|
break
|
||||||
of wEnd:
|
of wEnd:
|
||||||
|
|
@ -119,9 +119,10 @@ proc parseDirective(L: var TLexer, tok: var TToken) =
|
||||||
of wElif: doElif(L, tok)
|
of wElif: doElif(L, tok)
|
||||||
of wElse: doElse(L, tok)
|
of wElse: doElse(L, tok)
|
||||||
of wEnd: doEnd(L, tok)
|
of wEnd: doEnd(L, tok)
|
||||||
of wWrite:
|
of wWrite:
|
||||||
ppGetTok(L, tok)
|
ppGetTok(L, tok)
|
||||||
msgs.msgWriteln(tokToStr(tok))
|
msgs.msgWriteln(strtabs.`%`(tokToStr(tok), options.gConfigVars,
|
||||||
|
{useEnvironment, useKey}))
|
||||||
ppGetTok(L, tok)
|
ppGetTok(L, tok)
|
||||||
else:
|
else:
|
||||||
case tok.ident.s.normalize
|
case tok.ident.s.normalize
|
||||||
|
|
@ -178,9 +179,10 @@ proc parseAssignment(L: var TLexer, tok: var TToken) =
|
||||||
if tok.tokType == tkBracketRi: confTok(L, tok)
|
if tok.tokType == tkBracketRi: confTok(L, tok)
|
||||||
else: lexMessage(L, errTokenExpected, "']'")
|
else: lexMessage(L, errTokenExpected, "']'")
|
||||||
add(val, ']')
|
add(val, ']')
|
||||||
if tok.tokType in {tkColon, tkEquals}:
|
let percent = tok.ident.id == getIdent("%=").id
|
||||||
|
if tok.tokType in {tkColon, tkEquals} or percent:
|
||||||
if len(val) > 0: add(val, ':')
|
if len(val) > 0: add(val, ':')
|
||||||
confTok(L, tok) # skip ':' or '='
|
confTok(L, tok) # skip ':' or '=' or '%'
|
||||||
checkSymbol(L, tok)
|
checkSymbol(L, tok)
|
||||||
add(val, tokToStr(tok))
|
add(val, tokToStr(tok))
|
||||||
confTok(L, tok) # skip symbol
|
confTok(L, tok) # skip symbol
|
||||||
|
|
@ -189,7 +191,11 @@ proc parseAssignment(L: var TLexer, tok: var TToken) =
|
||||||
checkSymbol(L, tok)
|
checkSymbol(L, tok)
|
||||||
add(val, tokToStr(tok))
|
add(val, tokToStr(tok))
|
||||||
confTok(L, tok)
|
confTok(L, tok)
|
||||||
processSwitch(s, val, passPP, info)
|
if percent:
|
||||||
|
processSwitch(s, strtabs.`%`(val, options.gConfigVars,
|
||||||
|
{useEnvironment, useEmpty}), passPP, info)
|
||||||
|
else:
|
||||||
|
processSwitch(s, val, passPP, info)
|
||||||
|
|
||||||
proc readConfigFile(filename: string) =
|
proc readConfigFile(filename: string) =
|
||||||
var
|
var
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,8 @@
|
||||||
|
|
||||||
# You may set environment variables with
|
# You may set environment variables with
|
||||||
# @putenv "key" "val"
|
# @putenv "key" "val"
|
||||||
# Environment variables cannot be used in the options, however!
|
# Environment variables can be accessed like so:
|
||||||
|
# gcc.path %= "$CC_PATH"
|
||||||
|
|
||||||
cc = gcc
|
cc = gcc
|
||||||
|
|
||||||
|
|
@ -21,6 +22,7 @@ mips.linux.gcc.linkerexe = "mips-openwrt-linux-gcc"
|
||||||
@end
|
@end
|
||||||
|
|
||||||
path="$lib/core"
|
path="$lib/core"
|
||||||
|
|
||||||
path="$lib/pure"
|
path="$lib/pure"
|
||||||
path="$lib/pure/collections"
|
path="$lib/pure/collections"
|
||||||
path="$lib/pure/concurrency"
|
path="$lib/pure/concurrency"
|
||||||
|
|
|
||||||
|
|
@ -158,7 +158,7 @@ proc getValue(t: StringTableRef, flags: set[FormatFlag], key: string): string =
|
||||||
else: result = ""
|
else: result = ""
|
||||||
if result.len == 0:
|
if result.len == 0:
|
||||||
if useKey in flags: result = '$' & key
|
if useKey in flags: result = '$' & key
|
||||||
elif not (useEmpty in flags): raiseFormatException(key)
|
elif useEmpty notin flags: raiseFormatException(key)
|
||||||
|
|
||||||
proc newStringTable*(mode: StringTableMode): StringTableRef {.
|
proc newStringTable*(mode: StringTableMode): StringTableRef {.
|
||||||
rtl, extern: "nst$1".} =
|
rtl, extern: "nst$1".} =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue