Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added sample code for dynamically compiled MGrammar parser

  • Loading branch information...
commit 54251c06d79f69850a1358234cc4fb4bf59ac28b 1 parent 57d8ecc
Charlie Robbins authored February 02, 2010
23  JsonmParser.cs
@@ -37,6 +37,27 @@ static JsonmParser()
37 37
                 MImage grammar = new MImage(@"jsonm.mx");
38 38
                 grammarParser = grammar.ParserFactories["jsonm.jsonm"].Create();
39 39
                 grammarParser.GraphBuilder = new NodeGraphBuilder();
  40
+                
  41
+                // Remark: Alternate parser generation approach; causes grammarParser.Parse to return a SimpleNode
  42
+                ////using (var r = new StreamReader(Environment.CurrentDirectory + @"\..\..\jsonm.mg"))
  43
+                ////{
  44
+                ////    var options = new CompilerOptions
  45
+                ////    {
  46
+                ////        Sources = 
  47
+                ////        { 
  48
+                ////            new TextItem
  49
+                ////            {
  50
+                ////                Name = "I Need A Name",
  51
+                ////                Reader = r,
  52
+                ////                ContentType = TextItemType.MGrammar
  53
+                ////            }
  54
+                ////        }
  55
+                ////    };
  56
+
  57
+                ////    CompilationResults results = Compiler.Compile(options);
  58
+                ////    grammarParser = results.ParserFactories["jsonm.jsonm"].Create();
  59
+                ////}
  60
+
40 61
             }
41 62
             catch (Exception ex)
42 63
             {
@@ -111,7 +132,7 @@ private JsonmObject ParseObject(Node objectNode)
111 132
             foreach (Tuple<string, object> pair in keyValuePairs)
112 133
             {
113 134
                 jsonmObject.TrySetMember(
114  
-                    new DynamicDictionaryMemberBinder(pair.Item1, false), 
  135
+                    new DynamicDictionaryMemberBinder(pair.Item1, false),
115 136
                     pair.Item2);
116 137
             }
117 138
 
4  jsonm.csproj
@@ -50,7 +50,9 @@
50 50
     <Reference Include="System.Runtime.Serialization" />
51 51
   </ItemGroup>
52 52
   <ItemGroup>
53  
-    <MCompile Include="jsonm.mg" />
  53
+    <MCompile Include="jsonm.mg">
  54
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
  55
+    </MCompile>
54 56
   </ItemGroup>
55 57
   <ItemGroup>
56 58
     <Compile Include="DynamicDictionary.cs" />

0 notes on commit 54251c0

Please sign in to comment.
Something went wrong with that request. Please try again.