Class: Rouge::Lexers::Dafny

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

Constant Summary

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

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, #as_bool, #as_lexer, #as_list, #as_string, #as_token, assert_utf8!, #bool_option, #continue_lex, continue_lex, debug_enabled?, demo, demo_file, desc, detect?, 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

Instance Method Details

#rootObject

IMPORTANT: Rules are ordered, which allows later rules to be simpler than they would otherwise be



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/rouge/lexers/dafny.rb', line 63

state :root do
  rule %r(/\*), Comment::Multiline, :comment
  rule %r(//.*?$), Comment::Single
  rule %r(\*/), Error          # should not have closing comment in :root
                               # is an improperly nested comment

  rule %r/'#{cchar}'/, Str::Char           # standard or escape char
  rule %r/'#{uchar}'/, Str::Char           # unicode char
  rule %r/'[^'\n\r]*'/, Error              # bad any other enclosed char
  rule %r/'[^'\n\r]*$/, Error              # bad unclosed char

  rule %r/"(?:#{schar}|#{uchar})*"/, Str::Double        # valid string
  rule %r/".*"/, Error                     # anything else that is closed
  rule %r/".*$/, Error                     # bad unclosed string

  rule %r/@"([^"]|"")*"/, Str::Other     # valid verbatim string
  rule %r/@".*/m, Error             # anything else , multiline unclosed


  rule %r/#{digits}\.#{digits}(?!#{idchar})/, Num::Float
  rule %r/0b#{bin_digits}(?!#{idchar})/, Num::Bin
  rule %r/0b#{idchar}*/, Error
  rule %r/0x#{hex_digits}(?!#{idchar})/, Num::Hex
  rule %r/0x#{idchar}*/, Error
  rule %r/#{digits}(?!#{idchar})/, Num::Integer
  rule %r/_(?!#{idchar})/, Name
  rule %r/_[0-9_]+[_]?(?!#{idchar})/, Error
  rule %r/[0-9_]+_(?!#{idchar})/, Error
  rule %r/[0-9]#{idchar}+/, Error

  rule %r/#{arrayType}/, Keyword::Type
  rule %r/#{bvType}/, Keyword::Type

  rule id do |m|
    if types.include?(m[0])
      token Keyword::Type
    elsif literals.include?(m[0])
      token Keyword::Constant
    elsif textOperators.include?(m[0])
      token Operator::Word
    elsif keywords.include?(m[0])
      token Keyword::Reserved
    else
      token Name
    end
  end

  rule %r/\.\./, Operator
  rule %r/[*!%&<>\|^+=:.\/-]/, Operator
  rule %r/[\[\](){},;`]/, Punctuation

  rule %r/[^\S\n]+/, Text
  rule %r/\n/, Text
  rule %r/./, Error # Catchall
end