public static BracesToken Parse(Token parent, Scope scope) { var startPos = scope.File.Position; scope.File.MoveNext(); var indentScope = scope.IndentNonRoot(); indentScope.Hint |= ScopeHint.SuppressFunctionDefinition; var retToken = new BracesToken(parent, scope, new Span(startPos, startPos)); retToken._openToken = new BraceToken(retToken, scope, new Span(startPos, scope.File.Position), retToken, true); retToken._tokens.Add(retToken._openToken); var closeToken = null as Token; var done = false; while (!scope.File.EndOfFile && !done) { var token = scope.File.ParseToken(retToken, indentScope); if (token == null) break; if (token.GetType() == typeof(OperatorToken) && (token as OperatorToken).Text == "}") { retToken._closeToken = new BraceToken(retToken, scope, token.Span, retToken, false); retToken._tokens.Add(retToken._closeToken); done = true; } else { retToken._tokens.Add(token); } } retToken.Span = new Span(startPos, scope.File.Position); return retToken; }
public FunctionToken(Token parent, Scope scope, IEnumerable<Token> tokens, Token dataTypeToken, IdentifierToken nameToken, BracketsToken argsToken, BracesToken scopeToken) : base(parent, scope, new Span(tokens.First().Span.Start, tokens.Last().Span.End)) { _tokens = tokens.ToArray(); _dataTypeToken = dataTypeToken; if (_dataTypeToken != null) _dataTypeToken.Parent = this; _nameToken = nameToken; _nameToken.Parent = this; _argsToken = argsToken; _argsToken.Parent = this; _scopeToken = scopeToken; _scopeToken.Parent = this; foreach (var tok in _tokens) tok.Parent = this; }
public BraceToken(Token parent, Scope scope, Span span, BracesToken braces, bool open) : base(parent, scope, span) { _braces = braces; _open = open; }