Permalink
Browse files

Added sample code for dynamically compiled MGrammar parser

  • Loading branch information...
indexzero committed Feb 2, 2010
1 parent 57d8ecc commit 54251c06d79f69850a1358234cc4fb4bf59ac28b
Showing with 25 additions and 2 deletions.
  1. +22 −1 JsonmParser.cs
  2. +3 −1 jsonm.csproj
View
@@ -37,6 +37,27 @@ static JsonmParser()
MImage grammar = new MImage(@"jsonm.mx");
grammarParser = grammar.ParserFactories["jsonm.jsonm"].Create();
grammarParser.GraphBuilder = new NodeGraphBuilder();
+
+ // Remark: Alternate parser generation approach; causes grammarParser.Parse to return a SimpleNode
+ ////using (var r = new StreamReader(Environment.CurrentDirectory + @"\..\..\jsonm.mg"))
+ ////{
+ //// var options = new CompilerOptions
+ //// {
+ //// Sources =
+ //// {
+ //// new TextItem
+ //// {
+ //// Name = "I Need A Name",
+ //// Reader = r,
+ //// ContentType = TextItemType.MGrammar
+ //// }
+ //// }
+ //// };
+
+ //// CompilationResults results = Compiler.Compile(options);
+ //// grammarParser = results.ParserFactories["jsonm.jsonm"].Create();
+ ////}
+
}
catch (Exception ex)
{
@@ -111,7 +132,7 @@ private JsonmObject ParseObject(Node objectNode)
foreach (Tuple<string, object> pair in keyValuePairs)
{
jsonmObject.TrySetMember(
- new DynamicDictionaryMemberBinder(pair.Item1, false),
+ new DynamicDictionaryMemberBinder(pair.Item1, false),
pair.Item2);
}
View
@@ -50,7 +50,9 @@
<Reference Include="System.Runtime.Serialization" />
</ItemGroup>
<ItemGroup>
- <MCompile Include="jsonm.mg" />
+ <MCompile Include="jsonm.mg">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </MCompile>
</ItemGroup>
<ItemGroup>
<Compile Include="DynamicDictionary.cs" />

0 comments on commit 54251c0

Please sign in to comment.