Exemplo n.º 1
0
        public void TestParseCueTokenOtherOptions()
        {
            string cueLine = "WOUND_GLASS, 5";

            string cueToken = ScriptConstants.ParseCueToken(cueLine, out string postCueLine);

            Assert.AreEqual("WOUND_GLASS", cueToken);
            Assert.AreEqual("5", postCueLine);
        }
Exemplo n.º 2
0
        public void TestParseCueToken()
        {
            string cueLine = "PHASE";

            string cueToken = ScriptConstants.ParseCueToken(cueLine, out string postCueLine);

            Assert.AreEqual("PHASE", cueToken);
            Assert.AreEqual(null, postCueLine);
        }
Exemplo n.º 3
0
        public void TestParseCueTokenWithOptions()
        {
            string cueLine = "PHASE: chest_shirt_01";

            string cueToken = ScriptConstants.ParseCueToken(cueLine, out string postCueLine);

            Assert.AreEqual("PHASE", cueToken);
            Assert.AreEqual("chest_shirt_01", postCueLine);
        }
Exemplo n.º 4
0
        private static List <TokenNode> GenerateTokens(IEnumerable <LineMeta> lines)
        {
            var capturedTokens = new Stack <TokenNode>();

            foreach (LineMeta meta in lines)
            {
                string line = meta.Line;
                // ZLog.Info($"[PASS 1] {line}, tokens: {capturedTokens.Count}");

                if (!line.StartsWith(ParseTokens.CUE_CHAR, out string cueLine))
                {
                    TokenNode node;
                    if (line == "")
                    {
                        node = new TokenNode
                        {
                            Type       = TokenType.BREAK,
                            LineNumber = meta.LineNumber,
                        };
                    }
                    else
                    {
                        node = new TokenNode
                        {
                            Type       = TokenType.MISC,
                            LineNumber = meta.LineNumber,
                            Content    = line
                        };
                    }

                    capturedTokens.Push(node);
                    // TokenNode previousNode = capturedTokens.Peek();
                    //
                    // if (previousNode.Content == null)
                    // {
                    //     previousNode.Content = line;
                    // }
                    // else
                    // {
                    //     previousNode.Content += $"{Environment.NewLine}{line}";
                    // }
                }
                else
                {
                    string cueToken = ScriptConstants.ParseCueToken(cueLine, out string cueData);
                    // ZLog.Info($"[TOKEN] {cueToken}");

                    if (cueToken.StartsWith(ParseTokens.CUE_END_TOKEN, out string endCueToken))
                    {
                        // ZLog.Info($"Found end token: {cueToken}");

                        if (capturedTokens.Count == 0)
                        {
                            throw new InvalidOperationException($"No captured items for token group: {endCueToken}, line: {meta.LineNumber}");
                        }

                        List <TokenNode> nodes = new List <TokenNode>();
                        TokenNode        captureGroup;
                        while ((captureGroup = capturedTokens.Pop()) != null)
                        {
                            if (captureGroup.Keyword == endCueToken)
                            {
                                if (captureGroup.Children == null)
                                {
                                    // found matching start token, has empty children
                                    break;
                                }
                            }

                            // ZLog.Info($"{captureGroup.Keyword} part of capture group, remaining: {capturedTokens.Count}");
                            nodes.Add(captureGroup);

                            if (capturedTokens.Count == 0)
                            {
                                throw new InvalidOperationException(
                                          $"No start token to capture group found: {endCueToken}, line: {meta.LineNumber}");
                            }
                        }

                        nodes.Reverse();

                        captureGroup.Children = nodes;

                        capturedTokens.Push(captureGroup);


                        continue;
                    }

                    TokenNode node = new TokenNode
                    {
                        Type       = TokenType.KEYWORD,
                        LineNumber = meta.LineNumber,
                        Keyword    = cueToken,
                        Data       = cueData
                    };

                    capturedTokens.Push(node);
                    //
                    // ZLog.Info($"[NODE] {node}");
                }
            }

            // since this is built up in reverse, we have to reverse it again to negate the effect
            var result = capturedTokens.ToList();

            result.Reverse();
            return(result);
        }