Skip to content

Commit

Permalink
Added sample code for dynamically compiled MGrammar parser
Browse files Browse the repository at this point in the history
  • Loading branch information
indexzero committed Feb 2, 2010
1 parent 57d8ecc commit 54251c0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
23 changes: 22 additions & 1 deletion JsonmParser.cs
Expand Up @@ -37,6 +37,27 @@ static JsonmParser()
MImage grammar = new MImage(@"jsonm.mx"); MImage grammar = new MImage(@"jsonm.mx");
grammarParser = grammar.ParserFactories["jsonm.jsonm"].Create(); grammarParser = grammar.ParserFactories["jsonm.jsonm"].Create();
grammarParser.GraphBuilder = new NodeGraphBuilder(); 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) catch (Exception ex)
{ {
Expand Down Expand Up @@ -111,7 +132,7 @@ private JsonmObject ParseObject(Node objectNode)
foreach (Tuple<string, object> pair in keyValuePairs) foreach (Tuple<string, object> pair in keyValuePairs)
{ {
jsonmObject.TrySetMember( jsonmObject.TrySetMember(
new DynamicDictionaryMemberBinder(pair.Item1, false), new DynamicDictionaryMemberBinder(pair.Item1, false),
pair.Item2); pair.Item2);
} }


Expand Down
4 changes: 3 additions & 1 deletion jsonm.csproj
Expand Up @@ -50,7 +50,9 @@
<Reference Include="System.Runtime.Serialization" /> <Reference Include="System.Runtime.Serialization" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<MCompile Include="jsonm.mg" /> <MCompile Include="jsonm.mg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</MCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="DynamicDictionary.cs" /> <Compile Include="DynamicDictionary.cs" />
Expand Down

0 comments on commit 54251c0

Please sign in to comment.