# -*- coding: utf-8 -*- # # frozen_string_literal: true module Rouge module Lexers class Actionscript < RegexLexer title "ActionScript" desc "ActionScript" tag 'actionscript' aliases 'as', 'as3' filenames '*.as' mimetypes 'application/x-actionscript' state :comments_and_whitespace do rule %r/\s+/, Text rule %r(//.*?$), Comment::Single rule %r(/\*.*?\*/)m, Comment::Multiline end state :expr_start do mixin :comments_and_whitespace rule %r(/) do token Str::Regex goto :regex end rule %r/[{]/, Punctuation, :object rule %r//, Text, :pop! end state :regex do rule %r(/) do token Str::Regex goto :regex_end end rule %r([^/]\n), Error, :pop! rule %r/\n/, Error, :pop! rule %r/\[\^/, Str::Escape, :regex_group rule %r/\[/, Str::Escape, :regex_group rule %r/\\./, Str::Escape rule %r{[(][?][:=>>? | === | !== )x, Operator, :expr_start rule %r([:-<>+*%&|\^/!=]=?), Operator, :expr_start rule %r/[(\[,]/, Punctuation, :expr_start rule %r/;/, Punctuation, :statement rule %r/[)\].]/, Punctuation rule %r/[?]/ do token Punctuation push :ternary push :expr_start end rule %r/[{}]/, Punctuation, :statement rule id do |m| if self.class.keywords.include? m[0] token Keyword push :expr_start elsif self.class.declarations.include? m[0] token Keyword::Declaration push :expr_start elsif self.class.reserved.include? m[0] token Keyword::Reserved elsif self.class.constants.include? m[0] token Keyword::Constant elsif self.class.builtins.include? m[0] token Name::Builtin else token Name::Other end end rule %r/\-?[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?/, Num::Float rule %r/0x[0-9a-fA-F]+/, Num::Hex rule %r/\-?[0-9]+/, Num::Integer rule %r/"(\\\\|\\"|[^"])*"/, Str::Double rule %r/'(\\\\|\\'|[^'])*'/, Str::Single end # braced parts that aren't object literals state :statement do rule %r/(#{id})(\s*)(:)/ do groups Name::Label, Text, Punctuation end rule %r/[{}]/, Punctuation mixin :expr_start end # object literals state :object do mixin :comments_and_whitespace rule %r/[}]/ do token Punctuation goto :statement end rule %r/(#{id})(\s*)(:)/ do groups Name::Attribute, Text, Punctuation push :expr_start end rule %r/:/, Punctuation mixin :root end # ternary expressions, where : is not a label! state :ternary do rule %r/:/ do token Punctuation goto :expr_start end mixin :root end end end end