This project is read-only.

Song Sample

Dsl

Song MaryHadALittleLamb 250
B4 A4 G4 A4
B4 B4 B4 -
A4 A4 A4 -
B4 D5 D5 -
B4 A4 G4 A4
B4 B4 B4 -
B4 A4 A4 B4
A4 G4 -  -

Grammar

namespace DynamicSongBuilder:
    import DynamicSongBuilder.Ast;
    import MetaSharp.Transformation.Parsing.Common;
    import MetaSharp.Transformation.Parsing.Extensions;

    grammar SongGrammar < BasicParser:

        Main =  m:Declare n:Identifier d:Number b:Bar*
            -> Song {
                Name = n, 
                Duration = d, 
                Bars = b };

        Rest = "-";
        Note = a:"A".."G";
        Sharp = "#";
        Flat = "b";
        Declare = "Song";
		
        RestOrNote 
            =  n:Rest -> Note { Key = n, Octave = 0 }
            |  n:Note s:Sharp o:Number -> Note { Key = n.tostring(s), Octave = o }
            |  [n:Note f:Flat o:Number -> Note { Key = n.tostring(f), Octave = o }]
            |  [n:Note o:Number -> Note { Key = n, Octave = o }];

        Bar = n:RestOrNote#4 -> Bar { Notes = n };
    end
end

Template

namespace Samples.Song.Templates:
    import System;
    import System.Collections.Generic;
    import SongRuntime;

    @for(song in {Song}):
    public class {song.Name} as Song:
        public constructor 
            super({song.Duration}):
                Bar bar;
            @for(b in {song.Bars}):
                bar = new Bar(this);
                @for(n in {b.Notes}):
                    bar.Notes.Add(new Note(bar, "{n.Key}", {n.Octave}));
                @end
                this.Bars.Add(bar);
            @end
        end
    end
    @end
end

Generated

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30128.1
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace Samples.Song.Templates {
    
    #line 2 "C:/Users/justin/Projects/CodePlex/MetaSharp/src/samples/SongSample/SongSample/MaryHadALittleLamb.song"
    using System;
    
    #line default
    #line hidden
    
    #line 3 "C:/Users/justin/Projects/CodePlex/MetaSharp/src/samples/SongSample/SongSample/MaryHadALittleLamb.song"
    using System.Collections.Generic;
    
    #line default
    #line hidden
    
    #line 4 "C:/Users/justin/Projects/CodePlex/MetaSharp/src/samples/SongSample/SongSample/MaryHadALittleLamb.song"
    using SongRuntime;
    
    #line default
    #line hidden
    
    
    
    #line 7 "C:/Users/justin/Projects/CodePlex/MetaSharp/src/samples/SongSample/SongSample/MaryHadALittleLamb.song"
    public class MaryHadALittleLamb : Song {
        
        
        #line 8 "C:/Users/justin/Projects/CodePlex/MetaSharp/src/samples/SongSample/SongSample/MaryHadALittleLamb.song"
        public MaryHadALittleLamb() : 
                base(250) {
            
            #line 10 "C:/Users/justin/Projects/CodePlex/MetaSharp/src/samples/SongSample/SongSample/MaryHadALittleLamb.song"
            Bar bar;
            
            #line default
            #line hidden
            
            #line 12 "C:/Users/justin/Projects/CodePlex/MetaSharp/src/samples/SongSample/SongSample/MaryHadALittleLamb.song"
            bar = new Bar(this);
            
            #line default
            #line hidden
            bar.Notes.Add(new Note(bar, "B", 4));
            bar.Notes.Add(new Note(bar, "A", 4));
            bar.Notes.Add(new Note(bar, "G", 4));
            bar.Notes.Add(new Note(bar, "A", 4));
            this.Bars.Add(bar);
            
            #line 24 "C:/Users/justin/Projects/CodePlex/MetaSharp/src/samples/SongSample/SongSample/MaryHadALittleLamb.song"
            bar = new Bar(this);
            
            #line default
            #line hidden
            bar.Notes.Add(new Note(bar, "B", 4));
            bar.Notes.Add(new Note(bar, "B", 4));
            bar.Notes.Add(new Note(bar, "B", 4));
            bar.Notes.Add(new Note(bar, "-", 0));
            this.Bars.Add(bar);
            
            #line 36 "C:/Users/justin/Projects/CodePlex/MetaSharp/src/samples/SongSample/SongSample/MaryHadALittleLamb.song"
            bar = new Bar(this);
            
            #line default
            #line hidden
            bar.Notes.Add(new Note(bar, "A", 4));
            bar.Notes.Add(new Note(bar, "A", 4));
            bar.Notes.Add(new Note(bar, "A", 4));
            bar.Notes.Add(new Note(bar, "-", 0));
            this.Bars.Add(bar);
            
            #line 48 "C:/Users/justin/Projects/CodePlex/MetaSharp/src/samples/SongSample/SongSample/MaryHadALittleLamb.song"
            bar = new Bar(this);
            
            #line default
            #line hidden
            bar.Notes.Add(new Note(bar, "B", 4));
            bar.Notes.Add(new Note(bar, "D", 5));
            bar.Notes.Add(new Note(bar, "D", 5));
            bar.Notes.Add(new Note(bar, "-", 0));
            this.Bars.Add(bar);
            
            #line 60 "C:/Users/justin/Projects/CodePlex/MetaSharp/src/samples/SongSample/SongSample/MaryHadALittleLamb.song"
            bar = new Bar(this);
            
            #line default
            #line hidden
            bar.Notes.Add(new Note(bar, "B", 4));
            bar.Notes.Add(new Note(bar, "A", 4));
            bar.Notes.Add(new Note(bar, "G", 4));
            bar.Notes.Add(new Note(bar, "A", 4));
            this.Bars.Add(bar);
            
            #line 72 "C:/Users/justin/Projects/CodePlex/MetaSharp/src/samples/SongSample/SongSample/MaryHadALittleLamb.song"
            bar = new Bar(this);
            
            #line default
            #line hidden
            bar.Notes.Add(new Note(bar, "B", 4));
            bar.Notes.Add(new Note(bar, "B", 4));
            bar.Notes.Add(new Note(bar, "B", 4));
            bar.Notes.Add(new Note(bar, "-", 0));
            this.Bars.Add(bar);
            
            #line 84 "C:/Users/justin/Projects/CodePlex/MetaSharp/src/samples/SongSample/SongSample/MaryHadALittleLamb.song"
            bar = new Bar(this);
            
            #line default
            #line hidden
            bar.Notes.Add(new Note(bar, "B", 4));
            bar.Notes.Add(new Note(bar, "A", 4));
            bar.Notes.Add(new Note(bar, "A", 4));
            bar.Notes.Add(new Note(bar, "B", 4));
            this.Bars.Add(bar);
            
            #line 96 "C:/Users/justin/Projects/CodePlex/MetaSharp/src/samples/SongSample/SongSample/MaryHadALittleLamb.song"
            bar = new Bar(this);
            
            #line default
            #line hidden
            bar.Notes.Add(new Note(bar, "A", 4));
            bar.Notes.Add(new Note(bar, "G", 4));
            bar.Notes.Add(new Note(bar, "-", 0));
            bar.Notes.Add(new Note(bar, "-", 0));
            this.Bars.Add(bar);
        }
        
        #line default
        #line hidden
    }
    
    #line default
    #line hidden
}

Last edited Mar 27, 2010 at 6:08 PM by justinc, version 2

Comments

No comments yet.