MmlSourceLineSet ProcessPragmaLine(MmlLine line) { result.Lexer.SetCurrentInput (line); line.Location.LinePosition++; // get identifier var identifier = result.Lexer.ReadNewIdentifier (); switch (identifier) { case "include": result.Lexer.SkipWhitespaces (true); return ProcessIncludeLine (line); case "variable": result.Lexer.SkipWhitespaces (true); return ProcessVariableLine (line); case "macro": result.Lexer.SkipWhitespaces (true); return ProcessMacroLine (line); case "comment": in_comment_mode = true; return null; case "endcomment": in_comment_mode = false; return null; case "define": case "conditional": case "meta": case "basecount": break; default: throw MmlError (line.Location, String.Format ("Unexpected preprocessor directive: {0}", identifier)); } result.Lexer.SkipWhitespaces (true); var ps = new MmlPragmaSource (identifier); ps.Lines.Add (line); result.Pragmas.Add (ps); return ps; }
void ParsePragmaLines(MmlPragmaSource src) { source.Lexer.SetCurrentInput (src); switch (src.Name) { default: throw new NotImplementedException (); case "basecount": source.Lexer.ExpectNext (MmlTokenType.NumberLiteral); result.BaseCount = (int) source.Lexer.Value; MmlValueExpr.BaseCount = result.BaseCount; break; case "conditional": var category = source.Lexer.ReadNewIdentifier (); switch (category) { case "block": source.Lexer.SkipWhitespaces (true); while (true) { source.Lexer.NewIdentifierMode = true; source.Lexer.ExpectNext (MmlTokenType.Identifier); string s = (string) source.Lexer.Value; result.Conditional.Blocks.Add (s); source.Lexer.SkipWhitespaces (); if (!source.Lexer.Advance () || source.Lexer.CurrentToken != MmlTokenType.Comma) break; source.Lexer.SkipWhitespaces (); } if (source.Lexer.Advance ()) throw new MmlException ("Extra conditional tokens", source.Lexer.Line.Location); source.Lexer.NewIdentifierMode = false; break; case "track": source.Lexer.SkipWhitespaces (true); var tracks = source.Lexer.ReadRange ().ToArray (); result.Conditional.Tracks.AddRange (tracks); source.Lexer.SkipWhitespaces (); if (source.Lexer.Advance ()) throw new MmlException ("Extra conditional tokens", source.Lexer.Line.Location); break; default: throw new MmlException (String.Format ("Unexpected compilation condition type '{0}'", category), source.Lexer.Line.Location); } break; case "meta": source.Lexer.NewIdentifierMode = true; var identifier = source.Lexer.ReadNewIdentifier (); source.Lexer.SkipWhitespaces (true); var text = source.Lexer.ReadStringLiteral (); switch (identifier) { case "title": case "copyright": case "text": break; default: throw new MmlException (String.Format ("Invalid #meta directive argument: {0}", identifier), source.Lexer.Line.Location); } result.MetaTexts.Add (new KeyValuePair<byte,string> (meta_map [identifier], text)); source.Lexer.NewIdentifierMode = false; break; case "define": source.Lexer.NewIdentifierMode = true; identifier = source.Lexer.ReadNewIdentifier (); source.Lexer.SkipWhitespaces (true); if (aliases.ContainsKey (identifier)) Console.WriteLine ("Warning: overwriting definition {0}, redefined at {1}", identifier, source.Lexer.Line.Location); aliases [identifier] = source.Lexer.Line.Text.Substring (source.Lexer.Line.Location.LinePosition); source.Lexer.NewIdentifierMode = false; break; } }