Class: Rouge::Lexers::SML

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

Constant Summary

Constants inherited from RegexLexer

RegexLexer::MAX_NULL_SCANS

Constants included from Token::Tokens

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

Class Method Summary collapse

Instance Method Summary collapse

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, title

Methods included from Token::Tokens

token

Constructor Details

This class inherits a constructor from Rouge::Lexer

Class Method Details

.analyze_text(text) ⇒ Object



31
32
33
# File 'lib/rouge/lexers/sml.rb', line 31

def self.analyze_text(text)
  return 0
end

.keywordsObject



14
15
16
17
18
19
20
21
22
# File 'lib/rouge/lexers/sml.rb', line 14

def self.keywords
  @keywords ||= Set.new %w(
    abstype and andalso as case datatype do else end exception
    fn fun handle if in infix infixr let local nonfix of op open
    orelse raise rec then type val with withtype while
    eqtype functor include sharing sig signature struct structure
    where
  )
end

.symbolic_reservedObject



24
25
26
# File 'lib/rouge/lexers/sml.rb', line 24

def self.symbolic_reserved
  @symbolic_reserved ||= Set.new %w(: | = => -> # :>)
end

Instance Method Details

#token_for_final_id(id) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/rouge/lexers/sml.rb', line 64

def token_for_final_id(id)
  if self.class.keywords.include? id or self.class.symbolic_reserved.include? id
    Error
  else
    Name
  end
end

#token_for_id(id) ⇒ Object



72
73
74
75
76
77
78
79
80
# File 'lib/rouge/lexers/sml.rb', line 72

def token_for_id(id)
  if self.class.keywords.include? id
    Keyword::Reserved
  elsif self.class.symbolic_reserved.include? id
    Punctuation
  else
    Name
  end
end

#token_for_id_with_dot(id) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/rouge/lexers/sml.rb', line 56

def token_for_id_with_dot(id)
  if self.class.keywords.include? id
    Error
  else
    Name::Namespace
  end
end