Skip to content

Commit 88f8bf9

Browse files
committed
type_checkers: css definition
1 parent 4d8f4e7 commit 88f8bf9

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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 TypeChecker
22+
CSS_PROPERTY_NAMES =
23+
{{ read_file("#{__DIR__}/../assets/css_properties").strip.lines }}
24+
25+
def check(node : Ast::CssDefinition) : Checkable
26+
node.value.each do |item|
27+
type =
28+
case item
29+
when Ast::Node
30+
resolve item
31+
else
32+
STRING
33+
end
34+
35+
unless node.name.starts_with?('-')
36+
error! :css_definition_no_property do
37+
block do
38+
text "There is no CSS property with the name:"
39+
bold %("#{node.name}")
40+
end
41+
42+
snippet node
43+
end unless CSS_PROPERTY_NAMES.includes?(node.name)
44+
end
45+
46+
error! :css_definition_type_mismatch do
47+
block do
48+
text "The type of the value for the CSS property"
49+
bold %("#{node.name}")
50+
text "is invalid."
51+
end
52+
53+
snippet "expecting one of these types:", "String\nNumber"
54+
snippet "Instead it is:", type
55+
snippet "The css definition in question is here:", node
56+
end unless Comparer.matches_any?(type, [STRING, NUMBER])
57+
end
58+
59+
VOID
60+
end
61+
end
62+
end

0 commit comments

Comments
 (0)