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); } }
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()); }
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()); }
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; }
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); } }
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); } }
public void DoubleValue() { var res = new TokenLine(" 2.3 6,6 a.s"); Assert.AreEqual(res, new[] { "2.3", "6", ",", "6", "a", ".", "s" }); }
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; } } }
public void EmptyLine() { var res = new TokenLine(""); Assert.AreEqual(res, new string[] { }); }
public void LongLine(string line, string[] tokens) { var res = new TokenLine(line); Assert.AreEqual(res, tokens); }
public void TestScreenedByQuote(string line, string[] tokens) { var res = new TokenLine(line); Assert.AreEqual(res, tokens); }
public void SpacesDoNotAffect(string line, string[] tokens) { var res = new TokenLine(line); Assert.AreEqual(res, tokens); }
public void TwoWordsClose(string line, string[] tokens) { var res = new TokenLine(line); Assert.AreEqual(res, tokens); }
public void TwoWordsDividedBySpace(string line, string[] tokens) { var res = new TokenLine(line); Assert.AreEqual(res, tokens); }
public void OnlySpaces() { var res = new TokenLine(" "); Assert.AreEqual(res, new string[] { }); }