public HlslLexer(SourceText text, ParserOptions options = null, IIncludeFileSystem includeFileSystem = null) { _includeFileResolver = new IncludeFileResolver(includeFileSystem ?? new DummyFileSystem()); _directives = DirectiveStack.Empty; if (options != null) { foreach (var define in options.PreprocessorDefines) { var lexer = new HlslLexer( SourceText.From($"#define {define.Key} {define.Value}", "__ConfiguredPreprocessorDefinitions__.hlsl")); lexer._mode = LexerMode.Directive; lexer.ExpandMacros = false; var dp = new DirectiveParser(lexer, _directives); var directive = dp.ParseDirective(true, true, false); _directives = directive.ApplyDirectives(_directives); } } _options = options ?? new ParserOptions(); ExpandMacros = true; _rootText = text; FileSegments = new List <FileSegment>(); _includeStack = new Stack <IncludeContext>(); PushIncludeContext(text); }
public HlslLexer(SourceText text, ParserOptions options = null, IIncludeFileSystem fileSystem = null) { _fileSystem = fileSystem ?? new DummyFileSystem(); _directives = DirectiveStack.Empty; if (options != null) foreach (var define in options.PreprocessorDefines) { _directives = _directives.Add(new Directive(new ObjectLikeDefineDirectiveTriviaSyntax( null, null, SyntaxFactory.ParseToken(define), new List<SyntaxToken> { SyntaxFactory.ParseToken("1") }, null, true))); } ExpandMacros = true; FileSegments = new List<FileSegment>(); _includeStack = new Stack<IncludeContext>(); PushIncludeContext(text); }
private SyntaxNode LexSingleDirective( bool isActive, bool endIsActive, bool afterNonWhitespaceOnLine, List <SyntaxNode> triviaList) { _start = _charReader.Position; if (char.IsWhiteSpace(_charReader.Current)) { ReadWhitespace(); AddTrivia(triviaList, SyntaxKind.WhitespaceTrivia); } var saveMode = _mode; var saveExpandMacros = ExpandMacros; _mode = LexerMode.Directive; ExpandMacros = false; var dp = new DirectiveParser(this, _directives); var directive = dp.ParseDirective(isActive, endIsActive, afterNonWhitespaceOnLine); if (!isActive || directive.Kind != SyntaxKind.IncludeDirectiveTrivia) { triviaList.Add(directive); } _directives = directive.ApplyDirectives(_directives); ExpandMacros = saveExpandMacros; _mode = saveMode; // Directive parser sometimes leaves charReader at start of token *after* the one we want. _charReader.Reset(directive.GetLastChildToken().GetLastSpanIncludingTrivia().End); _start = _charReader.Position; return(directive); }
private SyntaxNode LexSingleDirective( bool isActive, bool endIsActive, bool afterNonWhitespaceOnLine, List<SyntaxNode> triviaList) { _start = _charReader.Position; if (char.IsWhiteSpace(_charReader.Current)) { ReadWhitespace(); AddTrivia(triviaList, SyntaxKind.WhitespaceTrivia); } var saveMode = _mode; var saveExpandMacros = ExpandMacros; _mode = LexerMode.Directive; ExpandMacros = false; var dp = new DirectiveParser(this, _directives); var directive = dp.ParseDirective(isActive, endIsActive, afterNonWhitespaceOnLine); if (!isActive || directive.Kind != SyntaxKind.IncludeDirectiveTrivia) triviaList.Add(directive); _directives = directive.ApplyDirectives(_directives); ExpandMacros = saveExpandMacros; _mode = saveMode; // Directive parser sometimes leaves charReader at start of token *after* the one we want. _charReader.Reset(directive.GetLastChildToken().GetLastSpanIncludingTrivia().End); _start = _charReader.Position; return directive; }
public DirectiveParser(HlslLexer lexer, DirectiveStack directiveStack) : base(lexer, LexerMode.Directive) { _lexer = lexer; _directiveStack = directiveStack; }