lib_ruby_parser/source/
magic_comment.rs

1use crate::Loc;
2
3/// An enum of all magic comment kinds
4#[repr(C)]
5#[derive(Debug, Clone, PartialEq)]
6pub enum MagicCommentKind {
7    /// `# encoding: ... comment`
8    Encoding,
9
10    /// `# frozen_string_literal: true/false` comment
11    FrozenStringLiteral,
12
13    /// `# warn_indent: true/false` comment
14    WarnIndent,
15
16    /// `# shareable_constant_value: ...` comment
17    ShareableConstantValue,
18}
19
20/// Representation of a magic comment in Ruby
21#[repr(C)]
22#[derive(Debug, Clone, PartialEq)]
23pub struct MagicComment {
24    /// Kind of a magic comment
25    pub kind: MagicCommentKind,
26
27    /// Location of the "key":
28    ///
29    /// ```text
30    /// # encoding: utf-8
31    ///   ~~~~~~~~
32    /// ```
33    pub key_l: Loc,
34
35    /// Location of the "value":
36    ///
37    /// ```text
38    /// # encoding: utf-8
39    ///             ~~~~~
40    /// ```
41    pub value_l: Loc,
42}