All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.dingyi222666.monarch.languages.LanguageRuby.kt Maven / Gradle / Ivy

The newest version!
package io.github.dingyi222666.monarch.languages

import io.github.dingyi222666.monarch.common.*
 import io.github.dingyi222666.monarch.loader.dsl.*
import io.github.dingyi222666.monarch.types.IMonarchLanguage

public val RubyLanguage: IMonarchLanguage by lazy {
  buildMonarchLanguage {
    tokenPostfix = ".ruby"
    brackets {
      bracket("(",")","delimiter.parenthesis")
      bracket("{","}","delimiter.curly")
      bracket("[","]","delimiter.square")
    }
    keywords("__LINE__", "__ENCODING__", "__FILE__", "BEGIN", "END", "alias", "and", "begin",
        "break", "case", "class", "def", "defined?", "do", "else", "elsif", "end", "ensure", "for",
        "false", "if", "in", "module", "next", "nil", "not", "or", "redo", "rescue", "retry",
        "return", "self", "super", "then", "true", "undef", "unless", "until", "when", "while",
        "yield")
    "keywordops" and listOf("::", "..", "...", "?", ":", "=>")
    "builtins" and listOf("require", "public", "private", "include", "extend", "attr_reader",
        "protected", "private_class_method", "protected_class_method", "new")
    "declarations" and listOf("module", "class", "def", "case", "do", "begin", "for", "if", "while",
        "until", "unless")
    "linedecls" and listOf("def", "case", "do", "begin", "for", "if", "while", "until", "unless")
    operators("^", "&", "|", "<=>", "==", "===", "!~", "=~", ">", ">=", "<", "<=", "<<", ">>", "+",
        "-", "*", "/", "%", "**", "~", "+@", "-@", "[]", "[]=", "`", "+=", "-=", "*=", "**=", "/=",
        "^=", "%=", "<<=", ">>=", "&=", "&&=", "||=", "|=")
    symbols("[=>"
        }
        "%([qws])(@delim)".action {
          token = "string.${'$'}1.delim"
          switchTo = "@qstring.${'$'}1.${'$'}2.${'$'}2"
        }
        "%r\\(".action {
          token = "regexp.delim"
          switchTo = "@pregexp.(.)"
        }
        "%r\\[".action {
          token = "regexp.delim"
          switchTo = "@pregexp.[.]"
        }
        "%r\\{".action {
          token = "regexp.delim"
          switchTo = "@pregexp.{.}"
        }
        "%r<".action {
          token = "regexp.delim"
          switchTo = "@pregexp.<.>"
        }
        "%r(@delim)".action {
          token = "regexp.delim"
          switchTo = "@pregexp.${'$'}1.${'$'}1"
        }
        "%(x|W|Q?)\\(".action {
          token = "string.${'$'}1.delim"
          switchTo = "@qqstring.${'$'}1.(.)"
        }
        "%(x|W|Q?)\\[".action {
          token = "string.${'$'}1.delim"
          switchTo = "@qqstring.${'$'}1.[.]"
        }
        "%(x|W|Q?)\\{".action {
          token = "string.${'$'}1.delim"
          switchTo = "@qqstring.${'$'}1.{.}"
        }
        "%(x|W|Q?)<".action {
          token = "string.${'$'}1.delim"
          switchTo = "@qqstring.${'$'}1.<.>"
        }
        "%(x|W|Q?)(@delim)".action {
          token = "string.${'$'}1.delim"
          switchTo = "@qqstring.${'$'}1.${'$'}2.${'$'}2"
        }
        "%([rqwsxW]|Q?).".action {
          token = "invalid"
          next = "@pop"
        }
        ".".action {
          token = "invalid"
          next = "@pop"
        }
      }
      "qstring" rules {
        "\\\\${'$'}".token("string.${'$'}S2.escape")
        "\\\\.".token("string.${'$'}S2.escape")
        ".".action {
          cases {
            "${'$'}#==${'$'}S4" and {
              token = "string.${'$'}S2.delim"
              next = "@pop"
            }
            "${'$'}#==${'$'}S3" and {
              token = "string.${'$'}S2.delim"
              next = "@push"
            }
            "@default" and "string.${'$'}S2"
          }
        }
      }
      "qqstring" rules {
        "#".action("string.${'$'}S2.escape").state("@interpolated")
        include("@qstring")
      }
      whitespace {
        "[ \\t\\r\\n]+".token("")
        "^\\s*=begin\\b".action("comment").state("@comment")
        "#.*${'$'}".token("comment")
      }
      comment {
        "[^=]+".token("comment")
        "^\\s*=begin\\b".token("comment.invalid")
        "^\\s*=end\\b.*".action("comment").state("@pop")
        "[=]".token("comment")
      }
    }
  }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy