ripex 0.2.0

Multi-language structural parsing and fact extraction.
Documentation
use crate::span::Span;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum TokenKind {
    Ident,
    // Keywords
    Abstract,
    As,
    Base,
    Bool,
    Break,
    Byte,
    Case,
    Catch,
    Char,
    Checked,
    Class,
    Const,
    Continue,
    Decimal,
    Default,
    Delegate,
    Do,
    Double,
    Else,
    Enum,
    Event,
    Explicit,
    Extern,
    False,
    Finally,
    Fixed,
    Float,
    For,
    ForEach,
    Goto,
    If,
    Implicit,
    In,
    Int,
    Interface,
    Internal,
    Is,
    Lock,
    Long,
    Namespace,
    New,
    Null,
    Object,
    Operator,
    Out,
    Override,
    Params,
    Private,
    Protected,
    Public,
    Readonly,
    Ref,
    Return,
    Sbyte,
    Sealed,
    Short,
    Sizeof,
    Stackalloc,
    Static,
    String,
    Struct,
    Switch,
    This,
    Throw,
    True,
    Try,
    Typeof,
    Uint,
    Ulong,
    Unchecked,
    Unsafe,
    Ushort,
    Using,
    Virtual,
    Void,
    Volatile,
    While,
    // Contextual keywords
    Add,
    And,
    Alias,
    Async,
    Await,
    By,
    Descending,
    Equals,
    From,
    Get,
    Global,
    Group,
    Init,
    Into,
    Join,
    Let,
    Managed,
    Nameof,
    Not,
    NotNull,
    On,
    Or,
    Orderby,
    Partial,
    Record,
    Remove,
    Select,
    Set,
    Unmanaged,
    Value,
    Var,
    When,
    Where,
    With,
    Yield,
    // Type keywords
    Nint,
    Nuint,
    StringInterpolated,

    // Operators
    Plus,
    Minus,
    Star,
    Slash,
    Percent,
    PlusPlus,
    MinusMinus,
    Ampersand,
    Pipe,
    Caret,
    Tilde,
    Exclamation,
    LtLt,
    GtGt,
    EqEq,
    Ne,
    Lt,
    Gt,
    LtEq,
    GtEq,
    AmpersandAmpersand,
    PipePipe,
    QuestionQuestion,
    Dot,
    DotDot,
    DotDotDot,
    Arrow,
    FatArrow,
    Colon,
    ColonColon,
    Semicolon,
    Comma,
    Question,
    QuestionDot,
    LParen,
    RParen,
    LBrace,
    RBrace,
    LBracket,
    RBracket,
    Eq,
    PlusEq,
    MinusEq,
    StarEq,
    SlashEq,
    PercentEq,
    AmpersandEq,
    PipeEq,
    CaretEq,
    LtLtEq,
    GtGtEq,
    QuestionQuestionEq,
    Nullable,
    Hash,
    At,

    IntLit,
    UIntLit,
    LongLit,
    ULongLit,
    FloatLit,
    DoubleLit,
    DecimalLit,
    CharLit,
    StringLit,
    VerbatimStringLit,
    InterpolatedStringLit,
    TrueLit,
    FalseLit,
    NullLit,

    Eof,
    Error,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Token {
    pub kind: TokenKind,
    pub span: Span,
    pub value: String,
    pub leading_comments: Vec<Comment>,
    pub has_line_break: bool,
}

impl Token {
    pub fn new(kind: TokenKind, span: Span) -> Self {
        Token {
            kind,
            span,
            value: String::new(),
            leading_comments: Vec::new(),
            has_line_break: false,
        }
    }
    pub fn with_value(kind: TokenKind, span: Span, value: impl Into<String>) -> Self {
        Token {
            kind,
            span,
            value: value.into(),
            leading_comments: Vec::new(),
            has_line_break: false,
        }
    }
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Comment {
    pub kind: CommentKind,
    pub span: Span,
    pub text: String,
}

impl Comment {
    pub fn new(kind: CommentKind, span: Span, text: impl Into<String>) -> Self {
        Comment {
            kind,
            span,
            text: text.into(),
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CommentKind {
    Line,
    Block,
    Doc,
}