Class: Glslkit::Preprocessor
- Inherits:
-
Object
- Object
- Glslkit::Preprocessor
- Defined in:
- lib/glslkit/preprocessor.rb
Constant Summary collapse
- INCLUDE_PATTERN =
/\A[ \t]*#[ \t]*include[ \t]*(?:"([^"]+)"|<([^>]+)>)[ \t]*\z/- VERSION_PATTERN =
/\A[ \t]*#[ \t]*version\b/- EXTENSION_PATTERN =
/\A[ \t]*#[ \t]*extension\b/- PRAGMA_ONCE_PATTERN =
/\A[ \t]*#[ \t]*pragma[ \t]+once[ \t]*\z/
Instance Method Summary collapse
-
#initialize(resolver:, line_directives: true) ⇒ Preprocessor
constructor
A new instance of Preprocessor.
- #process(entry_request) ⇒ Object
Constructor Details
#initialize(resolver:, line_directives: true) ⇒ Preprocessor
Returns a new instance of Preprocessor.
17 18 19 20 |
# File 'lib/glslkit/preprocessor.rb', line 17 def initialize(resolver:, line_directives: true) @resolver = resolver @line_directives = line_directives end |
Instance Method Details
#process(entry_request) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/glslkit/preprocessor.rb', line 22 def process(entry_request) run = Run.new canonical_path, content = @resolver.read(entry_request, from: nil) (run, canonical_path, content) header = [] header << run.version if run.version header.concat(run.extensions) code = "#{(header + run.body).join("\n")}\n" # segmentsはbody基準(ヘッダを含まない)の行番号で溜めてあるので、 # ヘッダの行数だけ一括でずらしてからSourceMapに登録する。ヘッダの # 行数はexpand()完了まで確定しない(#versionがどのファイルで見つかる # かは走査してみないと分からない)ため、この2段階が必要になる。 run.segments.each do |body_line, file_index, source_line| run.source_map.add_segment(output_line: header.size + body_line, file_index: file_index, source_line: source_line) end Source.new( code: code, source_map: run.source_map, reflection: Reflection.new(code), digest: Digest.hexdigest(code) ) end |