diff --git a/CHANGELOG.md b/CHANGELOG.md index 2faaae1..ce4fd62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,15 @@ +## [0.8.1] + +### Added +- Dart keywords +- TypeScript keywords +- GO keywords +- PHP keywords +- supported languages list to README + +### Fixed +- all current keywords + ## [0.8.0] ### Changed @@ -26,37 +38,35 @@ ## [0.6.0] ### Added -- Support for other non-mobile targets +- support for other non-mobile targets ### Changed -- Project maven description +- project maven description - Kotlin version to 1.9.0 ## [0.5.0] ### Changed -- Publication script to add pom and java doc to all targets +- publication script to add pom and java doc to all targets ## [0.4.2] ### Changed -- Version everywhere to 0.4.2 +- version everywhere to 0.4.2 ## [0.4.1] ### Added -- More sections to README +- more sections to README ## [0.4.0] ### Changed - -- Snapshot is moved to Highlights to keep it with each instance +- snapshot is moved to Highlights to keep it with each instance ## [0.3.1] ### Added - - README code usage examples - folder with sample - README installation section @@ -64,33 +74,28 @@ ## [0.3.0] ### Added - -- Public static `themes` and `languages` functions for easier accessing +- public static `themes` and `languages` functions for easier accessing all predefined values ## [0.2.1] ### Added - -- This CHANGELOG file to hopefully serve as an evolving example of a +- this CHANGELOG file to hopefully serve as an evolving example of a standardized open source project CHANGELOG ## [0.2.0] ### Added - -- Own native algorithm for `indicesOf` function +- own native algorithm for `indicesOf` function - KMM targets (iosArm64, iosX64, iosSimulatorArm64, jvm) ### Changed - - Java target to Kotlin -- Escaped comment indicator characters to the regular ones +- escaped comment indicator characters to the regular ones ## [0.1.0] ### Added - -- Token locators and other internal core components -- Unit tests -- Public API interface +- token locators and other internal core components +- unit tests +- public API interface diff --git a/README.md b/README.md index 03336d5..4fd42d5 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ repositories { ``` ```shell -implementation("dev.snipme:highlights:0.8.0") +implementation("dev.snipme:highlights:0.8.1") ``` ## Features ✨ @@ -65,6 +65,26 @@ Highlights.Builder() More advance usage of this library is shown [here](/sample). +## Languages 🌍 + +`C`, +`C++`, +`DART`, +`JAVA`, +`KOTLIN`, +`RUST`, +`C#`, +`COFFEESCRIPT`, +`JAVASCRIPT`, +`PERL`, +`PYTHON`, +`RUBY`, +`SHELL`, +`SWIFT`, +`TYPESCRIPT`, +`GO`, +`PHP` + ## Themes 🖌️ The library comes with predefined syntax coloring themes available in `SyntaxThemes`: diff --git a/build.gradle.kts b/build.gradle.kts index b29a0a9..5b5ac38 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ plugins { } group = "dev.snipme" -version = "0.8.0" +version = "0.8.1" kotlin { // Android diff --git a/src/commonMain/kotlin/dev/snipme/highlights/internal/CodeAnalyzer.kt b/src/commonMain/kotlin/dev/snipme/highlights/internal/CodeAnalyzer.kt index 2c1f5d1..fd7c538 100644 --- a/src/commonMain/kotlin/dev/snipme/highlights/internal/CodeAnalyzer.kt +++ b/src/commonMain/kotlin/dev/snipme/highlights/internal/CodeAnalyzer.kt @@ -1,20 +1,23 @@ package dev.snipme.highlights.internal import dev.snipme.highlights.internal.SyntaxTokens.ALL_KEYWORDS -import dev.snipme.highlights.internal.SyntaxTokens.ALL_MIXED_KEYWORDS -import dev.snipme.highlights.internal.SyntaxTokens.COFFEE_KEYWORDS +import dev.snipme.highlights.internal.SyntaxTokens.COFFEE_SCRIPT_KEYWORDS import dev.snipme.highlights.internal.SyntaxTokens.CPP_KEYWORDS import dev.snipme.highlights.internal.SyntaxTokens.CSHARP_KEYWORDS import dev.snipme.highlights.internal.SyntaxTokens.C_KEYWORDS +import dev.snipme.highlights.internal.SyntaxTokens.DART_KEYWORDS +import dev.snipme.highlights.internal.SyntaxTokens.GO_KEYWORDS +import dev.snipme.highlights.internal.SyntaxTokens.JAVASCRIPT_KEYWORDS import dev.snipme.highlights.internal.SyntaxTokens.JAVA_KEYWORDS -import dev.snipme.highlights.internal.SyntaxTokens.JSCRIPT_KEYWORDS import dev.snipme.highlights.internal.SyntaxTokens.KOTLIN_KEYWORDS import dev.snipme.highlights.internal.SyntaxTokens.PERL_KEYWORDS +import dev.snipme.highlights.internal.SyntaxTokens.PHP_KEYWORDS import dev.snipme.highlights.internal.SyntaxTokens.PYTHON_KEYWORDS import dev.snipme.highlights.internal.SyntaxTokens.RUBY_KEYWORDS import dev.snipme.highlights.internal.SyntaxTokens.RUST_KEYWORDS import dev.snipme.highlights.internal.SyntaxTokens.SH_KEYWORDS import dev.snipme.highlights.internal.SyntaxTokens.SWIFT_KEYWORDS +import dev.snipme.highlights.internal.SyntaxTokens.TYPESCRIPT_KEYWORDS import dev.snipme.highlights.internal.locator.AnnotationLocator import dev.snipme.highlights.internal.locator.CommentLocator import dev.snipme.highlights.internal.locator.KeywordLocator @@ -29,17 +32,20 @@ import dev.snipme.highlights.model.SyntaxLanguage.C import dev.snipme.highlights.model.SyntaxLanguage.COFFEESCRIPT import dev.snipme.highlights.model.SyntaxLanguage.CPP import dev.snipme.highlights.model.SyntaxLanguage.CSHARP +import dev.snipme.highlights.model.SyntaxLanguage.DART import dev.snipme.highlights.model.SyntaxLanguage.DEFAULT +import dev.snipme.highlights.model.SyntaxLanguage.GO import dev.snipme.highlights.model.SyntaxLanguage.JAVA import dev.snipme.highlights.model.SyntaxLanguage.JAVASCRIPT import dev.snipme.highlights.model.SyntaxLanguage.KOTLIN -import dev.snipme.highlights.model.SyntaxLanguage.MIXED import dev.snipme.highlights.model.SyntaxLanguage.PERL +import dev.snipme.highlights.model.SyntaxLanguage.PHP import dev.snipme.highlights.model.SyntaxLanguage.PYTHON import dev.snipme.highlights.model.SyntaxLanguage.RUBY import dev.snipme.highlights.model.SyntaxLanguage.RUST import dev.snipme.highlights.model.SyntaxLanguage.SHELL import dev.snipme.highlights.model.SyntaxLanguage.SWIFT +import dev.snipme.highlights.model.SyntaxLanguage.TYPESCRIPT data class CodeSnapshot( val code: String, @@ -87,20 +93,23 @@ internal object CodeAnalyzer { private fun analyzeForLanguage(code: String, language: SyntaxLanguage) = when (language) { DEFAULT -> analyzeCodeWithKeywords(code, ALL_KEYWORDS) - MIXED -> analyzeCodeWithKeywords(code, ALL_MIXED_KEYWORDS) C -> analyzeCodeWithKeywords(code, C_KEYWORDS) CPP -> analyzeCodeWithKeywords(code, CPP_KEYWORDS) JAVA -> analyzeCodeWithKeywords(code, JAVA_KEYWORDS) KOTLIN -> analyzeCodeWithKeywords(code, KOTLIN_KEYWORDS) RUST -> analyzeCodeWithKeywords(code, RUST_KEYWORDS) CSHARP -> analyzeCodeWithKeywords(code, CSHARP_KEYWORDS) - COFFEESCRIPT -> analyzeCodeWithKeywords(code, COFFEE_KEYWORDS) - JAVASCRIPT -> analyzeCodeWithKeywords(code, JSCRIPT_KEYWORDS) + COFFEESCRIPT -> analyzeCodeWithKeywords(code, COFFEE_SCRIPT_KEYWORDS) + JAVASCRIPT -> analyzeCodeWithKeywords(code, JAVASCRIPT_KEYWORDS) PERL -> analyzeCodeWithKeywords(code, PERL_KEYWORDS) PYTHON -> analyzeCodeWithKeywords(code, PYTHON_KEYWORDS) RUBY -> analyzeCodeWithKeywords(code, RUBY_KEYWORDS) SHELL -> analyzeCodeWithKeywords(code, SH_KEYWORDS) SWIFT -> analyzeCodeWithKeywords(code, SWIFT_KEYWORDS) + DART -> analyzeCodeWithKeywords(code, DART_KEYWORDS) + TYPESCRIPT -> analyzeCodeWithKeywords(code, TYPESCRIPT_KEYWORDS) + GO -> analyzeCodeWithKeywords(code, GO_KEYWORDS) + PHP -> analyzeCodeWithKeywords(code, PHP_KEYWORDS) } private fun analyzeCodeWithKeywords(code: String, keywords: List): CodeStructure { diff --git a/src/commonMain/kotlin/dev/snipme/highlights/internal/SyntaxTokens.kt b/src/commonMain/kotlin/dev/snipme/highlights/internal/SyntaxTokens.kt index f1aaefe..ebea5b2 100644 --- a/src/commonMain/kotlin/dev/snipme/highlights/internal/SyntaxTokens.kt +++ b/src/commonMain/kotlin/dev/snipme/highlights/internal/SyntaxTokens.kt @@ -1,127 +1,150 @@ package dev.snipme.highlights.internal internal object SyntaxTokens { - val FLOW_CONTROL_KEYWORDS = "break,continue,do,else,for,if,return,while".split(",") - - val C_KEYWORDS = FLOW_CONTROL_KEYWORDS + ("auto,case,char,const,default," - + "double,enum,extern,float,goto,inline,int,long,register,short,signed," - + "sizeof,static,struct,switch,typedef,union,unsigned,void,volatile").split(",") - - val COMMON_KEYWORDS = C_KEYWORDS + ("catch,class,delete,false,import," - + "new,operator,private,protected,public,this,throw,true,try,typeof").split(",") - - val CPP_KEYWORDS = COMMON_KEYWORDS + ("alignof,align_union,asm,axiom,bool," - + "concept,concept_map,const_cast,constexpr,decltype,delegate," - + "dynamic_cast,explicit,export,friend,generic,late_check," - + "mutable,namespace,nullptr,property,reinterpret_cast,static_assert," - + "static_cast,template,typeid,typename,using,virtual,where").split(",") - - val JAVA_KEYWORDS = COMMON_KEYWORDS + - ("abstract,assert,boolean,byte,extends,final,finally,implements,import," - + "instanceof,interface,null,native,package,strictfp,super,synchronized," - + "throws,transient").split(",") - - val KOTLIN_KEYWORDS = JAVA_KEYWORDS + - ("as,as?,fun,in,!in,is,!is,object,typealias,val,var,when,by,constructor,delegate,dynamic," - + "file,get,init,set,value,where,actual,annotation,companion,crossinline,data,enum,expect," - + "external,field,infix,inline,inner,internal,lateinit,noinline,open,operator,out,override," - + "reified,sealed,suspend,tailrec,vararg").split(",") - - val RUST_KEYWORDS = FLOW_CONTROL_KEYWORDS + ( "as,assert,const,copy,drop," - + "enum,extern,fail,false,fn,impl,let,log,loop,match,mod,move,mut,priv," - + "pub,pure,ref,self,static,struct,true,trait,type,unsafe,use").split(",") - - val CSHARP_KEYWORDS = JAVA_KEYWORDS + - ("as,base,by,checked,decimal,delegate,descending,dynamic,event," - + "fixed,foreach,from,group,implicit,in,internal,into,is,let," - + "lock,object,out,override,orderby,params,partial,readonly,ref,sbyte," - + "sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort," - + "var,virtual,where").split(",") - - val COFFEE_KEYWORDS = ("all,and,by,catch,class,else,extends,false,finally," - + "for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then," - + "throw,true,try,unless,until,when,while,yes").split(",") - - val JSCRIPT_KEYWORDS = COMMON_KEYWORDS + - ("debugger,eval,export,function,get,null,set,undefined,var,with," - + "Infinity,NaN").split(",") - - val PERL_KEYWORDS = ("caller,delete,die,do,dump,elsif,eval,exit,foreach,for," - + "goto,if,import,last,local,my,next,no,our,print,package,redo,require," - + "sub,undef,unless,until,use,wantarray,while,BEGIN,END").split(",") - - val PYTHON_KEYWORDS = FLOW_CONTROL_KEYWORDS + - ("and,as,assert,class,def,del," - + "elif,except,exec,finally,from,global,import,in,is,lambda," - + "nonlocal,not,or,pass,print,raise,try,with,yield," - + "False,True,None").split(",") - - val RUBY_KEYWORDS = FLOW_CONTROL_KEYWORDS + - ("alias,and,begin,case,class," - + "def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo," - + "rescue,retry,self,super,then,true,undef,unless,until,when,yield," - + "BEGIN,END").split(",") - - val SH_KEYWORDS = FLOW_CONTROL_KEYWORDS + - ("case,done,elif,esac,eval,fi," - + "function,in,local,set,then,until").split(",") - - val SWIFT_KEYWORDS = FLOW_CONTROL_KEYWORDS + "," + - "associatedtype,async,await,class,deinit,enum,extension,fileprivate," + - "func,import,init,inout,internal,let,open,operator,private,protocol,public,rethrows,static," + - "struct,subscript,typealias,andvar,case,default,defer,fallthrough," + - "guard,in,repeat,switch,where,as,Any,catch,false,is,nil,super,self,Self," + - "throw,throws,true,try,#available,#colorLiteral,#column,#else,#elseif,#endif,#error,#file," + - "#fileID,#fileLiteral,#filePath,#function,#if,#imageLiteral,#line,#selector,#sourceLocation," + - "#warning,associativity,convenience,dynamic,didSet,final,get,infix,indirect,lazy,left," + - "mutating,none,nonmutating,optional,override,postfix,precedence,prefix,Protocol,required," + - "right,set,Type,unowned,weak,willSet,var,_".split(",") - - val ALL_KEYWORDS = (CPP_KEYWORDS + KOTLIN_KEYWORDS + CSHARP_KEYWORDS - + RUST_KEYWORDS + COFFEE_KEYWORDS - + JSCRIPT_KEYWORDS + PERL_KEYWORDS + PYTHON_KEYWORDS + RUBY_KEYWORDS - + SH_KEYWORDS + SWIFT_KEYWORDS) - - val ALL_MIXED_KEYWORDS: List = - """#available #column #define #defined #elif #else #else#elseif #endif #error #file #function - #if #ifdef #ifndef #include #line #pragma #selector #undef abstract add after alias - alignas alignof and and_eq andalso as ascending asm assert associatedtype associativity - async atomic_cancel atomic_commit atomic_noexcept auto await base become begin bitand - bitor bnot bor box break bsl bsr bxor case catch chan - checked class compl concept cond const const_cast constexpr continue convenience - covariant crate debugger decltype def default defer deferred defined? deinit - del delegate delete descending didset div do dynamic dynamic_cast dynamictype - elif else elseif elsif end ensure eval event except explicit export extends extension - extern external factory fallthrough false final finally fixed fn for foreach friend - from fun func function get global go goto group guard if impl implements implicit import - in indirect infix init inline inout instanceof interface internal into is join lambda - lazy left let library local lock long loop macro map match mod module move mut mutable - mutating namespace native new next nil noexcept none nonlocal nonmutating not not_eq - null nullptr object of offsetof operator optional or or_eq orderby orelse out override - package params part partial pass postfix precedence prefix priv private proc protected - protocol pub public pure raise range readonly receive redo ref register reinterpret_cast - rem remove repeat required requires rescue rethrow rethrows retry return right sbyte - sealed select self set short signed sizeof stackalloc static static_assert static_cast - strictfp struct subscript super switch sync synchronized template then this - thread_local throw throws trait transaction_safe transaction_safe_dynamic transient - true try type typealias typedef typeid typename typeof uint ulong unchecked undef - union unless unowned unsafe unsigned unsized until use ushort using value var virtual - void volatile wchar_t weak when where while willset with xor xor_eq xorauto yield - yieldabstract yieldarguments val list override get set as as? in !in !is is by - constructor delegate dynamic field file init param property receiver setparam data - data expect lateinit crossinline companion annotation actual noinline open reified - suspend tailrec vararg it constraint alter column table all any asc backup database - between check create index replace view procedure unique desc distinct drop exec - exists foreign key full outer having inner insert like limit order primary rownum - top truncate update values""" - .split(" ") + + val C_KEYWORDS = """ + auto,break,case,char,const,continue,default,do,double,else,enum,extern,float,for,goto,if, + int,long,register,return,short,signed,sizeof,static,struct,switch,typedef,union,unsigned, + void,volatile,while + """.toTokenList() + + val CPP_KEYWORDS = """ + asm,auto,bool,break,case,catch,char,class,const,const_cast,continue,default,delete,do, + double,dynamic_cast,else,enum,explicit,export,extern,false,float,for,friend,goto,if,inline, + int,long,mutable,namespace,new,operator,private,protected,public,register,reinterpret_cast, + return,short,signed,sizeof,static,static_cast,struct,switch,template,this,throw,true,try, + typedef,typeid,typename,union,unsigned,using,virtual,void,volatile,wchar_t,while + """.toTokenList() + + val JAVA_KEYWORDS = """ + abstract,assert,boolean,break,byte,case,catch,char,class,const,continue,default,do,double, + else,enum,extends,final,finally,float,for,goto,if,implements,import,instanceof,int, + interface,long,native,new,null,package,private,protected,public,return,short,static, + strictfp,super,switch,synchronized,this,throw,throws,transient,try,void,volatile,while + """.toTokenList() + + val KOTLIN_KEYWORDS = """ + actual,abstract,annotation,as,as?,break,by,catch,class,companion,const,constructor,continue, + coroutine,crossinline,data,delegate,dynamic,do,else,enum,expect,external,false,final, + finally,for,fun,get,if,import,in,!in,infix,inline,interface,internal,is,!is,lazy,lateinit, + native,null,object,open,operator,out,override,package,private,protected,public,reified, + return,sealed,set,super,suspend,tailrec,this,throw,true,try,typealias,typeof,val,var,vararg, + when,while,yield + """.toTokenList() + + val RUST_KEYWORDS = """ + as,async,await,break,const,continue,crate,dyn,else,enum,extern,false,fn,for,if,impl,in,let, + loop,match,mod,move,mut,pub,ref,return,Self,self,static,struct,super,trait,true,type,union, + unsafe,use,where,while,abstract,become,box,do,final,macro,override,priv,try,typeof, + unsized,virtual,yield + """.toTokenList() + + val CSHARP_KEYWORDS = """ + abstract,as,base,bool,break,byte,case,catch,char,checked,class,const,continue,decimal, + default,delegate,do,double,else,enum,event,explicit,extern,false,finally,fixed,float,for, + foreach,goto,if,implicit,in,int,interface,internal,is,lock,long,namespace,new,null,object, + operator,out,override,params,private,protected,public,readonly,ref,return,sbyte,sealed, + short,sizeof,stackalloc,static,string,struct,switch,this,throw,true,try,typeof,uint,ulong, + unchecked,unsafe,ushort,using,virtual,void,volatile,while + """.toTokenList() + + val COFFEE_SCRIPT_KEYWORDS = """ + =,->,Infinity,NaN,and,arguments,await,break,by,case,catch,class,continue,debugger,delete, + defer,default,do,else,export,extends,false,finally,for,function,if,import,in,instanceof,is, + isnt,let,loop,new,no,not,null,of,on,or,package,return,super,switch,this,throw,true,try, + typeof,unless,undefined,var,wait,when,with,yield + """.toTokenList() + + val JAVASCRIPT_KEYWORDS = """ + async,await,boolean,break,case,catch,class,const,continue,debugger,default,delete,do,else, + enum,export,extends,false,finally,for,function,if,implements,import,in,instanceof,interface, + let,new,null,package,private,protected,public,return,super,switch,this,throw,true,try,typeof, + var,void,while,with,yield + """.toTokenList() + + val PERL_KEYWORDS = """ + __DATA__,__END__,__FILE__,__LINE__,__PACKAGE__,and,cmp,continue,do,else,elsif,eq,eval,for, + foreach,goto,gt,if,last,last,le,lt,my,ne,next,no,not,or,package,redo,ref,return,sub,unless, + until,use,while,xor + """.toTokenList() + + val PYTHON_KEYWORDS = """ + False,True,and,as,assert,async,await,break,class,continue,def,del,elif,else,except,finally, + for,from,global,if,import,in,is,lambda,nonlocal,not,or,pass,raise,return,try,while,with, + yield + """.toTokenList() + + val RUBY_KEYWORDS = """ + __ENCODING__,__END__,__FILE__,__LINE__,BEGIN,END,alias,and,begin,break,case,class,def, + defined?,do,else,elsif,end,ensure,false,for,if,in,module,next,nil,not,or,redo,rescue,retry, + return,self,super,then,true,undef,unless,until,when,while,yield + """.toTokenList() + + val SH_KEYWORDS = """ + alias,bg,bind,break,builtin,caller,cd,command,compgen,complete,compopt,continue,declare, + dirs,disown,echo,enable,eval,exec,exit,export,fc,fg,getopts,hash,help,history,jobs,kill,let, + local,logout,popd,printf,pushd,pwd,read,readonly,return,set,shift,shopt,source,suspend,test, + """.toTokenList() + + val SWIFT_KEYWORDS = """ + _,associatedtype,class,deinit,enum,extension,fileprivate,func,import,init,inout,internal, + let,open,operator,private,precedencegroup,protocol,public,rethrows,static,struct,subscript, + typealias,varbreak,case,catch,continue,default,defer,do,else,fallthrough,for,guard,if,in, + repeat,return,throw,switch,where,while,Any,as,await,catch,false,is,nil,rethrows,self,Self, + super,throw,throws,true,try,#available,#colorLiteral,#else,#elseif,#endif,#fileLiteral,#if, + #imageLiteral,#keyPath,#selector,#sourceLocation,#unavailable,associativity,convenience, + didSet,dynamic,final,get,indirect,infix,lazy,left,mutating,none,nonmutating,optional, + override,postfix,precedence,prefix,Protocol,required,right,set,some,Type,unowned,weak, + willSet + """.toTokenList() + + val DART_KEYWORDS = """ + abstract,as,assert,async,await,base,break,case,catch,class,const,continue,covariant,default, + deferred,do,dynamic,else,enum,export,extends,external,factory,false,final,finally,for,get, + if,implements,import,in,interface,is,late,library,mixin,new,null,on,operator,part,required, + rethrow,return,sealed,set,show,static,super,switch,this,throw,true,try,var,void,when,with, + while,yield + """.toTokenList() + + val GO_KEYWORDS = """ + break,case,chan,const,continue,default,defer,else,fallthrough,false,for,func,go,goto,if, + import,interface,map,package,range,return,select,struct,switch,type,var,true + """.toTokenList() + + val PHP_KEYWORDS = """ + __halt_compiler,abstract,and,array,as,break,callable,case,catch,class,clone,const,continue, + declare,default,die,do,echo,else,elseif,empty,enddeclare,endfor,endforeach,endif,endswitch, + endwhile,eval,exit,extends,final,finally,fn,for,foreach,function,global,goto,if,implements, + include,include_once,instanceof,insteadof,interface,isset,list,match,new,or,print,private, + protected,public,require,require_once,return,static,switch,throw,trait,try,unset,use,var, + while,xor,yield + """.toTokenList() + + val TYPESCRIPT_KEYWORDS = """ + abstract,as,asserts,await,break,case,catch,class,const,constructor,continue,debugger, + default, delete,do,else,enum,export,extends,false,finally,for,from,function,get,if, + implements,import,in,infer,instanceof,interface,is,keyof,let,module,namespace,new,null, + number,object,package,private,protected,public,readonly,require,global,return,set,static, + string,super,switch,this,throw,true,try,type,typeof,undefined,unique,unknown,var,void,while, + with,yield + """.toTokenList() + + val ALL_KEYWORDS = (CPP_KEYWORDS + KOTLIN_KEYWORDS + CSHARP_KEYWORDS + RUST_KEYWORDS + + COFFEE_SCRIPT_KEYWORDS + JAVASCRIPT_KEYWORDS + PERL_KEYWORDS + PYTHON_KEYWORDS + + RUBY_KEYWORDS + SH_KEYWORDS + SWIFT_KEYWORDS + DART_KEYWORDS + GO_KEYWORDS + + PHP_KEYWORDS + TYPESCRIPT_KEYWORDS) // TODO Migrate to list of chars - val TOKEN_DELIMITERS = listOf(" ", ",", ".", ":", ";", "(", ")", "=", "{", "}", "<", ">", "\r", "\n") + val TOKEN_DELIMITERS = + listOf(" ", ",", ".", ":", ";", "(", ")", "=", "{", "}", "<", ">", "\r", "\n") val STRING_DELIMITERS = listOf("\'", "\"", "\"\"\"") val COMMENT_DELIMITERS = listOf("//", "#") + // TODO Add support for other other languages like Dart or Python val MULTILINE_COMMENT_DELIMITERS = listOf(Pair("/*", "*/")) val PUNCTUATION_CHARACTERS = listOf(",", ".", ":", ";") val MARK_CHARACTERS = listOf("(", ")", "=", "{", "}", "<", ">", "-", "+", "[", "]", "|", "&") -} \ No newline at end of file + + private fun String.toTokenList() = trimIndent().split(",") +} + diff --git a/src/commonMain/kotlin/dev/snipme/highlights/model/SyntaxLanguage.kt b/src/commonMain/kotlin/dev/snipme/highlights/model/SyntaxLanguage.kt index f28b7ae..7e0147c 100644 --- a/src/commonMain/kotlin/dev/snipme/highlights/model/SyntaxLanguage.kt +++ b/src/commonMain/kotlin/dev/snipme/highlights/model/SyntaxLanguage.kt @@ -2,9 +2,9 @@ package dev.snipme.highlights.model enum class SyntaxLanguage { DEFAULT, - MIXED, C, CPP, + DART, JAVA, KOTLIN, RUST, @@ -15,7 +15,10 @@ enum class SyntaxLanguage { PYTHON, RUBY, SHELL, - SWIFT; + SWIFT, + TYPESCRIPT, + GO, + PHP; companion object { fun getNames(): List = values().map { diff --git a/src/commonTest/kotlin/dev/snipme/highlights/internal/CodeAnalyzerTest.kt b/src/commonTest/kotlin/dev/snipme/highlights/internal/CodeAnalyzerTest.kt index 675353a..df4c45f 100644 --- a/src/commonTest/kotlin/dev/snipme/highlights/internal/CodeAnalyzerTest.kt +++ b/src/commonTest/kotlin/dev/snipme/highlights/internal/CodeAnalyzerTest.kt @@ -98,7 +98,7 @@ internal class CodeAnalyzerTest { 123.00f """.trimIndent() - val firstResult = CodeAnalyzer.analyze(testCode, SyntaxLanguage.KOTLIN) + val firstResult = CodeAnalyzer.analyze(testCode) assertEquals(false, firstResult.incremental) val secondTestCode = """ @@ -110,20 +110,18 @@ internal class CodeAnalyzerTest { ... 123.00f - field.forEach { } + class """.trimIndent() - val snapshot = CodeSnapshot(testCode, firstResult, SyntaxLanguage.KOTLIN) + val snapshot = CodeSnapshot(testCode, firstResult, SyntaxLanguage.DEFAULT) - val result = CodeAnalyzer.analyze(secondTestCode, SyntaxLanguage.KOTLIN, snapshot) + val result = CodeAnalyzer.analyze(secondTestCode, snapshot = snapshot) assertEquals(true, result.incremental) assertEquals( listOf( PhraseLocation(30, 31), PhraseLocation(31, 32), - PhraseLocation(68, 69), - PhraseLocation(70, 71) ), result.marks ) @@ -135,7 +133,6 @@ internal class CodeAnalyzerTest { PhraseLocation(42, 43), PhraseLocation(43, 44), PhraseLocation(48, 49), - PhraseLocation(59, 60), ), result.punctuations ) @@ -144,7 +141,6 @@ internal class CodeAnalyzerTest { listOf( PhraseLocation(14, 19), PhraseLocation(22, 29), - PhraseLocation(54, 59) ), result.keywords ) @@ -197,7 +193,7 @@ internal class CodeAnalyzerTest { 123.00f """.trimIndent() - val firstResult = CodeAnalyzer.analyze(testCode, SyntaxLanguage.KOTLIN) + val firstResult = CodeAnalyzer.analyze(testCode) assertEquals(false, firstResult.incremental) val secondTestCode = """ @@ -206,9 +202,9 @@ internal class CodeAnalyzerTest { class """.trimIndent() - val snapshot = CodeSnapshot(testCode, firstResult, SyntaxLanguage.KOTLIN) + val snapshot = CodeSnapshot(testCode, firstResult, SyntaxLanguage.DEFAULT) - val result = CodeAnalyzer.analyze(secondTestCode, SyntaxLanguage.KOTLIN, snapshot) + val result = CodeAnalyzer.analyze(secondTestCode, snapshot = snapshot) assertEquals(true, result.incremental) assertEquals(