about summary refs log tree commit diff
path: root/src/libexpr
diff options
context:
space:
mode:
authorShea Levy <shea@shealevy.com>2015-02-19T13·05-0500
committerShea Levy <shea@shealevy.com>2015-02-19T13·05-0500
commite0953d53de1dbb89ef0ff779e53ffdb0d988e806 (patch)
treefdace2efd90da8735d3abb36a16f65aad9b28f79 /src/libexpr
parent1816ac0db1817642e27ef1544c7d9b904dbb670a (diff)
Allow the leading component of a path to be a ~
Diffstat (limited to 'src/libexpr')
-rw-r--r--src/libexpr/lexer.l2
-rw-r--r--src/libexpr/parser.y10
2 files changed, 11 insertions, 1 deletions
diff --git a/src/libexpr/lexer.l b/src/libexpr/lexer.l
index 82520ee7a59a..7051909008d1 100644
--- a/src/libexpr/lexer.l
+++ b/src/libexpr/lexer.l
@@ -80,6 +80,7 @@ static Expr * unescapeStr(SymbolTable & symbols, const char * s)
 ID          [a-zA-Z\_][a-zA-Z0-9\_\'\-]*
 INT         [0-9]+
 PATH        [a-zA-Z0-9\.\_\-\+]*(\/[a-zA-Z0-9\.\_\-\+]+)+
+HPATH       \~(\/[a-zA-Z0-9\.\_\-\+]+)+
 SPATH       \<[a-zA-Z0-9\.\_\-\+]+(\/[a-zA-Z0-9\.\_\-\+]+)*\>
 URI         [a-zA-Z][a-zA-Z0-9\+\-\.]*\:[a-zA-Z0-9\%\/\?\:\@\&\=\+\$\,\-\_\.\!\~\*\']+
 
@@ -159,6 +160,7 @@ or          { return OR_KW; }
 <IND_STRING>.    return yytext[0]; /* just in case: shouldn't be reached */
 
 {PATH}      { yylval->path = strdup(yytext); return PATH; }
+{HPATH}     { yylval->path = strdup(yytext); return HPATH; }
 {SPATH}     { yylval->path = strdup(yytext); return SPATH; }
 {URI}       { yylval->uri = strdup(yytext); return URI; }
 
diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y
index 7d877cd67862..f4648b902ba4 100644
--- a/src/libexpr/parser.y
+++ b/src/libexpr/parser.y
@@ -268,7 +268,7 @@ void yyerror(YYLTYPE * loc, yyscan_t scanner, ParseData * data, const char * err
 %token <id> ID ATTRPATH
 %token <e> STR IND_STR
 %token <n> INT
-%token <path> PATH SPATH
+%token <path> PATH HPATH SPATH
 %token <uri> URI
 %token IF THEN ELSE ASSERT WITH LET IN REC INHERIT EQ NEQ AND OR IMPL OR_KW
 %token DOLLAR_CURLY /* == ${ */
@@ -376,6 +376,14 @@ expr_simple
       $$ = stripIndentation(CUR_POS, data->symbols, *$2);
   }
   | PATH { $$ = new ExprPath(absPath($1, data->basePath)); }
+  | HPATH {
+      auto path = string{$1 + 1};
+      $$ = new ExprConcatStrings(CUR_POS, false, new vector<Expr *>{
+          new ExprPath("/"),
+          new ExprApp(new ExprVar(data->symbols.create("__getEnv")),
+              new ExprString(data->symbols.create("HOME"))),
+          new ExprString(data->symbols.create(path))});
+  }
   | SPATH {
       string path($1 + 1, strlen($1) - 2);
       $$ = new ExprApp(CUR_POS,