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 MoonJson
22+ class Parser
23+ def parse : MoonJson
24+ dependencies = [] of Installer ::Depdency
25+ formatter = Formatter ::Config .new
26+ source_directories = %w[]
27+ test_directories = %w[]
28+ name = " "
29+
30+ application = Application .new(meta: {} of String => String , orientation: " " , theme_color: " " , css_prefix: " " , display: " " , title: " " , name: " " , head: " " , icon: " " )
31+
32+ @parser .read_object do |key |
33+ case key
34+ when " source-directories"
35+ source_directories = parse_source_directories
36+ when " test-directories"
37+ test_directories = parse_test_directories
38+ when " dependencies"
39+ dependencies = parse_dependencies
40+ when " application"
41+ application = parse_application
42+ when " formatter"
43+ formatter = parse_formatter
44+ when " moon-version"
45+ parse_moon_version
46+ when " name"
47+ name = parse_name
48+ else
49+ error! :root_invalid_key do
50+ snippet " The root object has an invalid key"
51+ end
52+ end
53+ end
54+
55+ rescue JSON ::ParseException
56+ error! :root_invalid do
57+ snippet " The root item should be an object"
58+ end
59+ end
60+ end
61+ end
62+ end
0 commit comments