]> git.mdlowis.com Git - archive/dlang.git/commitdiff
Implemented hash map syntax
authorMike D. Lowis <mike@mdlowis.com>
Tue, 6 Mar 2012 01:47:30 +0000 (20:47 -0500)
committerMike D. Lowis <mike@mdlowis.com>
Tue, 6 Mar 2012 01:47:30 +0000 (20:47 -0500)
example.dl
source/dllexer/dllexer.h
source/dlparser/dlparser.cpp
source/dlparser/dlparser.h
source/main.cpp

index bbc0c66309ba24e5d5dcc4e9d6c615a7088d86c0..c3a4a7248d9a9fdea2b85ddab22f345b683c77ed 100644 (file)
@@ -40,6 +40,13 @@ foo = "12345"[2]
 # SYMBOL
 foo = $some_symbol
 
+# MAP
+foo = {
+    $foo : 1 + 1,
+    $bar : 2 + 2,
+    $stuff : 3 + 3
+}
+
 #% if [
 #    (Ex Bk) : exec_if($1, $2),
 #    (Ex Bk Bk) : exec_if($1, $2, $3)
index 620d7664e78e461f10503e17b8f58ad6b2e6f0de..562566e4ff7ef973a2ece0c8428d48ccde09108f 100644 (file)
@@ -15,6 +15,7 @@ typedef enum TokenTypes
     LIST     = 5,
     VECTOR   = 6,
     FUNC     = 7,
+    MAP      = 8,
 
     // Symbols
     LBRACK   = 10,
index 22b396569b0b8087c2e0a18c6dac75b06e5122b8..3b2e0aca05886553e56123b3fb3f9ff3dddc04b8 100644 (file)
@@ -284,10 +284,27 @@ AST* DLParser::Literal(void)
     return node;
 }
 
+// MapLiteral = '{' (Literal ':' LogicalExpr)* '}'
 AST* DLParser::MapLiteral(void)
 {
     AST* ret = NULL;
-    throw Exception(lookaheadToken(1).line(), lookaheadToken(1).column());
+
+    //throw Exception(lookaheadToken(1).line(),lookaheadToken(1).column());
+    match(LBRACE);
+    do
+    {
+        if( lookaheadType(1) == COMMA ) consume();
+
+        AST* child = Literal();
+        match(SEP);
+        child = _new AST(SEP, 2, child, LogicalExpr());
+
+        ret = ((ret == NULL) ? _new AST(MAP) : ret);
+        ret->addChild(child);
+    }
+    while( lookaheadType(1) == COMMA );
+    match(RBRACE);
+
     return ret;
 }
 
index b3553d0841a17425c1bec8edf261e89f6fe0c6af..8fca4ff9bbab380e98b9b8ae66d497883c561de9 100644 (file)
@@ -60,6 +60,7 @@ class DLParser : public BTParser
         //         | STRING
         //         | SYMBOL
         //
+        // MapLiteral = '{' (Literal ':' AssignExpr)* '}'
         // VectorLiteral = '[' ExpList ']'
         //
         // ListLiteral = '(' ExpList ')'
index d9db18d53068599f37e80e079d39b0ebcf0c4852..0493636080493f396783be9ff22c96ca1bc89d42 100644 (file)
@@ -20,7 +20,6 @@ int main(int argc, char** argv)
     {
         string input_fname(argv[1]);
         string temp_fname = createTempFileName( input_fname );
-        (void)temp_fname;
         DLParser parser;
         ASTPrinter* visitor = NULL;