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

Methods included from Token::Tokens

token

Constructor Details

This class inherits a constructor from Rouge::Lexer

Class Method Details

.analyze_text(text) ⇒ Object



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

def self.analyze_text(text)
  return 0
end

.keywordsObject



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

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



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

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

Instance Method Details

#token_for_final_id(id) ⇒ Object



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

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



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

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



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

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