Class: Rouge::Lexers::AddmusicK

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

Constant Summary collapse

KEYWORDS =
Set.new %w(
  samples instruments instrument path default optimized pack
)

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

Instance Method Summary collapse

Methods inherited from RegexLexer

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

Methods inherited from Rouge::Lexer

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

Methods included from Token::Tokens

token

Constructor Details

#initializeAddmusicK

Returns a new instance of AddmusicK.



24
25
26
27
28
# File 'lib/rouge/lexers/addmusick.rb', line 24

def initialize(*)
  super

  @highlight_macros = bool_option(:macros) { true }
end

Class Method Details

.detect?(analyzer) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
# File 'lib/rouge/lexers/addmusick.rb', line 18

def self.detect?(analyzer)
  return true if analyzer.match?(/\A(\s+|;.*?$)*#spc\s*[{]/i)
  return true if analyzer.match?(/\A(\s+|;.*?$)*#option smwvtable\b/i)
  return true if analyzer.match?(/\A(\s+|;.*?$)*#amk \d/i)
end

Instance Method Details

#note_tokenObject



30
31
32
33
34
# File 'lib/rouge/lexers/addmusick.rb', line 30

def note_token
  return Str if @last == :rest
  return Name::Function if @last == :fade || @last == :arp
  Str::Symbol
end

#step(state, stream) ⇒ Object

override [jneen] This override is required because AddmusicK has an extremely free-form macro system that doesn't "look like a function call" the same way that normal preproc macros do. They are quite literally arbitrary characters that pre-empt other tokens, in all states.

AddmusicK is technically even more lenient than this about where macros can show up, e.g. "F=v123" will attempt to substitute into $FF twice. Neither Ramekin nor this lexer support that.



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rouge/lexers/addmusick.rb', line 45

def step(state, stream)
  if @highlight_macros
    @macros.reverse_each do |macro|
      if stream.skip(macro)
        token Comment::Preproc
        return true
      end
    end
  end

  super(state, stream)
end