Esempio n. 1
0
        public void Process()
        {
            // process pragmas
            foreach (var ps in source.Pragmas)
                ParsePragmaLines (ps);

            // add built-in variables
            result.Variables.Add (new MmlVariableDefinition ("__timeline_position", null) { Type = MmlDataType.Number });
            var bc = new MmlVariableDefinition ("__base_count", null) { Type = MmlDataType.Number };
            bc.DefaultValueTokens.Add (new MmlToken () { TokenType = MmlTokenType.NumberLiteral, Value = result.BaseCount });
            result.Variables.Add (bc);

            // process variables
            foreach (var vs in source.Variables)
                ParseVariableLines (vs);

            // process macros, recursively
            foreach (var ms in source.Macros)
                ParseMacroLines (ms);

            // process tracks
            foreach (var ts in source.Tracks)
                ParseTrackLines (ts);
        }
Esempio n. 2
0
        void ParseVariableList(List<MmlVariableDefinition> vars, bool isVariable)
        {
            int count = 0;
            while (true) {
                if (source.Lexer.CurrentToken == MmlTokenType.OpenCurly)
                    break; // go to parse body
                if (count > 0) {
                    source.Lexer.ExpectCurrent (MmlTokenType.Comma);
                    source.Lexer.NewIdentifierMode = true;
                    source.Lexer.Advance ();
                }
                source.Lexer.ExpectCurrent (MmlTokenType.Identifier);
                var arg = new MmlVariableDefinition ((string) source.Lexer.Value, source.Lexer.Line.Location);
                vars.Add (arg);
                count++;

                // FIXME: possibly use MmlToken.Colon?
                source.Lexer.SkipWhitespaces ();
                if (source.Lexer.Line.PeekChar () != ':') {
                    arg.Type = MmlDataType.Number;
                    if (!source.Lexer.Advance () && isVariable)
                        return;
                    continue;
                }
                source.Lexer.Line.ReadChar ();

                source.Lexer.NewIdentifierMode = false;
                if (!source.Lexer.Advance ())
                    throw source.Lexer.LexerError ("type name is expected after ':' in macro argument definition");
                switch (source.Lexer.CurrentToken) {
                case MmlTokenType.KeywordNumber:
                case MmlTokenType.KeywordString:
                case MmlTokenType.KeywordLength:
                case MmlTokenType.KeywordBuffer:
                    break;
                default:
                    throw new MmlException (String.Format ("Data type name is expected, but got {0}", source.Lexer.CurrentToken), source.Lexer.Line.Location);
                }
                arg.Type = (MmlDataType) source.Lexer.Value;
                source.Lexer.SkipWhitespaces ();
                if (source.Lexer.Line.PeekChar () != '=') {
                    if (!source.Lexer.Advance () && isVariable)
                        return;
                    continue;
                }
                source.Lexer.Line.ReadChar ();

                bool loop = true;
                while (loop) {
                    if (!source.Lexer.Advance ()) {
                        if (isVariable)
                            return;
                        throw source.Lexer.LexerError ("Incomplete argument default value definition");
                    }
                    switch (source.Lexer.CurrentToken) {
                    case MmlTokenType.Comma:
                    case MmlTokenType.OpenCurly:
                        loop = false;
                        continue;
                    }

                    arg.DefaultValueTokens.Add (source.Lexer.CreateParsedToken ());
                }
            }
        }
Esempio n. 3
0
        MmlSemanticVariable BuildVariableDeclaration(MmlVariableDefinition src)
        {
            var ret = new MmlSemanticVariable (src.Name, src.Type);

            if (src.DefaultValueTokens.Count == 0)
                return ret;

            var stream = new TokenStream (src.DefaultValueTokens, src.Location);
            ret.DefaultValue = new Parser.MmlParser (stream.Source).ParseExpression ();

            return ret;
        }