diff --git a/README.md b/README.md index 6cffa01..551cd64 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # CodeView (Android) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-codeview--android-blue.svg)](https://android-arsenal.com/details/1/4216) -[![Release](https://jitpack.io/v/kbiakov/CodeView-android.svg)](https://jitpack.io/#kbiakov/CodeView-Android) +[![Release](https://jitpack.io/v/kbiakov/CodeView-Android.svg)](https://jitpack.io/#kbiakov/CodeView-Android) [![Build Status](https://travis-ci.org/kbiakov/CodeView-android.svg?branch=master)](https://travis-ci.org/kbiakov/CodeView-Android) @@ -226,11 +226,11 @@ List of apps on Play Store where this library used. Ping me if you want to be he Icon | Application ------------ | ------------- | [GeekBrains] - | [Awesome Android - UI Libraries] | [Codify - Codes On The Go] + | [C Programming - 200+ Offline Tutorial and Examples] + | [Awesome Android - UI Libraries] | [GitJourney for GitHub] | [Source Code - Lập Trình] - | [C Programming - CodeSpot] ## Contribute 1. You can add your theme (see [ColorTheme](https://github.com/Softwee/codeview-android/blob/master/codeview/src/main/java/io/github/kbiakov/codeview/highlight/CodeHighlighter.kt) class). Try to add some classic color themes or create your own if it looks cool. You can find many of them in different open-source text editors.
@@ -264,8 +264,8 @@ SOFTWARE. ``` [GeekBrains]:https://play.google.com/store/apps/details?id=ru.geekbrains +[Codify - Codes On The Go]:https://play.google.com/store/apps/details?id=com.femindharamshi.spa +[C Programming - 200+ Offline Tutorial and Examples]:https://play.google.com/store/apps/details?id=com.rsd.cprogramming [Awesome Android - UI Libraries]:https://play.google.com/store/apps/details?id=in.sumeetlubal.aweandroid.aweandroid [GitJourney for GitHub]:https://play.google.com/store/apps/details?id=com.oklab.githubjourney -[Codify - Codes On The Go]:https://play.google.com/store/apps/details?id=com.femindharamshi.spa [Source Code - Lập Trình]:https://play.google.com/store/apps/details?id=com.noah.truongpq.codeview -[C Programming - CodeSpot]:https://play.google.com/store/apps/details?id=com.rsd.cprogramming diff --git a/build.gradle b/build.gradle index 37ef2a4..0173b17 100644 --- a/build.gradle +++ b/build.gradle @@ -1,18 +1,18 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlinVersion = '1.3.11' + ext.kotlinVersion = '1.3.21' ext.minSdk = 15 ext.compileSdk = 28 ext.buildTools = '28.0.3' - ext.supportLibrary = '28.0.0' + ext.androidxLibrary = '1.1.0-alpha02' repositories { jcenter() google() } dependencies { - classpath 'com.android.tools.build:gradle:3.3.0' + classpath 'com.android.tools.build:gradle:3.3.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" } } diff --git a/codeview/build.gradle b/codeview/build.gradle index c460859..3009fee 100644 --- a/codeview/build.gradle +++ b/codeview/build.gradle @@ -24,6 +24,6 @@ android { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion" - implementation "com.android.support:appcompat-v7:$supportLibrary" - implementation "com.android.support:recyclerview-v7:$supportLibrary" + implementation "androidx.appcompat:appcompat:$androidxLibrary" + implementation "androidx.recyclerview:recyclerview:$androidxLibrary" } diff --git a/codeview/src/main/java/io/github/kbiakov/codeview/CodeView.kt b/codeview/src/main/java/io/github/kbiakov/codeview/CodeView.kt index 6d5a1ed..3d404e4 100644 --- a/codeview/src/main/java/io/github/kbiakov/codeview/CodeView.kt +++ b/codeview/src/main/java/io/github/kbiakov/codeview/CodeView.kt @@ -3,11 +3,11 @@ package io.github.kbiakov.codeview import android.content.Context import android.graphics.drawable.Drawable import android.graphics.drawable.GradientDrawable -import android.support.v7.widget.LinearLayoutManager -import android.support.v7.widget.RecyclerView import android.util.AttributeSet import android.view.View import android.widget.RelativeLayout +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView import io.github.kbiakov.codeview.Thread.delayed import io.github.kbiakov.codeview.adapters.AbstractCodeAdapter import io.github.kbiakov.codeview.adapters.CodeWithNotesAdapter diff --git a/codeview/src/main/java/io/github/kbiakov/codeview/adapters/AbstractCodeAdapter.kt b/codeview/src/main/java/io/github/kbiakov/codeview/adapters/AbstractCodeAdapter.kt index 10738c9..848d321 100644 --- a/codeview/src/main/java/io/github/kbiakov/codeview/adapters/AbstractCodeAdapter.kt +++ b/codeview/src/main/java/io/github/kbiakov/codeview/adapters/AbstractCodeAdapter.kt @@ -3,13 +3,13 @@ package io.github.kbiakov.codeview.adapters import android.annotation.SuppressLint import android.content.Context import android.graphics.Typeface -import android.support.v7.widget.RecyclerView import android.util.SparseArray import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.LinearLayout import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView import io.github.kbiakov.codeview.* import io.github.kbiakov.codeview.Thread.asyncUi import io.github.kbiakov.codeview.adapters.AbstractCodeAdapter.ViewHolderType.Companion.BordersCount diff --git a/codeview/src/main/java/io/github/kbiakov/codeview/highlight/FontCache.java b/codeview/src/main/java/io/github/kbiakov/codeview/highlight/FontCache.java index 83367ec..d85ac2d 100644 --- a/codeview/src/main/java/io/github/kbiakov/codeview/highlight/FontCache.java +++ b/codeview/src/main/java/io/github/kbiakov/codeview/highlight/FontCache.java @@ -2,7 +2,6 @@ import android.content.Context; import android.graphics.Typeface; -import android.util.Log; import java.util.Map; import java.util.WeakHashMap; diff --git a/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangEx.java b/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangEx.java new file mode 100644 index 0000000..c8d697d --- /dev/null +++ b/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangEx.java @@ -0,0 +1,49 @@ +package io.github.kbiakov.codeview.highlight.prettify.lang; + + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; + +import io.github.kbiakov.codeview.highlight.prettify.parser.Prettify; + +public class LangEx extends Lang { + + public LangEx() { + List> _shortcutStylePatterns = new ArrayList>(); + List> _fallthroughStylePatterns = new ArrayList>(); + + _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[\\t\\n\\r \\xA0]+"), null, "\t\n\r \\xA0"})); + _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^#.*"), null, "#"})); + _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^'(?:[^'\\\\]|\\\\(?:.|\\n|\\r))*'?"), null, "\\'"})); + _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_ATTRIB_NAME, Pattern.compile("^@\\w+"), null, "@"})); + _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^[!%&()*+,\\-;<=>?\\[\\\\\\]^{|}]+"), null, "!%&()*+,-;<=>?[\\\\]^{|}"})); + _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^(?:0o[0-7](?:[0-7]|_[0-7])*|0x[\\da-fA-F](?:[\\da-fA-F]|_[\\da-fA-F])*|\\d(?:\\d|_\\d)*(?:\\.\\d(?:\\d|_\\d)*)?(?:[eE][+\\-]?\\d(?:\\d|_\\d)*)?)"), + null, "0123456789"})); + + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_ATTRIB_NAME, Pattern.compile("^iex(?:\\(\\d+\\))?> ")})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^::"), null})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^:(?:\\w+[\\!\\?\\@]?|\"(?:[^\"\\\\]|\\\\.)*\"?)")})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_ATTRIB_NAME, Pattern.compile("^(?:__(?:CALLER|ENV|MODULE|DIR)__)")})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^(?:alias|case|catch|def(?:delegate|exception|impl|macrop?|module|overridable|p?|protocol|struct)|do|else|end|fn|for|if|in|import|quote|raise|require|rescue|super|throw|try|unless|unquote(?:_splicing)?|use|when|with|yield)\\b")})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^(?:true|false|nil)\\b")})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^(?:\\w+[\\!\\?\\@]?|\"(?:[^\"\\\\]|\\\\.)*\"):(?!:)")})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^\"\"\"\\s*(\\r|\\n)+(?:\"\"?(?!\")|[^\\\\\"]|\\\\(?:.|\\n|\\r))*\"{0,3}")})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^\"(?:[^\"\\\\]|\\\\(?:.|\\n|\\r))*\"?(?!\")")})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_TYPE, Pattern.compile("^[A-Z]\\w*")})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^_\\w*")})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[$a-z]\\w*[\\!\\?]?")})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_ATTRIB_VALUE, Pattern.compile("^~[A-Z](?:\\/(?:[^\\/\\r\\n\\\\]|\\\\.)+\\/|\\|(?:[^\\|\\r\\n\\\\]|\\\\.)+\\||\"(?:[^\"\\r\\n\\\\]|\\\\.)+\"|'(?:[^'\\r\\n\\\\]|\\\\.)+')[A-Z]*", Pattern.CASE_INSENSITIVE)})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_ATTRIB_VALUE, Pattern.compile("^~[A-Z](?:\\((?:[^\\)\\r\\n\\\\]|\\\\.)+\\)|\\[(?:[^\\]\\r\\n\\\\]|\\\\.)+\\]|\\{(?:[^\\}\\r\\n\\\\]|\\\\.)+\\}|\\<(?:[^\\>\\r\\n\\\\]|\\\\.)+\\>)[A-Z]*", Pattern.CASE_INSENSITIVE)})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^(?:\\.+|\\/|[:~])")})); + + + setShortcutStylePatterns(_shortcutStylePatterns); + setFallthroughStylePatterns(_fallthroughStylePatterns); + } + + public static List getFileExtensions() { + return Arrays.asList(new String[]{"ex", "exs"}); + } +} diff --git a/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangKotlin.java b/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangKotlin.java new file mode 100644 index 0000000..935eab9 --- /dev/null +++ b/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangKotlin.java @@ -0,0 +1,38 @@ +package io.github.kbiakov.codeview.highlight.prettify.lang; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; + +import io.github.kbiakov.codeview.highlight.prettify.parser.Prettify; + +public class LangKotlin extends Lang { + + public LangKotlin() { + List> _shortcutStylePatterns = new ArrayList>(); + List> _fallthroughStylePatterns = new ArrayList>(); + + _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[\\t\\n\\r \\xA0]+"), null, "\\t\\n\\r \\xA0"})); + _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^[.!%&()*+,\\-;<=>?\\[\\\\\\]^{|}:]+"), null, ".!%&()*+,-;<=>?[\\\\]^{|}:"})); + + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^\\b(package|public|protected|private|open|abstract|constructor|final|override|import|for|while|as|typealias|get|set|((data|enum|annotation|sealed) )?class|this|super|val|var|fun|is|in|throw|return|break|continue|(companion )?object|if|try|else|do|when|init|interface|typeof)\\b")})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^(?:true|false|null)\\b")})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^(0[xX][0-9a-fA-F_]+L?|0[bB][0-1]+L?|[0-9_.]+([eE]-?[0-9]+)?[fFL]?)")})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_TYPE, Pattern.compile("^(\\b[A-Z]+[a-z][a-zA-Z0-9_$@]*|`.*`)"), null})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^\\/\\/.*")})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^\\/\\*[\\s\\S]*?(?:\\*\\/|$)")})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("'.'")})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^\"([^\"\\\\]|\\\\[\\s\\S])*\"")})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^\"{3}[\\s\\S]*?[^\\\\]\"{3}")})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^@([a-zA-Z0-9_$@]*|`.*`)")})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^[a-zA-Z0-9_]+@")})); + + setShortcutStylePatterns(_shortcutStylePatterns); + setFallthroughStylePatterns(_fallthroughStylePatterns); + } + + public static List getFileExtensions() { + return Arrays.asList(new String[]{"kotlin"}); + } +} diff --git a/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangLasso.java b/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangLasso.java new file mode 100644 index 0000000..4db53e1 --- /dev/null +++ b/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangLasso.java @@ -0,0 +1,41 @@ +package io.github.kbiakov.codeview.highlight.prettify.lang; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; + +import io.github.kbiakov.codeview.highlight.prettify.parser.Prettify; + +public class LangLasso extends Lang { + + public LangLasso() { + List> _shortcutStylePatterns = new ArrayList>(); + List> _fallthroughStylePatterns = new ArrayList>(); + + _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[\\t\\n\\r \\xA0]+"), null, "\\t\\n\\r \\xA0"})); + _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^\\'[^\\'\\\\]*(?:\\\\[\\s\\S][^\\'\\\\]*)*(?:\\'|$)"), null, "\'"})); + _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^\\\"[^\\\"\\\\]*(?:\\\\[\\s\\S][^\\\"\\\\]*)*(?:\\\"|$)"), null, "\""})); + _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^\\`[^\\`]*(?:\\`|$)"), null, "`"})); + _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^0x[\\da-f]+|\\d+", Pattern.CASE_INSENSITIVE), null, "0123456789"})); + _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_ATTRIB_NAME, Pattern.compile("^[#$][a-z_][\\w.]*|#\\d+\\b|#![ \\S]+lasso9\\b", Pattern.CASE_INSENSITIVE), null, "#$"})); + + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_TAG, Pattern.compile("^[\\[\\]]|<\\?(?:lasso(?:script)?|=)|\\?>|(no_square_brackets|noprocess)\\b", Pattern.CASE_INSENSITIVE)})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^\\/\\/[^\\r\\n]*|\\/\\*[\\s\\S]*?\\*\\/")})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_ATTRIB_NAME, Pattern.compile("^-(?!infinity)[a-z_][\\w.]*|\\.\\s*'[a-z_][\\w.]*'|\\.{3}", Pattern.CASE_INSENSITIVE)})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^\\d*\\.\\d+(?:e[-+]?\\d+)?|(infinity|NaN)\\b", Pattern.CASE_INSENSITIVE)})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_ATTRIB_VALUE, Pattern.compile("^::\\s*[a-z_][\\w.]*", Pattern.CASE_INSENSITIVE)})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^(?:true|false|none|minimal|full|all|void|and|or|not|bw|nbw|ew|new|cn|ncn|lt|lte|gt|gte|eq|neq|rx|nrx|ft)\\b", Pattern.CASE_INSENSITIVE)})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_TYPE, Pattern.compile("^(?:array|date|decimal|duration|integer|map|pair|string|tag|xml|null|boolean|bytes|keyword|list|locale|queue|set|stack|staticarray|local|var|variable|global|data|self|inherited|currentcapture|givenblock)\\b|^\\.\\.?", Pattern.CASE_INSENSITIVE)})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^(?:cache|database_names|database_schemanames|database_tablenames|define_tag|define_type|email_batch|encode_set|html_comment|handle|handle_error|header|if|inline|iterate|ljax_target|link|link_currentaction|link_currentgroup|link_currentrecord|link_detail|link_firstgroup|link_firstrecord|link_lastgroup|link_lastrecord|link_nextgroup|link_nextrecord|link_prevgroup|link_prevrecord|log|loop|namespace_using|output_none|portal|private|protect|records|referer|referrer|repeating|resultset|rows|search_args|search_arguments|select|sort_args|sort_arguments|thread_atomic|value_list|while|abort|case|else|fail_if|fail_ifnot|fail|if_empty|if_false|if_null|if_true|loop_abort|loop_continue|loop_count|params|params_up|return|return_value|run_children|soap_definetag|soap_lastrequest|soap_lastresponse|tag_name|ascending|average|by|define|descending|do|equals|frozen|group|handle_failure|import|in|into|join|let|match|max|min|on|order|parent|protected|provide|public|require|returnhome|skip|split_thread|sum|take|thread|to|trait|type|where|with|yield|yieldhome)\\b", Pattern.CASE_INSENSITIVE)})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[a-z_][\\w.]*(?:=\\s*(?=\\())?", Pattern.CASE_INSENSITIVE)})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^:=|[-+*\\/%=<>&|!?\\\\]+")})); + + setShortcutStylePatterns(_shortcutStylePatterns); + setFallthroughStylePatterns(_fallthroughStylePatterns); + } + + public static List getFileExtensions() { + return Arrays.asList(new String[]{"lasso", "ls", "lassoscript"}); + } +} diff --git a/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangLogtalk.java b/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangLogtalk.java new file mode 100644 index 0000000..5f08b24 --- /dev/null +++ b/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangLogtalk.java @@ -0,0 +1,35 @@ +package io.github.kbiakov.codeview.highlight.prettify.lang; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; + +import io.github.kbiakov.codeview.highlight.prettify.parser.Prettify; + +public class LangLogtalk extends Lang { + + public LangLogtalk() { + List> _shortcutStylePatterns = new ArrayList>(); + List> _fallthroughStylePatterns = new ArrayList>(); + + _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^\\\"(?:[^\\\"\\\\\\n\\x0C\\r]|\\\\[\\s\\S])*(?:\\\"|$)"), null, "\""})); + _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^[a-z][a-zA-Z0-9_]*")})); + _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^\\'(?:[^\\'\\\\\\n\\x0C\\r]|\\\\[^&])+\\'?"), null, "\'"})); + _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^(?:0'.|0b[0-1]+|0o[0-7]+|0x[\\da-f]+|\\d+(?:\\.\\d+)?(?:e[+\\-]?\\d+)?)", Pattern.CASE_INSENSITIVE), null, "0123456789"})); + + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^%[^\\r\\n]*"), null, "%"})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^\\/\\*[\\s\\S]*?\\*\\/")})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^\\s*:-\\s(c(a(lls|tegory)|oinductive)|p(ublic|r(ot(ocol|ected)|ivate))|e(l(if|se)|n(coding|sure_loaded)|xport)|i(f|n(clude|itialization|fo))|alias|d(ynamic|iscontiguous)|m(eta_(non_terminal|predicate)|od(e|ule)|ultifile)|reexport|s(et_(logtalk|prolog)_flag|ynchronized)|o(bject|p)|use(s|_module))")})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^\\s*:-\\s(e(lse|nd(if|_(category|object|protocol)))|built_in|dynamic|synchronized|threaded)")})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_TYPE, Pattern.compile("^[A-Z_][a-zA-Z0-9_]*")})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^[.,;{}:^<>=\\\\/+*?#!-]")})); + + setShortcutStylePatterns(_shortcutStylePatterns); + setFallthroughStylePatterns(_fallthroughStylePatterns); + } + + public static List getFileExtensions() { + return Arrays.asList(new String[]{"logtalk", "lgt"}); + } +} \ No newline at end of file diff --git a/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangSwift.java b/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangSwift.java new file mode 100644 index 0000000..a92339f --- /dev/null +++ b/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangSwift.java @@ -0,0 +1,35 @@ +package io.github.kbiakov.codeview.highlight.prettify.lang; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; + +import io.github.kbiakov.codeview.highlight.prettify.parser.Prettify; + +public class LangSwift extends Lang { + + public LangSwift() { + List> _shortcutStylePatterns = new ArrayList>(); + List> _fallthroughStylePatterns = new ArrayList>(); + + _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[ \\n\\r\\t\\v\\f\\\0]+"), null, " \\n\\r\\t\\v\\f\\0"})); + _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^\"(?:[^\"\\\\]|(?:\\\\.)|(?:\\\\\\((?:[^\"\\\\)]|\\\\.)*\\)))*\""), null, "\""})); + + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^(?:(?:0x[\\da-fA-F][\\da-fA-F_]*\\.[\\da-fA-F][\\da-fA-F_]*[pP]?)|(?:\\d[\\d_]*\\.\\d[\\d_]*[eE]?))[+-]?\\d[\\d_]*"), null})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^-?(?:(?:0(?:(?:b[01][01_]*)|(?:o[0-7][0-7_]*)|(?:x[\\da-fA-F][\\da-fA-F_]*)))|(?:\\d[\\d_]*))"), null})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^(?:_|Any|true|false|nil)\\b"), null})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^\\b(?:__COLUMN__|__FILE__|__FUNCTION__|__LINE__|#available|#colorLiteral|#column|#else|#elseif|#endif|#file|#fileLiteral|#function|#if|#imageLiteral|#line|#selector|#sourceLocation|arch|arm|arm64|associatedtype|associativity|as|break|case|catch|class|continue|convenience|default|defer|deinit|didSet|do|dynamic|dynamicType|else|enum|extension|fallthrough|fileprivate|final|for|func|get|guard|import|indirect|infix|init|inout|internal|i386|if|in|iOS|iOSApplicationExtension|is|lazy|left|let|mutating|none|nonmutating|open|operator|optional|OSX|OSXApplicationExtension|override|postfix|precedence|prefix|private|protocol|Protocol|public|repeat|required|rethrows|return|right|safe|Self|self|set|static|struct|subscript|super|switch|throw|throws|try|Type|typealias|unowned|unsafe|var|weak|watchOS|where|while|willSet|x86_64)\\b"), null})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^\\/\\/.*?[\\n\\r]"), null})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^\\/\\*[\\s\\S]*?(?:\\*\\/|$)"), null})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^<<=|<=|<<|>>=|>=|>>|===|==|\\.\\.\\.|&&=|\\.\\.<|!==|!=|&=|~=|~|\\(|\\)|\\[|\\]|\\{|}|@|#|;|\\.|,|:|\\|\\|=|\\?\\?|\\|\\||&&|&\\*|&\\+|&-|&=|\\+=|-=|\\/=|\\*=|\\^=|%=|\\|=|->|`|==|\\+\\+|--|\\/|\\+|!|\\*|%|<|>|&|\\||\\^|\\?|=|-|_"), null})); + _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_TYPE, Pattern.compile("^\\b(?:[@_]?[A-Z]+[a-z][A-Za-z_$@0-9]*|\\w+_t\\b)"), null})); + + setShortcutStylePatterns(_shortcutStylePatterns); + setFallthroughStylePatterns(_fallthroughStylePatterns); + } + + public static List getFileExtensions() { + return Arrays.asList(new String[]{"swift"}); + } +} \ No newline at end of file diff --git a/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/parser/Prettify.java b/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/parser/Prettify.java index 970cdd8..e462202 100644 --- a/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/parser/Prettify.java +++ b/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/parser/Prettify.java @@ -31,8 +31,11 @@ import io.github.kbiakov.codeview.highlight.prettify.lang.LangErlang; import io.github.kbiakov.codeview.highlight.prettify.lang.LangGo; import io.github.kbiakov.codeview.highlight.prettify.lang.LangHs; +import io.github.kbiakov.codeview.highlight.prettify.lang.LangKotlin; +import io.github.kbiakov.codeview.highlight.prettify.lang.LangLasso; import io.github.kbiakov.codeview.highlight.prettify.lang.LangLisp; import io.github.kbiakov.codeview.highlight.prettify.lang.LangLlvm; +import io.github.kbiakov.codeview.highlight.prettify.lang.LangLogtalk; import io.github.kbiakov.codeview.highlight.prettify.lang.LangLua; import io.github.kbiakov.codeview.highlight.prettify.lang.LangMatlab; import io.github.kbiakov.codeview.highlight.prettify.lang.LangMd; @@ -51,6 +54,8 @@ import io.github.kbiakov.codeview.highlight.prettify.lang.LangWiki; import io.github.kbiakov.codeview.highlight.prettify.lang.LangXq; import io.github.kbiakov.codeview.highlight.prettify.lang.LangYaml; +import io.github.kbiakov.codeview.highlight.prettify.lang.LangEx; +import io.github.kbiakov.codeview.highlight.prettify.lang.LangSwift; /** * This is similar to the prettify.js in JavaScript Prettify. @@ -394,6 +399,11 @@ public Prettify() { register(LangWiki.class); register(LangXq.class); register(LangYaml.class); + register(LangEx.class); + register(LangSwift.class); + register(LangKotlin.class); + register(LangLogtalk.class); + register(LangLasso.class); } catch (Exception ex) { LOG.log(Level.SEVERE, null, ex); } diff --git a/codeview/src/main/java/io/github/kbiakov/codeview/views/LineDiffView.kt b/codeview/src/main/java/io/github/kbiakov/codeview/views/LineDiffView.kt index 996840d..ff1bcdd 100644 --- a/codeview/src/main/java/io/github/kbiakov/codeview/views/LineDiffView.kt +++ b/codeview/src/main/java/io/github/kbiakov/codeview/views/LineDiffView.kt @@ -1,10 +1,10 @@ package io.github.kbiakov.codeview.views import android.content.Context -import android.support.v4.content.ContextCompat import android.view.LayoutInflater import android.widget.RelativeLayout import android.widget.TextView +import androidx.core.content.ContextCompat import io.github.kbiakov.codeview.R import io.github.kbiakov.codeview.highlight.FontCache diff --git a/codeview/src/main/res/layout/layout_code_view.xml b/codeview/src/main/res/layout/layout_code_view.xml index 3f3d70e..44165b9 100644 --- a/codeview/src/main/res/layout/layout_code_view.xml +++ b/codeview/src/main/res/layout/layout_code_view.xml @@ -11,7 +11,7 @@ android:layout_height="wrap_content" android:fillViewport="true"> -