Esempio n. 1
0
		public void Render(TaskAbstract parent,TokenLine tokens,StreamWriter fs)
		{
			var t = tokens.Find(Token.Create(TokenKind.ReservedWord,SubKindCSharp.Class));
			if (t== null)
			{
				fs.Write("//ERROR No class found");
				return;
			}
			
			var clase = t.Next;
			if (clase== null)
			{
				fs.Write("//ERROR No class name found");
				return;
			}
			Variables.AddOrReplace(parent?.Variables);
			Variables.AddOrReplace("$class",clase.Value.Value);
			Variables.AddOrReplace("$stripclass", clase.Value.Value.RemoveLeft("_",No));
			Variables.AddOrReplace("$accessmodified",tokens.FirstOrDefault(to => to.IsSubKind(TokenKind.ReservedWord, SubKindCSharp.AccessModifier))?.Value);
			Variables.AddOrReplace("$static", tokens.FirstOrDefault(to => to.Value=="static")?.Value);
			foreach(var c in Code)
			{
				var cad = c.ReplaceAll(Variables, Yes);
				fs.WriteLine(cad);
			}
		}
Esempio n. 2
0
        public void ShouldSetAllPropertiesWhenCreatingATokenLineAndOnlyTheLineIsSupplied()
        {
            var line      = new[] { new StringToken(TokenType.Word, 1, 1, 1, "hello") };
            var tokenLine = new TokenLine(line);

            CollectionAssert.AreEqual(line, tokenLine.GetAll());
            CollectionAssert.AreEqual(new TokenLine[] { }, tokenLine.Children.GetAll());
        }
Esempio n. 3
0
        public void ShouldSetAllPropertiesWhenCreatingATokenLine()
        {
            var line      = new[] { new StringToken(TokenType.Word, 1, 1, 1, "hello") };
            var children  = new TokenLine[] { };
            var tokenLine = new TokenLine(line, children);

            CollectionAssert.AreEqual(line, tokenLine.GetAll());
            CollectionAssert.AreEqual(children, tokenLine.Children.GetAll());
        }
Esempio n. 4
0
		public override TokenLine Grouping(TokenLine ts)
		{
			var res = new TokenLine();
			var p = ts.First;
			var t = p?.Value;
			while(p!= null)
			{
				var p2 = p.Next;
				var p3 = p2?.Next;
				if ((p!= null)&&(p2!= null)&(p3!= null)&&(p.Value.IsKind(TokenKind.Word))&& (p2.Value.Value==".") && (p.Value.IsKind(TokenKind.Word)))
                {
					t = Token.Group(TokenKind.Word, 0, t, p2.Value, p3.Value);
					ts.Remove(p2);
					ts.Remove(p3);
				}
				res.Add(t);
				p = p.Next;
				t = p?.Value;
			}
			return res;
		}
Esempio n. 5
0
		public void Render(TaskAbstract parent, TokenLine tokens, StreamWriter fs)
		{
			var t = tokens.Find(Token.Create(TokenKind.ReservedWord,SubKindCSharp.Namespace));
			if (t == null)
			{
				fs.Write("//ERROR No namespace found");
				return;
			}
			var nspace = t.Next;
			if (nspace == null)
			{
				fs.Write("//ERROR No namespace name found");
				return;
			}
			Variables.AddOrReplace(parent?.Variables);
			Variables.AddOrReplace("$namespace", nspace.Value.Value);
			foreach (var c in Code)
			{
				var cad = c.ReplaceAll(Variables, Yes);
				fs.WriteLine(cad);
			}
		}
Esempio n. 6
0
		public void Render(TaskAbstract parent, TokenLine tokens, StreamWriter fs)
		{
			var ret = tokens.Find(Token.ANY(TokenKind.Word));
			if (ret == null)
			{
				fs.Write("//ERROR No return type found");
				return;
			}
			var name = ret.Next;
			Variables.AddOrReplace(parent.Variables);

			Variables.AddOrReplace("$accessmodified", tokens.FirstOrDefault(to => to.IsSubKind(TokenKind.ReservedWord, SubKindCSharp.AccessModifier))?.Value);
			Variables.AddOrReplace("$static", tokens.FirstOrDefault(to => to.Value == "static")?.Value);
			Variables.AddOrReplace("$returntype", ret.Value.Value);
			Variables.AddOrReplace("$name", name.Value.Value);
			Variables.AddOrReplace("$stripname", name.Value.Value.RemoveLeft("_",No));
			foreach (var c in Code)
			{
				var cad = c.ReplaceAll(Variables, Yes);
				fs.WriteLine(cad);
			}
		}
