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(\r \t \v)
CHARS =
lambda { |list| Regexp.new %/[#{list.join}]/  }
NOT_CHARS =
lambda { |list| Regexp.new %/[^#{list.join}]/ }

Constants inherited from RegexLexer

RegexLexer::MAX_NULL_SCANS

Constants included from Token::Tokens

Token::Tokens::Num, Token::Tokens::Str

Instance Attribute Summary

Attributes inherited from Rouge::Lexer

#options

Class Method Summary collapse

Methods inherited from RegexLexer

append, #delegate, #goto, #group, #groups, #in_state?, #pop!, prepend, #push, #recurse, replace_state, #reset!, #reset_stack, #stack, start, start_procs, state, #state, #state?, state_definitions, states, #step, #stream_tokens, #token

Methods inherited from Rouge::Lexer

aliases, all, #as_bool, #as_lexer, #as_list, #as_string, #as_token, #bool_option, continue_lex, #continue_lex, debug_enabled?, demo, demo_file, desc, detectable?, disable_debug!, enable_debug!, filenames, find, find_fancy, guess, guess_by_filename, guess_by_mimetype, guess_by_source, guesses, #hash_option, #initialize, lex, #lex, #lexer_option, #list_option, lookup_fancy, mimetypes, option, option_docs, #reset!, #stream_tokens, #string_option, #tag, tag, title, #token_option, #with

Methods included from Token::Tokens

token

Constructor Details

This class inherits a constructor from Rouge::Lexer

Class Method Details

.detect?(text) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
# File 'lib/rouge/lexers/tcl.rb', line 13

def self.detect?(text)
  return true if text.shebang? 'tclsh'
  return true if text.shebang? 'wish'
  return true if text.shebang? 'jimsh'
end

.gen_command_state(name = '') ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/rouge/lexers/tcl.rb', line 58

def self.gen_command_state(name='')
  state(:"command#{name}") do
    rule %r/#/, Comment, :comment

    mixin :word

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

    rule %r/#{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



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

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

  state :"params_in_#{name}" do
    rule close do
      token Punctuation
      pop! 2
    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