public void TestSkipNewLine() { var tokeniser = new PhpTokeniser("\n\n\n \n $"); tokeniser.SkipWhitespace(); Assert.Equal('$', tokeniser.GetTrivia()); }
public void TestSkipLineComment() { var tokeniser = new PhpTokeniser(@" // // line 1 // line 2 // // // $"); tokeniser.SkipWhitespace(); Assert.Equal('$', tokeniser.GetTrivia()); }
public static PhpArrayElementSyntaxNode Parse(PhpTokeniser tokeniser) { tokeniser.SkipWhitespace(); PhpStringLiteralSyntaxNode key = tokeniser.GetTrivia() switch { '\'' => PhpStringLiteralSyntaxNode.Parse(tokeniser), '"' => PhpStringLiteralSyntaxNode.Parse(tokeniser), _ => throw tokeniser.ConstructError($"Invalid array value identifier ({tokeniser.GetTrivia()}).") }; tokeniser.SkipWhitespace(); tokeniser.SkipPattern(new[] { '=', '>' }); tokeniser.SkipWhitespace(); PhpSyntaxNode value = tokeniser.GetTrivia() switch { '\'' => PhpStringLiteralSyntaxNode.Parse(tokeniser), '"' => PhpStringLiteralSyntaxNode.Parse(tokeniser), '[' => PhpArraySyntaxNode.Parse(tokeniser), _ => throw tokeniser.ConstructError($"Invalid array value identifier ({tokeniser.GetTrivia()}).") }; tokeniser.SkipWhitespace(); // Skip trailing trivia for this element. if (tokeniser.TryGetTrivia(out var trivia) && trivia == ',') { tokeniser.Advance(); } tokeniser.SkipWhitespace(); return(new PhpArrayElementSyntaxNode(key, value)); } } }
public void TestSkipBlockComment() { var tokeniser = new PhpTokeniser(@" /** * This is a * BLOCK COMMENT!! */ /**/ $"); tokeniser.SkipWhitespace(); Assert.Equal('$', tokeniser.GetTrivia()); }