Class: Rouge::Lexers::TCL
- Inherits:
-
RegexLexer
- Object
- Rouge::Lexer
- RegexLexer
- Rouge::Lexers::TCL
- 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
Constants included from Token::Tokens
Token::Tokens::Num, Token::Tokens::Str
Class Method Summary collapse
- .analyze_text(text) ⇒ Object
- .gen_command_state(name = '') ⇒ Object
- .gen_delimiter_states(name, close, opts = {}) ⇒ Object
Methods inherited from RegexLexer
append, #delegate, get_state, #get_state, #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, assert_utf8!, #debug, default_options, demo, demo_file, desc, filenames, find, find_fancy, guess, guess_by_filename, guess_by_mimetype, guess_by_source, guesses, #initialize, lex, #lex, mimetypes, #option, #options, #reset!, #stream_tokens, tag, #tag
Methods included from Token::Tokens
Constructor Details
This class inherits a constructor from Rouge::Lexer
Class Method Details
.analyze_text(text) ⇒ Object
11 12 13 14 15 |
# File 'lib/rouge/lexers/tcl.rb', line 11 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
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/rouge/lexers/tcl.rb', line 56 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
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/rouge/lexers/tcl.rb', line 80 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 |