Esempio n. 7
0
        public void DoubleValue()
        {
            var res = new TokenLine("   2.3     6,6   a.s");

            Assert.AreEqual(res, new[] { "2.3", "6", ",", "6", "a", ".", "s" });
        }
Esempio n. 8
0
        ITokenLine ParseLine(IEnumerator <TokenData> it, int parentBlockColumn)
        {
            var line      = new TokenLine();
            var expectEnd = false;

            while (true)
            {
                ExtractLineTokens(it, line);
                if (_done)
                {
                    return(line);
                }

                while (true)
                {
                    var nextColumn = GetIndent(it);
                    switch (it.Current.Type)
                    {
                    case Token.NewLineIndentation:
                        if (nextColumn < parentBlockColumn)
                        {
                            return(line);                                    // end of the parent block
                        }
                        if (nextColumn == parentBlockColumn && !expectEnd)
                        {
                            return(line);                                                   // normal line break
                        }
                        // line continuation
                        while (true)
                        {
                            if (!it.MoveNext())
                            {
                                _done = true;
                            }
                            if (_done)
                            {
                                return(line);           // should not happen (final NewLineIndentation was filtered)
                            }
                            ExtractLineTokens(it, line);
                            if (_done)
                            {
                                return(line);
                            }

                            if (it.Current.Type != Token.NewLineIndentation)
                            {
                                break;
                            }
                            //var continueColumn = GetIndent(it);
                            //if (continueColumn >= nextColumn) continue; // next line is part of the continuation
                            // TODO report continuation error
                            // TODO handling: add lines to a block as well
                        }
                        continue;

                    case Token.BlockEndIndentation:
                        if (nextColumn < parentBlockColumn)
                        {
                            if (expectEnd)
                            {
                                // TODO report missing end
                                // handling terminate line anyways
                            }
                            return(line);    // end of the parent block
                        }
                        if (nextColumn == parentBlockColumn)
                        {
                            if (!expectEnd)
                            {
                                // TODO report unexpected end
                                // handling terminate line anyways
                            }
                            if (!it.MoveNext())
                            {
                                _done = true;                     // consume the end
                            }
                            return(line);
                        }
                        // TODO report nested end
                        // handling: ignored
                        if (!it.MoveNext())
                        {
                            _done = true;
                            return(line);
                        }
                        continue;

                    case Token.BlockStartIndentation:
                        expectEnd = true;
                        var current = it.Current;
                        if (nextColumn < parentBlockColumn)
                        {
                            // TODO report missing end
                            // handling: add empty block and finish line
                            current.Data = new BlockLiteral();
                            line.Tokens.Add(current);
                            return(line);
                        }
                        if (nextColumn == parentBlockColumn)
                        {
                            // empty block
                            current.Data = new BlockLiteral();
                            line.Tokens.Add(current);
                            if (!it.MoveNext())
                            {
                                _done = true;
                            }
                            continue;
                        }
                        current.Data = ParseBlock(it, nextColumn);
                        line.Tokens.Add(current);
                        continue;
                    }
                    break;
                }
            }
        }
Esempio n. 9
0
        public void EmptyLine()
        {
            var res = new TokenLine("");

            Assert.AreEqual(res, new string[] { });
        }
Esempio n. 10
0
        public void LongLine(string line, string[] tokens)
        {
            var res = new TokenLine(line);

            Assert.AreEqual(res, tokens);
        }
Esempio n. 11
0
        public void TestScreenedByQuote(string line, string[] tokens)
        {
            var res = new TokenLine(line);

            Assert.AreEqual(res, tokens);
        }
Esempio n. 12
0
        public void SpacesDoNotAffect(string line, string[] tokens)
        {
            var res = new TokenLine(line);

            Assert.AreEqual(res, tokens);
        }
Esempio n. 13
0
        public void TwoWordsClose(string line, string[] tokens)
        {
            var res = new TokenLine(line);

            Assert.AreEqual(res, tokens);
        }
Esempio n. 14
0
        public void TwoWordsDividedBySpace(string line, string[] tokens)
        {
            var res = new TokenLine(line);

            Assert.AreEqual(res, tokens);
        }
Esempio n. 15
0
        public void OnlySpaces()
        {
            var res = new TokenLine("           ");

            Assert.AreEqual(res, new string[] { });
        }