BVB Source Codes

rouge Show moonscript.rb Source code

Return Download rouge: download moonscript.rb Source code - Download rouge Source code - Type:.rb
  1. # -*- coding: utf-8 -*- #
  2.  
  3. module Rouge
  4.   module Lexers
  5.     load_lexer 'lua.rb'
  6.  
  7.     class Moonscript < RegexLexer
  8.       title "MoonScript"
  9.       desc "Moonscript (http://www.moonscript.org)"
  10.       tag 'moonscript'
  11.       aliases 'moon'
  12.       filenames '*.moon'
  13.       mimetypes 'text/x-moonscript', 'application/x-moonscript'
  14.  
  15.       def initialize(opts={})
  16.         @function_highlighting = opts.delete(:function_highlighting) { true }
  17.         @disabled_modules = opts.delete(:disabled_modules) { [] }
  18.         super(opts)
  19.       end
  20.  
  21.       def self.analyze_text(text)
  22.         return 1 if text.shebang? 'moon'
  23.       end
  24.  
  25.       def builtins
  26.         return [] unless @function_highlighting
  27.  
  28.         @builtins ||= Set.new.tap do |builtins|
  29.           Rouge::Lexers::Lua.builtins.each do |mod, fns|
  30.             next if @disabled_modules.include? mod
  31.             builtins.merge(fns)
  32.           end
  33.         end
  34.       end
  35.  
  36.       state :root do
  37.         rule %r(#!(.*?)$), Comment::Preproc # shebang
  38.         rule //, Text, :main
  39.       end
  40.  
  41.       state :base do
  42.         ident = '(?:[\w_][\w\d_]*)'
  43.  
  44.         rule %r((?i)(\d*\.\d+|\d+\.\d*)(e[+-]?\d+)?'), Num::Float
  45.        rule %r((?i)\d+e[+-]?\d+), Num::Float
  46.        rule %r((?i)0x[0-9a-f]*), Num::Hex
  47.        rule %r(\d+), Num::Integer
  48.        rule %r(@#{ident}*), Name::Variable::Instance
  49.        rule %r([A-Z][\w\d_]*), Name::Class
  50.        rule %r("?[^"]+":), Literal::String::Symbol
  51.        rule %r(#{ident}:), Literal::String::Symbol
  52.        rule %r(:#{ident}), Literal::String::Symbol
  53.  
  54.        rule %r(\s+), Text::Whitespace
  55.        rule %r((==|~=|!=|<=|>=|\.\.\.|\.\.|->|=>|[=+\-*/%^<>#!\\])), Operator
  56.        rule %r([\[\]\{\}\(\)\.,:;]), Punctuation
  57.        rule %r((and|or|not)\b), Operator::Word
  58.  
  59.        keywords = %w{
  60.          break class continue do else elseif end extends for if import in
  61.          repeat return switch super then unless until using when with while
  62.        }
  63.        rule %r((#{keywords.join('|')})\b), Keyword
  64.        rule %r((local|export)\b), Keyword::Declaration
  65.        rule %r((true|false|nil)\b), Keyword::Constant
  66.  
  67.        rule %r([A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)?) do |m|
  68.          name = m[0]
  69.          if self.builtins.include?(name)
  70.            token Name::Builtin
  71.          elsif name =~ /\./
  72.            a, b = name.split('.', 2)
  73.            token Name, a
  74.            token Punctuation, '.'
  75.            token Name, b
  76.          else
  77.            token Name
  78.          end
  79.        end
  80.      end
  81.  
  82.      state :main do
  83.        rule %r(--.*$), Comment::Single
  84.        rule %r(\[(=*)\[.*?\]\1\])m, Str::Heredoc
  85.  
  86.        mixin :base
  87.  
  88.        rule %r('), Str::Single, :sqs
  89.         rule %r("), Str::Double, :dqs
  90.      end
  91.  
  92.      state :sqs do
  93.        rule %r('), Str::Single, :pop!
  94.        rule %r([^']+), Str::Single
  95.      end
  96.  
  97.      state :interpolation do
  98.        rule %r(\}), Str::Interpol, :pop!
  99.        mixin :base
  100.      end
  101.  
  102.      state :dqs do
  103.        rule %r(#\{), Str::Interpol, :interpolation
  104.        rule %r("), Str::Double, :pop!
  105.         rule %r(#[^{]), Str::Double
  106.         rule %r([^"#]+), Str::Double
  107.      end
  108.    end
  109.  end
  110. end
  111.  
downloadmoonscript.rb Source code - Download rouge Source code
Related Source Codes/Software:
spring-security-oauth - Support for adding OAuth1(a) and OAuth2 features (... 2017-04-23
Toucan - Fabulous Image Processing in Swift 2017-04-23
CoffeeScriptRedux - 2017-04-23
breakpoint - Really simple media queries in Sa 2017-04-23
libsvm - 2017-04-22
sphinx_rtd_theme - Sphinx theme for readthedocs.org 2017-04-23
BlurEffectForAndroidDesign - Sample to show how to implement blur graphical tri... 2017-04-23
mama2 - Mother plan - all firewood high flame 2017-04-23
JKeyboardPanelSwitch - For resolve the layout conflict when keybord & amp... 2017-04-23
viz.js - A hack to put Graphviz on the web. ... 2017-04-23
browser-diet - 2017-04-30
react-music - Make beats with React! http... 2017-04-30
java-code-styles - IntelliJ IDEA code style settings for Square's Jav... 2017-04-30
swing - A swipeable cards interface. The swipe-left/swipe-... 2017-04-30
qTip2 - qTip2 - Pretty powerful tooltips ... 2017-04-30
jo - JSON output from a shell 2017-04-30
Fluidbox - Replicating and improving the lightbox module seen... 2017-04-30
boto3 - AWS SDK for Python http://a... 2017-04-30
PreloadJS - PreloadJS makes preloading assets & getting ag... 2017-04-29
gotraining - Go Training Class Material : ... 2017-04-29

 Back to top