Class: Rouge::Lexers::TCL

Inherits:
RegexLexer show all
Defined in:
lib/rouge/lexers/tcl.rb

Constant Summary collapse

KEYWORDS =
%w(
  after apply array break catch continue elseif else error
  eval expr for foreach global if namespace proc rename return
  set switch then trace unset update uplevel upvar variable
  vwait while
)
BUILTINS =
%w(
  append bgerror binary cd chan clock close concat dde dict
  encoding eof exec exit fblocked fconfigure fcopy file
  fileevent flush format gets glob history http incr info interp
  join lappend lassign lindex linsert list llength load loadTk
  lrange lrepeat lreplace lreverse lsearch lset lsort mathfunc
  mathop memory msgcat open package pid pkg::create pkg_mkIndex
  platform platform::shell puts pwd re_syntax read refchan
  regexp registry regsub scan seek socket source split string
  subst tell time tm unknown unload
)
OPEN =
%w| \( \[ \{ " |
CLOSE =
%w| \) \] \} |
ALL =
OPEN + CLOSE
END_LINE =
CLOSE + %w(; \n)
END_WORD =
END_LINE + %w(\s)
CHARS =
lambda { |list| Regexp.new %/[#{list.join}]/  }
NOT_CHARS =
lambda { |list| Regexp.new %/[^#{list.join}]/ }

Constants inherited from RegexLexer

RegexLexer::MAX_NULL_SCANS

Class Method Summary collapse

Methods inherited from RegexLexer

#delegate, get_state, #get_state, #group, #in_state?, #pop!, #push, #reset!, #reset_stack, #run_callback, #run_rule, #stack, start, start_procs, #state, state, #state?, states, #step, #stream_tokens, #token

Methods inherited from Rouge::Lexer

aliases, all, assert_utf8!, #debug, default_options, demo, demo_file, desc, filenames, find, find_fancy, guess, guess_by_filename, guess_by_mimetype, guess_by_source, #initialize, #lex, lex, mimetypes, #option, #options, register, #reset!, #stream_tokens, tag, #tag

Constructor Details

This class inherits a constructor from Rouge::Lexer

Class Method Details

.analyze_text(text) ⇒ Object



9
10
11
12
13
# File 'lib/rouge/lexers/tcl.rb', line 9

def self.analyze_text(text)
  return 1 if text.shebang? 'tclsh'
  return 1 if text.shebang? 'wish'
  return 1 if text.shebang? 'jimsh'
end

.gen_command_state(name = '') ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/rouge/lexers/tcl.rb', line 54

def self.gen_command_state(name='')
  state(:"command#{name}") do
    mixin :word

    rule /##{NOT_CHARS[END_LINE]}+/, 'Comment.Single'

    rule /(?=#{CHARS[END_WORD]})/ do
      push :"params#{name}"
    end

    rule /#{NOT_CHARS[END_WORD]}+/ do |m|
      if KEYWORDS.include? m[0]
        token 'Keyword'
      elsif BUILTINS.include? m[0]
        token 'Name.Builtin'
      else
        token 'Text'
      end
    end

    mixin :whitespace
  end
end

.gen_delimiter_states(name, close, opts = {}) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/rouge/lexers/tcl.rb', line 78

def self.gen_delimiter_states(name, close, opts={})
  gen_command_state("_in_#{name}")

  state :"params_in_#{name}" do
    rule close do
      token 'Punctuation'
      pop!; pop!
    end

    # mismatched delimiters.  Braced strings with mismatched
    # closing delimiters should be okay, since this is standard
    # practice, like {]]]]}
    if opts[:strict]
      rule CHARS[CLOSE - [close]], 'Error'
    else
      rule CHARS[CLOSE - [close]], 'Text'
    end

    mixin :params
  end

  state name do
    rule close, 'Punctuation', :pop!
    mixin :"command_in_#{name}"
  end
end