Sha256: f9b1a9aee9b642bff7cc8949fc900aca3ad2aa6b6b73fb66e57d3cec692818aa

Contents?: true

Size: 904 Bytes

Versions: 2

Compression:

Stored size: 904 Bytes

Contents

# -*- coding: utf-8 -*- #
# frozen_string_literal: true

module Rouge
  module Lexers
    class JSON < RegexLexer
      title 'JSON'
      desc "JavaScript Object Notation (json.org)"
      tag 'json'
      filenames '*.json'
      mimetypes 'application/json', 'application/vnd.api+json',
                'application/hal+json', 'application/problem+json',
                'application/schema+json'

      state :root do
        rule %r/\s+/m, Text::Whitespace
        rule %r/"/, Str::Double, :string
        rule %r/(?:true|false|null)\b/, Keyword::Constant
        rule %r/[{},:\[\]]/, Punctuation
        rule %r/-?(?:0|[1-9]\d*)\.\d+(?:e[+-]?\d+)?/i, Num::Float
        rule %r/-?(?:0|[1-9]\d*)(?:e[+-]?\d+)?/i, Num::Integer
      end

      state :string do
        rule %r/[^\\"]+/, Str::Double
        rule %r/\\./, Str::Escape
        rule %r/"/, Str::Double, :pop!
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rouge-3.5.1 lib/rouge/lexers/json.rb
rouge-3.5.0 lib/rouge/lexers/json.rb