BVB Source Codes

rouge Show shell.rb Source code

Return Download rouge: download shell.rb Source code - Download rouge Source code - Type:.rb
  1. # -*- coding: utf-8 -*- #
  2.  
  3. module Rouge
  4.   module Lexers
  5.     class Shell < RegexLexer
  6.       title "shell"
  7.       desc "Various shell languages, including sh and bash"
  8.  
  9.       tag 'shell'
  10.       aliases 'bash', 'zsh', 'ksh', 'sh'
  11.       filenames '*.sh', '*.bash', '*.zsh', '*.ksh',
  12.                 '.bashrc', '.zshrc', '.kshrc', '.profile', 'PKGBUILD'
  13.  
  14.       mimetypes 'application/x-sh', 'application/x-shellscript'
  15.  
  16.       def self.analyze_text(text)
  17.         text.shebang?(/(ba|z|k)?sh/) ? 1 : 0
  18.       end
  19.  
  20.       KEYWORDS = %w(
  21.         if fi else while do done for then return function
  22.         select continue until esac elif in
  23.       ).join('|')
  24.  
  25.       BUILTINS = %w(
  26.         alias bg bind break builtin caller cd command compgen
  27.         complete declare dirs disown echo enable eval exec exit
  28.         export false fc fg getopts hash help history jobs kill let
  29.         local logout popd printf pushd pwd read readonly set shift
  30.         shopt source suspend test time times trap true type typeset
  31.         ulimit umask unalias unset wait
  32.       ).join('|')
  33.  
  34.       state :basic do
  35.         rule /#.*$/, Comment
  36.  
  37.         rule /\b(#{KEYWORDS})\s*\b/, Keyword
  38.         rule /\bcase\b/, Keyword, :case
  39.  
  40.         rule /\b(#{BUILTINS})\s*\b(?!\.)/, Name::Builtin
  41.  
  42.         rule /^\S*[\$%>#] +/, Generic::Prompt
  43.  
  44.         rule /(\b\w+)(=)/ do |m|
  45.           groups Name::Variable, Operator
  46.         end
  47.  
  48.         rule /[\[\]{}()=]/, Operator
  49.         rule /&&|\|\|/, Operator
  50.  
  51.         rule /<<</, Operator # here-string
  52.         rule /<<-?\s*(\'?)\\?(\w+)\1/ do |m|
  53.          lsh = Str::Heredoc
  54.          token lsh
  55.          heredocstr = Regexp.escape(m[2])
  56.  
  57.          push do
  58.            rule /\s*#{heredocstr}\s*\n/, lsh, :pop!
  59.            rule /.*?\n/, lsh
  60.          end
  61.        end
  62.      end
  63.  
  64.      state :double_quotes do
  65.        # NB: "abc$" is literally the string abc$.
  66.        # Here we prevent :interp from interpreting $" as a variable.
  67.        rule /(?:\$#?)?"/, Str::Double, :pop!
  68.        mixin :interp
  69.        rule /[^"`\\$]+/, Str::Double
  70.      end
  71.  
  72.      state :ansi_string do
  73.        rule /\\./, Str::Escape
  74.        rule /[^\\']+/, Str::Single
  75.         mixin :single_quotes
  76.       end
  77.  
  78.       state :single_quotes do
  79.         rule /'/, Str::Single, :pop!
  80.        rule /[^']+/, Str::Single
  81.       end
  82.  
  83.       state :data do
  84.         rule /\s+/, Text
  85.         rule /\\./, Str::Escape
  86.         rule /\$?"/, Str::Double, :double_quotes
  87.        rule /\$'/, Str::Single, :ansi_string
  88.  
  89.        # single quotes are much easier than double quotes - we can
  90.        # literally just scan until the next single quote.
  91.        # POSIX: Enclosing characters in single-quotes ( '' )
  92.        # shall preserve the literal value of each character within the
  93.        # single-quotes. A single-quote cannot occur within single-quotes.
  94.        rule /'/, Str::Single, :single_quotes
  95.  
  96.        rule /\*/, Keyword
  97.  
  98.        rule /;/, Text
  99.        rule /[^=\*\s{}()$"'`\\<]+/, Text
  100.        rule /\d+(?= |\Z)/, Num
  101.        rule /</, Text
  102.        mixin :interp
  103.      end
  104.  
  105.      state :curly do
  106.        rule /}/, Keyword, :pop!
  107.        rule /:-/, Keyword
  108.        rule /[a-zA-Z0-9_]+/, Name::Variable
  109.        rule /[^}:"`'$]+/, Punctuation
  110.         mixin :root
  111.       end
  112.  
  113.       state :paren do
  114.         rule /\)/, Keyword, :pop!
  115.         mixin :root
  116.       end
  117.  
  118.       state :math do
  119.         rule /\)\)/, Keyword, :pop!
  120.         rule %r([-+*/%^|&]|\*\*|\|\|), Operator
  121.         rule /\d+(#\w+)?/, Num
  122.         mixin :root
  123.       end
  124.  
  125.       state :case do
  126.         rule /\besac\b/, Keyword, :pop!
  127.         rule /\|/, Punctuation
  128.         rule /\)/, Punctuation, :case_stanza
  129.         mixin :root
  130.       end
  131.  
  132.       state :case_stanza do
  133.         rule /;;/, Punctuation, :pop!
  134.         mixin :root
  135.       end
  136.  
  137.       state :backticks do
  138.         rule /`/, Str::Backtick, :pop!
  139.        mixin :root
  140.      end
  141.  
  142.      state :interp do
  143.        rule /\\$/, Str::Escape # line continuation
  144.        rule /\\./, Str::Escape
  145.        rule /\$\(\(/, Keyword, :math
  146.        rule /\$\(/, Keyword, :paren
  147.        rule /\${#?/, Keyword, :curly
  148.        rule /`/, Str::Backtick, :backticks
  149.         rule /\$#?(\w+|.)/, Name::Variable
  150.       end
  151.  
  152.       state :root do
  153.         mixin :basic
  154.         mixin :data
  155.       end
  156.     end
  157.   end
  158. end
  159.  
downloadshell.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