Files
news.gitea.happylizard.me/bin/gems/rouge-4.7.0/lib/rouge/lexers/json.rb
T
pizza2d1 4cee170d66
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 9s
Add bin and edit workflow
2026-09-16 13:11:16 -06:00

73 lines
1.8 KiB
Ruby

# -*- 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', 'Pipfile.lock'
mimetypes 'application/json', 'application/vnd.api+json',
'application/hal+json', 'application/problem+json',
'application/schema+json'
state :whitespace do
rule %r/\s+/, Text::Whitespace
end
state :root do
mixin :whitespace
rule %r/{/, Punctuation, :object
rule %r/\[/, Punctuation, :array
mixin :name
mixin :value
# These characters may be invalid but syntax correctness is a non-goal
rule %r/[\]}]/, Punctuation
end
state :object do
mixin :whitespace
mixin :name
mixin :value
rule %r/}/, Punctuation, :pop!
rule %r/,/, Punctuation
end
state :name do
rule %r/("(?:\\.|[^"\\\n])*?")(\s*)(:)/ do
groups Name::Label, Text::Whitespace, Punctuation
end
end
state :value do
mixin :whitespace
mixin :constants
rule %r/"/, Str::Double, :string
rule %r/\[/, Punctuation, :array
rule %r/{/, Punctuation, :object
end
state :string do
rule %r/[^\\"]+/, Str::Double
rule %r/\\./, Str::Escape
rule %r/"/, Str::Double, :pop!
end
state :array do
mixin :value
rule %r/\]/, Punctuation, :pop!
rule %r/,/, Punctuation
end
state :constants do
rule %r/(?:true|false|null)/, Keyword::Constant
rule %r/-?(?:0|[1-9]\d*)\.\d+(?:e[+-]?\d+)?/i, Num::Float
rule %r/-?(?:0|[1-9]\d*)(?:e[+-]?\d+)?/i, Num::Integer
end
end
end
end