|
| 1 | +# ----------------------------------------------------------------------- |
| 2 | +# This file is part of MoonScript |
| 3 | +# |
| 4 | +# MoonSript is free software: you can redistribute it and/or modify |
| 5 | +# it under the terms of the GNU General Public License as published by |
| 6 | +# the Free Software Foundation, either version 3 of the License, or |
| 7 | +# (at your option) any later version. |
| 8 | +# |
| 9 | +# MoonSript is distributed in the hope that it will be useful, |
| 10 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +# GNU General Public License for more details. |
| 13 | +# |
| 14 | +# You should have received a copy of the GNU General Public License |
| 15 | +# along with MoonSript. If not, see <https://www.gnu.org/licenses/>. |
| 16 | +# |
| 17 | +# Copyright (C) 2025 Krisna Pranav, MoonScript Developers |
| 18 | +# ----------------------------------------------------------------------- |
| 19 | + |
| 20 | +module MoonScript |
| 21 | + class SourceMapGenerator |
| 22 | + alias Mapping = Tuple(Ast::Node | Nil, Tuple(Int32, Int32), String | Nil) |
| 23 | + |
| 24 | + getter mappings = {} of Int32 => Array(Mapping) |
| 25 | + |
| 26 | + getter sources_content = [] of String |
| 27 | + |
| 28 | + getter sources_names = [] of String |
| 29 | + |
| 30 | + getter sources = [] of String |
| 31 | + |
| 32 | + def initialize(unsorted: Deque(Mapping), @generated) |
| 33 | + unsorted.each do |item| |
| 34 | + (mappings[item[1][0]] ||= [] of Mapping) << item |
| 35 | + end |
| 36 | + end |
| 37 | + |
| 38 | + def get_source_index(file) |
| 39 | + sources.index(file.path) || begin |
| 40 | + sources_content << file.contents |
| 41 | + sources << file.path |
| 42 | + sources.size - 1 |
| 43 | + end |
| 44 | + end |
| 45 | +end |
0 commit comments