private bool ParseDollar(TemplateStream stream, TokenList tokens, ContextStack context, ScopeStack scope) { if (stream.Current != '$' || scope.Current == Scope.Block) return false; var next = stream.Peek(); if (next == '$') { stream.Advance(2); return true; } if (char.IsLetter(next)) { scope.Push(Scope.Statement); stream.Advance(); return true; } if (next == '{') { scope.Push(Scope.Block); stream.Advance(); return true; } return false; }
private bool ParseDollar(TemplateStream stream, TokenList tokens, ContextStack context, ScopeStack scope) { if (stream.Current != '$' || scope.Current == Scope.Block) { return(false); } var next = stream.Peek(); if (next == '$') { stream.Advance(2); return(true); } if (char.IsLetter(next)) { scope.Push(Scope.Statement); stream.Advance(); return(true); } if (next == '{') { scope.Push(Scope.Block); stream.Advance(); return(true); } return(false); }
private bool ParseComment(TemplateStream stream, TokenList tokens, ContextStack context) { if (stream.Current != '/' || stream.Peek() != '/') return false; var start = stream.Position; var line = stream.Line; while (stream.Advance()) { if (stream.Peek() == '\r') { stream.Advance(); break; } } tokens.Add(new Token(start, stream.Position - start, line, TokenType.Comment, context.Current)); return true; }
private bool ParseStatement(TemplateStream stream, TokenList tokens, ContextStack context, ScopeStack scope) { if (scope.Current == Scope.Statement) { scope.Pop(); } else if (scope.Current == Scope.Block) { var previous = stream.Peek(-1); if (previous == '$' || char.IsLetterOrDigit(previous)) { return(false); } } else { return(false); } var name = stream.PeekWord(); var identifier = context.Current.GetIdentifier(name); if (identifier != null) { tokens.Add(new Token(stream.Position, name.Length, stream.Line, TokenType.Identifier, context.Current, identifier.QuickInfo)); stream.Advance(name.Length); if (identifier.Type == IdentifierType.Indexed) { if (stream.Current == '(') { scope.Push(Scope.Filter); } if (stream.Current == '[') { scope.Push(Scope.Template); context.Push(name, stream.Position); } } else if (identifier.Type == IdentifierType.Boolean) { if (stream.Current == '[') { scope.Push(Scope.True); } } return(true); } return(false); }
private bool ParseComment(TemplateStream stream, TokenList tokens, ContextStack context) { if (stream.Current != '/' || stream.Peek() != '/') { return(false); } var start = stream.Position; var line = stream.Line; while (stream.Advance()) { if (stream.Peek() == '\r') { stream.Advance(); break; } } tokens.Add(new Token(start, stream.Position - start, line, TokenType.Comment, context.Current)); return(true); }
private bool ParseStatement(TemplateStream stream, TokenList tokens, ContextStack context, ScopeStack scope) { if (scope.Current == Scope.Statement) { scope.Pop(); } else if (scope.Current == Scope.Block) { var previous = stream.Peek(-1); if (previous == '$' || char.IsLetterOrDigit(previous)) return false; } else { return false; } var name = stream.PeekWord(); var identifier = context.Current.GetIdentifier(name); if (identifier != null) { tokens.Add(new Token(stream.Position, name.Length, stream.Line, TokenType.Identifier, context.Current, identifier.QuickInfo)); stream.Advance(name.Length); if (identifier.Type == IdentifierType.Indexed) { if (stream.Current == '(') scope.Push(Scope.Filter); if (stream.Current == '[') { scope.Push(Scope.Template); context.Push(name, stream.Position); } } else if (identifier.Type == IdentifierType.Boolean) { if (stream.Current == '[') scope.Push(Scope.True); } return true; } return false; }