import ace from 'brace' ; ( ace as any ) . define ( 'ace/mode/glisp' , function ( this , acequire , exports ) { const oop = acequire ( '../lib/oop' ) ; const TextMode = acequire ( './text' ) . Mode ; const GlispHighlightRules = acequire ( './glisp_highlight_rules' ) . GlispHighlightRules ; const MatchingParensOutdent = acequire ( './matching_parens_outdent' ) . MatchingParensOutdent ; const Mode = function ( this ) { this . HighlightRules = GlispHighlightRules ; this . $outdent = new MatchingParensOutdent ( ) ; this . $behaviour = this . $defaultBehaviour ; } ; oop . inherits ( Mode , TextMode ) ; ( function ( this ) { this . lineCommentStart = ';' ; this . minorIndentFunctions = [ 'if' , 'case' , 'defn' , 'defmacro' , 'def' , 'defvar' , 'g' , 'transform' , 'style' , 'path/transform' , 'artboard' , 'clip' , ] ; this . $toIndent = function ( str ) { return str . split ( '' ) . map ( function ( ch ) { if ( /\s/ . exec ( ch ) ) { return ch ; } else { return ' ' ; } } ) . join ( '' ) ; } ; this . $calculateIndent = function ( line , tab ) { let baseIndent = this . $getIndent ( line ) as string ; let delta = 0 ; let isParen , ch , i ; for ( i = line . length - 1 ; i >= 0 ; i -- ) { ch = line [ i ] ; if ( ch === '(' ) { delta -- ; isParen = true ; } else if ( ch === '(' || ch === '[' || ch === '{' ) { delta -- ; isParen = false ; } else if ( ch === ')' || ch === ']' || ch === '}' ) { delta ++ ; } if ( delta < 0 ) { break ; } } if ( delta < 0 && isParen ) { i += 1 ; const iBefore = i ; let fn = '' ; while ( true ) { ch = line [ i ] ; if ( ch === ' ' || ch === '\t' ) { if ( this . minorIndentFunctions . indexOf ( fn ) !== - 1 ) { return this . $toIndent ( line . substring ( 0 , iBefore - 1 ) + tab ) ; } else { return this . $toIndent ( line . substring ( 0 , i + 1 ) ) ; } } else if ( ch === undefined ) { return this . $toIndent ( line . substring ( 0 , iBefore - 1 ) + tab ) ; } fn += line [ i ] ; i ++ ; } } else if ( delta < 0 && ! isParen ) { return this . $toIndent ( line . substring ( 0 , i + 1 ) ) ; } else if ( delta > 0 ) { baseIndent = baseIndent . substring ( 0 , baseIndent . length - tab . length ) ; return baseIndent ; } else { return baseIndent ; } } ; this . getNextLineIndent = function ( state , line , tab ) { return this . $calculateIndent ( line , tab ) ; } ; this . checkOutdent = function ( state , line , input ) { return this . $outdent . checkOutdent ( line , input ) ; } ; this . autoOutdent = function ( state , doc , row ) { this . $outdent . autoOutdent ( doc , row ) ; } ; this . $id = 'ace/mode/glisp' ; } . call ( Mode . prototype ) ) ; exports . Mode = Mode ; } ) ; ( ace as any ) . define ( 'ace/mode/glisp_highlight_rules' , function ( this , acequire , exports ) { const oop = acequire ( 'ace/lib/oop' ) ; const TextHighlightRules = acequire ( 'ace/mode/text_highlight_rules' ) . TextHighlightRules ; const GlispHighlightRules = function ( this ) { const clojureBuiltinFunctions = '' ; const builtinFunctions = clojureBuiltinFunctions ; const specialForms = 'throw try catch eval eval* var def do fn macro if let quote style transform g defn defmacro defvar' ; const keywordMapper = this . createKeywordMapper ( { function : specialForms , 'support.function' : builtinFunctions , } , 'identifier' , false , ' ' ) ; this . $rules = this . $rules = { start : [ { token : 'comment' , regex : ';.*$' , } , { token : 'keyword' , regex : '[\\#\\^\\&]' , } , { token : 'keyword' , regex : '[%][0-9]*' , } , { token : 'keyword' , regex : '[@]' , } , { token : 'constant.numeric' , regex : '[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b' , } , { token : 'constant.language' , regex : 'true|false|nil' , } , { token : 'function' , regex : '[\\+|\\-|\\*|\\/||=|!=|<=|>=|<|>]' , } , { token : keywordMapper , regex : '[a-zA-Z_$\\/][a-zA-Z0-9_$\\-]*\\b' , } , { token : 'identifier' , regex : '[\\(]' , next : 'fncall' , } , { token : 'identifier' , regex : '[\\)]' , } , { token : 'keyword.operator' , regex : '\\:[a-zA-Z_$][a-zA-Z0-9_$\\-]*\\b' , } , { token : 'string' , regex : '"' , next : 'string' , } , ] , fncall : [ { token : 'function' , regex : '[\\s]*[^\\s\\(\\[\\{]+' , next : 'start' , } , ] , string : [ { token : 'constant.language.escape' , regex : '\\\\.|\\\\$' , } , { token : 'string' , regex : '[^"\\\\]+' , } , { token : 'string' , regex : '"' , next : 'start' , } , ] , } ; } ; oop . inherits ( GlispHighlightRules , TextHighlightRules ) ; exports . GlispHighlightRules = GlispHighlightRules ; } ) ;