├── .gitattributes ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── build.gradle ├── codeview ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── assets │ ├── fonts │ │ ├── Consolas.ttf │ │ ├── CourierNew.ttf │ │ ├── DejaVuSansMono.ttf │ │ ├── DroidSansMonoSlashed.ttf │ │ ├── Inconsolata.ttf │ │ └── Monaco.ttf │ └── training-set │ │ ├── c++ │ │ ├── NaClFile.cpp │ │ ├── c++.cpp │ │ └── hstest.cpp │ │ ├── c │ │ ├── adlist.c │ │ ├── async.c │ │ ├── c.c │ │ └── cluster.c │ │ ├── coffeescript │ │ └── coffee-script.coffee │ │ ├── csharp │ │ ├── BasicAuthenticationFixture.cs │ │ ├── ChromiumWebBrowser.cs │ │ ├── MemberIdentifier.cs │ │ └── csharp.cs │ │ ├── css │ │ ├── css.css │ │ ├── new 6.txt │ │ ├── new 7.txt │ │ └── new 8.txt │ │ ├── html │ │ ├── html.html │ │ ├── index.html │ │ ├── options.html │ │ └── test.html │ │ ├── javascript │ │ ├── javascript.js │ │ ├── new 2.txt │ │ ├── new 3.txt │ │ ├── new 4.txt │ │ └── new 5.txt │ │ ├── objective-c │ │ └── objective-c.m │ │ ├── python │ │ ├── new 2.txt │ │ ├── new 3.txt │ │ ├── new 4.txt │ │ └── python.py │ │ ├── ruby │ │ ├── artifactory.rb │ │ ├── jekyll_steps.rb │ │ ├── ruby.rb │ │ └── travis.rb │ │ └── shell │ │ └── shell.sh │ ├── java │ └── io │ │ └── github │ │ └── kbiakov │ │ └── codeview │ │ ├── CodeView.kt │ │ ├── Utils.kt │ │ ├── adapters │ │ ├── AbstractCodeAdapter.kt │ │ ├── CodeWithDiffsAdapter.kt │ │ └── CodeWithNotesAdapter.kt │ │ ├── classifier │ │ ├── Classifier.kt │ │ ├── CodeClassifier.kt │ │ └── CodeProcessor.java │ │ ├── highlight │ │ ├── CodeHighlighter.kt │ │ ├── FontCache.java │ │ ├── parser │ │ │ ├── ParseResult.java │ │ │ └── Parser.java │ │ └── prettify │ │ │ ├── PrettifyParser.java │ │ │ ├── lang │ │ │ ├── Lang.java │ │ │ ├── LangAppollo.java │ │ │ ├── LangBasic.java │ │ │ ├── LangClj.java │ │ │ ├── LangCss.java │ │ │ ├── LangDart.java │ │ │ ├── LangErlang.java │ │ │ ├── LangGo.java │ │ │ ├── LangHs.java │ │ │ ├── LangLisp.java │ │ │ ├── LangLlvm.java │ │ │ ├── LangLua.java │ │ │ ├── LangMatlab.java │ │ │ ├── LangMd.java │ │ │ ├── LangMl.java │ │ │ ├── LangMumps.java │ │ │ ├── LangN.java │ │ │ ├── LangPascal.java │ │ │ ├── LangProto.java │ │ │ ├── LangR.java │ │ │ ├── LangRd.java │ │ │ ├── LangScala.java │ │ │ ├── LangSql.java │ │ │ ├── LangTcl.java │ │ │ ├── LangTex.java │ │ │ ├── LangVb.java │ │ │ ├── LangVhdl.java │ │ │ ├── LangWiki.java │ │ │ ├── LangXq.java │ │ │ ├── LangYaml.java │ │ │ └── package-info.java │ │ │ └── parser │ │ │ ├── CombinePrefixPattern.java │ │ │ ├── Job.java │ │ │ ├── Prettify.java │ │ │ └── Util.java │ │ └── views │ │ ├── BidirectionalScrollView.kt │ │ ├── LineDiffView.kt │ │ └── LineNoteView.kt │ └── res │ ├── layout │ ├── item_code_diff.xml │ ├── item_code_line.xml │ └── layout_code_view.xml │ └── values │ ├── attrs.xml │ ├── colors.xml │ ├── dimens.xml │ └── strings.xml ├── example ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── io │ │ └── github │ │ └── kbiakov │ │ └── codeviewexample │ │ ├── BaseApplication.java │ │ ├── CustomAdapter.java │ │ └── ListingsActivity.java │ └── res │ ├── layout │ ├── activity_listings.xml │ └── custom_footer.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitattributes: -------------------------------------------------------------------------------- 1 | *.cpp linguist-language=Kotlin 2 | *.c linguist-language=Kotlin 3 | *.coffee linguist-language=Kotlin 4 | *.cs linguist-language=Kotlin 5 | *.css linguist-language=Kotlin 6 | *.html linguist-language=Kotlin 7 | *.js linguist-language=Kotlin 8 | *.h linguist-language=Kotlin 9 | *.m linguist-language=Kotlin 10 | *.rb linguist-language=Kotlin 11 | *.sh linguist-language=Kotlin 12 | *.py linguist-language=Kotlin -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### Android ### 2 | # Built application files 3 | *.apk 4 | *.ap_ 5 | 6 | # Files for the Dalvik VM 7 | *.dex 8 | 9 | # Java class files 10 | *.class 11 | 12 | # Generated files 13 | bin/ 14 | gen/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | /*/build/ 20 | 21 | # Ignore Gradle GUI config 22 | gradle-app.setting 23 | 24 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 25 | !gradle-wrapper.jar 26 | 27 | # Local configuration file (sdk path, etc) 28 | local.properties 29 | 30 | # Proguard folder generated by Eclipse 31 | proguard/ 32 | 33 | # Log Files 34 | *.log 35 | 36 | ### Android Patch ### 37 | gen-external-apklibs 38 | 39 | 40 | ### Intellij ### 41 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm 42 | 43 | *.iml 44 | 45 | ## Directory-based project format: 46 | .idea/ 47 | # if you remove the above rule, at least ignore the following: 48 | 49 | # User-specific stuff: 50 | # .idea/workspace.xml 51 | # .idea/tasks.xml 52 | # .idea/dictionaries 53 | 54 | # Sensitive or high-churn files: 55 | # .idea/dataSources.ids 56 | # .idea/dataSources.xml 57 | # .idea/sqlDataSources.xml 58 | # .idea/dynamic.xml 59 | # .idea/uiDesigner.xml 60 | 61 | # Gradle: 62 | # .idea/gradle.xml 63 | # .idea/libraries 64 | 65 | # Mongo Explorer plugin: 66 | # .idea/mongoSettings.xml 67 | 68 | ## File-based project format: 69 | *.ipr 70 | *.iws 71 | 72 | ## Plugin-specific files: 73 | 74 | # IntelliJ 75 | /out/ 76 | 77 | # mpeltonen/sbt-idea plugin 78 | .idea_modules/ 79 | 80 | # JIRA plugin 81 | atlassian-ide-plugin.xml 82 | 83 | # Crashlytics plugin (for Android Studio and IntelliJ) 84 | com_crashlytics_export_strings.xml 85 | crashlytics.properties 86 | crashlytics-build.properties 87 | *.iml 88 | 89 | *.iml 90 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: android 2 | 3 | sudo: required 4 | 5 | jdk: 6 | - oraclejdk8 7 | 8 | android: 9 | components: 10 | - tools # to get the new `repository-11.xml` 11 | - tools # to install latest Android SDK tools 12 | - platform-tools 13 | - build-tools-28.0.3 14 | - android-28 15 | - extra-android-m2repository # Design Support library 16 | - android-21 17 | - sys-img-armeabi-v7a-android-21 # system image (emulator) 18 | licenses: 19 | - android-sdk-license-.+ 20 | 21 | env: 22 | global: 23 | - ADB_INSTALL_TIMEOUT=8 # timeout (in minutes) 24 | 25 | before_script: 26 | # Automatically accept all SDK licences 27 | - echo yes | android update sdk --no-ui --all --filter build-tools-28.0.3,android-28,extra-android-m2repository 28 | # Emulator Management: create, start & wait 29 | - echo no | android create avd --force -n test -t android-21 --abi armeabi-v7a 30 | - emulator -avd test -no-skin -no-audio -no-window & 31 | - android-wait-for-emulator 32 | - adb shell input keyevent 82 & 33 | 34 | script: 35 | - android list target 36 | - ./gradlew build connectedCheck 37 | - ./gradlew connectedAndroidTest 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Kirill Biakov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | ext.kotlinVersion = '1.3.11' 5 | ext.minSdk = 15 6 | ext.compileSdk = 28 7 | ext.buildTools = '28.0.3' 8 | ext.supportLibrary = '28.0.0' 9 | 10 | repositories { 11 | jcenter() 12 | google() 13 | } 14 | dependencies { 15 | classpath 'com.android.tools.build:gradle:3.3.0' 16 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" 17 | } 18 | } 19 | 20 | allprojects { 21 | repositories { 22 | jcenter() 23 | google() 24 | } 25 | } 26 | 27 | task clean(type: Delete) { 28 | delete rootProject.buildDir 29 | } 30 | -------------------------------------------------------------------------------- /codeview/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /codeview/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'kotlin-android' 3 | 4 | android { 5 | compileSdkVersion compileSdk 6 | buildToolsVersion buildTools 7 | 8 | defaultConfig { 9 | minSdkVersion minSdk 10 | targetSdkVersion compileSdk 11 | versionCode 1 12 | versionName '1.3.2' 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | lintOptions { 21 | abortOnError false 22 | } 23 | } 24 | 25 | dependencies { 26 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion" 27 | implementation "com.android.support:appcompat-v7:$supportLibrary" 28 | implementation "com.android.support:recyclerview-v7:$supportLibrary" 29 | } 30 | -------------------------------------------------------------------------------- /codeview/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/macuser/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /codeview/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /codeview/src/main/assets/fonts/Consolas.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbiakov/CodeView-Android/91ec9008effbfc1e82335ad568f177043eb9881a/codeview/src/main/assets/fonts/Consolas.ttf -------------------------------------------------------------------------------- /codeview/src/main/assets/fonts/CourierNew.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbiakov/CodeView-Android/91ec9008effbfc1e82335ad568f177043eb9881a/codeview/src/main/assets/fonts/CourierNew.ttf -------------------------------------------------------------------------------- /codeview/src/main/assets/fonts/DejaVuSansMono.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbiakov/CodeView-Android/91ec9008effbfc1e82335ad568f177043eb9881a/codeview/src/main/assets/fonts/DejaVuSansMono.ttf -------------------------------------------------------------------------------- /codeview/src/main/assets/fonts/DroidSansMonoSlashed.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbiakov/CodeView-Android/91ec9008effbfc1e82335ad568f177043eb9881a/codeview/src/main/assets/fonts/DroidSansMonoSlashed.ttf -------------------------------------------------------------------------------- /codeview/src/main/assets/fonts/Inconsolata.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbiakov/CodeView-Android/91ec9008effbfc1e82335ad568f177043eb9881a/codeview/src/main/assets/fonts/Inconsolata.ttf -------------------------------------------------------------------------------- /codeview/src/main/assets/fonts/Monaco.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbiakov/CodeView-Android/91ec9008effbfc1e82335ad568f177043eb9881a/codeview/src/main/assets/fonts/Monaco.ttf -------------------------------------------------------------------------------- /codeview/src/main/assets/training-set/c++/NaClFile.cpp: -------------------------------------------------------------------------------- 1 | 2 | #define NACLFILE_CPP 3 | #include "NaClFile.h" 4 | #include "NaClFileSystem.h" 5 | 6 | //#include 7 | //#define EOF -1 8 | 9 | FILE * nacl_fopen ( const char * path, const char *mode ) { 10 | 11 | return ( FILE * )NaClFileSystem::Get ()->fopen ( path, mode ); 12 | } 13 | 14 | int nacl_fclose ( FILE *file ) { 15 | 16 | return NaClFileSystem::Get ()->fclose ((NaClFile *) file ); 17 | } 18 | 19 | int nacl_fread ( void *ptr, int size, int count, FILE *file ) { 20 | 21 | return NaClFileSystem::Get ()->fread ( ptr, size, count, (NaClFile *) file ); 22 | } 23 | 24 | int nacl_fwrite ( const void * ptr, int size, int count, FILE *file ) { 25 | 26 | return NaClFileSystem::Get ()->fwrite ( ptr, size, count, (NaClFile *) file ); 27 | } 28 | 29 | int nacl_feof ( FILE * void_file ) { 30 | 31 | NaClFile * file = ( NaClFile * ) void_file; 32 | return ( file->mOffset == file->mSize ); 33 | } 34 | 35 | int nacl_ferror ( FILE * void_file ) { 36 | 37 | //unimplemented 38 | return 0; 39 | } 40 | 41 | void nacl_clearerr ( FILE * void_file ) { 42 | //do nothing 43 | } 44 | 45 | int nacl_fgetc ( FILE * void_file ) { 46 | 47 | NaClFile * file = ( NaClFile * ) void_file; 48 | 49 | if( file && file->mIsHttpLoaded ) { 50 | 51 | int remainingSize = file->mSize - file->mOffset; 52 | 53 | if ( remainingSize ) { 54 | int data = file->mData [ file->mOffset ]; 55 | file->mOffset += 1; 56 | return data; 57 | } 58 | else { 59 | return EOF; 60 | } 61 | } 62 | return 0; 63 | } 64 | 65 | int nacl_ungetc (int c, FILE *void_file) { 66 | 67 | NaClFile * file = ( NaClFile * ) void_file; 68 | 69 | if( file && file->mIsHttpLoaded ) { 70 | 71 | if ( file->mOffset ) { 72 | file->mOffset -= 1; 73 | file->mData [ file->mOffset ] = c; 74 | return file->mData [ file->mOffset ]; 75 | } 76 | else { 77 | return EOF; 78 | } 79 | } 80 | return 0; 81 | } 82 | 83 | int nacl_fseek ( FILE * void_file, long int offset, int origin ) { 84 | 85 | NaClFile * file = ( NaClFile * ) void_file; 86 | 87 | int originPosition; 88 | switch ( origin ) { 89 | case SEEK_SET: 90 | originPosition = 0; 91 | break; 92 | case SEEK_CUR: 93 | originPosition = file->mOffset; 94 | break; 95 | case SEEK_END: 96 | originPosition = file->mSize; 97 | break; 98 | } 99 | int position = originPosition + offset; 100 | if ( position <= file->mSize ) { 101 | 102 | file->mOffset = position; 103 | return 0; 104 | } 105 | 106 | return -1; 107 | } 108 | 109 | long int nacl_ftell ( FILE * void_file ) { 110 | 111 | NaClFile * file = ( NaClFile * ) void_file; 112 | 113 | return file->mOffset; 114 | } 115 | 116 | int nacl_stat ( const char *path, struct stat *s ) { 117 | 118 | //open file with Head 119 | int foundFile = NaClFileSystem::Get ()->stat ( path, s ); 120 | 121 | if ( !foundFile ) { 122 | 123 | s->st_mode = S_IFREG; 124 | s->st_ctime = 0; 125 | s->st_mtime = 0; 126 | s->st_atime = 0; 127 | 128 | return 0; 129 | } 130 | 131 | return -1; 132 | } 133 | 134 | char *nacl_getcwd(char *buf, size_t size) { 135 | 136 | for ( int i = 0; i < size; ++i ) { 137 | buf [ i ] = ( char ) 0; 138 | } 139 | 140 | buf [ 0 ] = '/'; 141 | 142 | return buf; 143 | } 144 | -------------------------------------------------------------------------------- /codeview/src/main/assets/training-set/csharp/csharp.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Reflection; 6 | using CodeClassifier.StringTokenizer; 7 | 8 | namespace CodeClassifier 9 | { 10 | public class CodeClassifier 11 | { 12 | private static CodeClassifier _instance; 13 | 14 | private const double SCORE_MULTIPLIER_PER_LEVEL = 2; 15 | private const double SCORE_MULTIPLIER_FOR_EXACT_MATCH = 5; 16 | 17 | private static List _matchTrees; 18 | 19 | private CodeClassifier() 20 | { 21 | string trainingSetPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); 22 | if (trainingSetPath == null) 23 | { 24 | throw new DirectoryNotFoundException("Could not find the training-set folder."); 25 | } 26 | 27 | // Train classifier 28 | string path = Path.Combine(trainingSetPath, "training-set"); 29 | string[] folders = Directory.GetDirectories(path); 30 | foreach (string folder in folders) 31 | { 32 | string[] files = Directory.GetFiles(folder); 33 | _matchTrees = new List(); 34 | foreach (string filePath in files) 35 | { 36 | string languageName = Path.GetFileNameWithoutExtension(filePath); 37 | if (languageName != null) 38 | { 39 | // Calculate the total possible score to normalize the score results 40 | double totalPossibleScore; 41 | TokenNode rootNode = BuildMatchTree(File.ReadAllText(filePath), out totalPossibleScore); 42 | _matchTrees.Add(new MatchTree(rootNode, languageName, totalPossibleScore)); 43 | } 44 | } 45 | } 46 | } 47 | 48 | private static TokenNode BuildMatchTree(string trainingCode, out double totalScorePossible) 49 | { 50 | List tokens = GetAllTokens(trainingCode); 51 | 52 | // Recursivly build the tree 53 | TokenNode root = new TokenNode(TokenKind.Unknown, 0, 1, null); 54 | double totalScore = 0; 55 | for (int index = 0; index < tokens.Count-1; index++) 56 | { 57 | totalScore += AddTokens(root, tokens, index); 58 | } 59 | 60 | totalScorePossible = totalScore; 61 | return root; 62 | } 63 | 64 | private static double AddTokens(TokenNode tokenNode, IList tokens, int index) 65 | { 66 | double totalScore = 0; 67 | while (index < tokens.Count && tokenNode.Level < 10) 68 | { 69 | Token codeToken = tokens[index]; 70 | TokenNode nextTreeToken = tokenNode.NextTokens.FirstOrDefault(nt => nt.Kind == codeToken.Kind); 71 | if (nextTreeToken == null) 72 | { 73 | // Token doesn't exist on this tree level yet 74 | var newToken = new TokenNode(codeToken.Kind, tokenNode.Level + 1, tokenNode.Score * SCORE_MULTIPLIER_PER_LEVEL, codeToken.Value); 75 | totalScore += tokenNode.Score * SCORE_MULTIPLIER_PER_LEVEL; 76 | tokenNode.NextTokens.Add(newToken); 77 | tokenNode = newToken; 78 | } 79 | else 80 | { 81 | // Token already exists on this level 82 | nextTreeToken.Examples.Add(codeToken.Value); 83 | tokenNode = nextTreeToken; 84 | } 85 | index++; 86 | } 87 | return totalScore; 88 | } 89 | 90 | private static List GetAllTokens(string code) 91 | { 92 | StringTokenizer.StringTokenizer stringTokenizer = new StringTokenizer.StringTokenizer(code); 93 | 94 | List tokens = new List(); 95 | Token token; 96 | do 97 | { 98 | token = stringTokenizer.Next(); 99 | tokens.Add(token); 100 | } while (token.Kind != TokenKind.Eof); 101 | return tokens; 102 | } 103 | 104 | public static string Classify(string snippet ) 105 | { 106 | // ReSharper disable once RedundantAssignment 107 | Dictionary scores; 108 | return Classify(snippet, out scores); 109 | } 110 | 111 | public static string Classify(string snippet, out Dictionary scores ) 112 | { 113 | if (_instance == null) 114 | { 115 | _instance = new CodeClassifier(); 116 | } 117 | 118 | scores = new Dictionary(); 119 | 120 | List tokens = GetAllTokens(snippet); 121 | double maxScore = 0; 122 | string bestMatchLanguage = null; 123 | 124 | foreach (MatchTree matchTree in _matchTrees) 125 | { 126 | double score = 0; 127 | for (int index = 0; index < tokens.Count; index++) 128 | { 129 | score += ScoreTokens(matchTree.MatchTreeRoot, tokens, index); 130 | } 131 | score = score / tokens.Count() / matchTree.TotalPossibleScore; 132 | 133 | //Console.WriteLine(matchTree.Language + "\t" + score); 134 | scores.Add(matchTree.Language, score); 135 | if (score > maxScore) 136 | { 137 | maxScore = score; 138 | bestMatchLanguage = matchTree.Language; 139 | } 140 | } 141 | return bestMatchLanguage; 142 | } 143 | 144 | private static double ScoreTokens(TokenNode tokenNode, IList tokens, int index) 145 | { 146 | Token codeToken = tokens[index]; 147 | TokenNode nextToken = tokenNode.NextTokens.FirstOrDefault(nt => nt.Kind == codeToken.Kind); 148 | if (nextToken != null) 149 | { 150 | // Token exists in match tree => points !!! 151 | double score = nextToken.Examples.Contains(codeToken.Value) ? 152 | SCORE_MULTIPLIER_FOR_EXACT_MATCH: 153 | SCORE_MULTIPLIER_PER_LEVEL; 154 | 155 | if (index < tokens.Count() - 1) 156 | { 157 | return score * ScoreTokens(nextToken, tokens, index + 1); 158 | } 159 | return score; 160 | } 161 | // Token did not exist => no points 162 | return 1; 163 | } 164 | } 165 | } -------------------------------------------------------------------------------- /codeview/src/main/assets/training-set/css/css.css: -------------------------------------------------------------------------------- 1 | 2 | html { 3 | margin: 0; 4 | padding: 0; 5 | border: 0; 6 | -moz-transition: all; 7 | -o-transition: all; 8 | -webkit-transition: all; 9 | transition: all; 10 | } 11 | 12 | .hidden { 13 | display: none !important; 14 | visibility: hidden !important; 15 | } 16 | 17 | body { 18 | stroke: #eee; 19 | stroke-width: 2; 20 | stroke-dasharray: 0; 21 | } 22 | 23 | a { 24 | text-align: center; 25 | font-size: 1.1rem; 26 | padding: 12px 0; 27 | } 28 | 29 | li { 30 | -webkit-touch-callout: none; 31 | -moz-user-select: none; 32 | -ms-user-select: none; 33 | -webkit-user-select: none; 34 | user-select: none; 35 | } 36 | 37 | /* points of interest */ 38 | ul > li { 39 | stroke: steelblue; 40 | stroke-width: 2; 41 | fill: #FFF; 42 | -moz-transform-origin: center; 43 | -ms-transform-origin: center; 44 | -o-transform-origin: center; 45 | -webkit-transform-origin: center; 46 | transform-origin: center; 47 | } 48 | 49 | a + div { 50 | background-size: cover; 51 | } 52 | 53 | 54 | 55 | div { 56 | background: #fff; 57 | } 58 | 59 | .n2-charts-close { 60 | font-size: 32px; 61 | position: absolute; 62 | top: 20px; 63 | right: 20px; 64 | padding: 2px 12px; 65 | cursor: pointer; 66 | } 67 | 68 | /* Landscape styles */ 69 | @media screen and (orientation:landscape) { 70 | 71 | .chart.fullscreen { 72 | font-size: 32px; 73 | position: absolute; 74 | top: 20px; 75 | right: 20px; 76 | padding: 2px 12px; 77 | cursor: pointer; 78 | } 79 | } 80 | 81 | @-moz-keyframes n2-poi-blink { 82 | 0% { 83 | -moz-transform: scale(1); 84 | -ms-transform: scale(1); 85 | -o-transform: scale(1); 86 | -webkit-transform: scale(1); 87 | transform: scale(1); 88 | } 89 | 90 | 100% { 91 | -moz-transform: scale(1); 92 | -ms-transform: scale(1); 93 | -o-transform: scale(1); 94 | -webkit-transform: scale(1); 95 | transform: scale(1); 96 | } 97 | } 98 | 99 | @-ms-keyframes n2-poi-blink { 100 | 0% { 101 | -moz-transform: scale(1); 102 | -ms-transform: scale(1); 103 | -o-transform: scale(1); 104 | -webkit-transform: scale(1); 105 | transform: scale(1); 106 | } 107 | 108 | 100% { 109 | -moz-transform: scale(1); 110 | -ms-transform: scale(1); 111 | -o-transform: scale(1); 112 | -webkit-transform: scale(1); 113 | transform: scale(1); 114 | } 115 | } 116 | 117 | @-webkit-keyframes n2-poi-blink { 118 | 0% { 119 | -moz-transform: scale(1); 120 | -ms-transform: scale(1); 121 | -o-transform: scale(1); 122 | -webkit-transform: scale(1); 123 | transform: scale(1); 124 | } 125 | 126 | 100% { 127 | -moz-transform: scale(1); 128 | -ms-transform: scale(1); 129 | -o-transform: scale(1); 130 | -webkit-transform: scale(1); 131 | transform: scale(1); 132 | } 133 | } 134 | 135 | @keyframes n2-poi-blink { 136 | 0% { 137 | -moz-transform: scale(1); 138 | -ms-transform: scale(1); 139 | -o-transform: scale(1); 140 | -webkit-transform: scale(1); 141 | transform: scale(1); 142 | } 143 | 144 | 100% { 145 | -moz-transform: scale(1); 146 | -ms-transform: scale(1); 147 | -o-transform: scale(1); 148 | -webkit-transform: scale(1); 149 | transform: scale(1); 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /codeview/src/main/assets/training-set/ruby/artifactory.rb: -------------------------------------------------------------------------------- 1 | class Artifactory < Formula 2 | desc "Manages binaries" 3 | homepage "http://www.jfrog.com/artifactory/" 4 | url "https://dl.bintray.com/jfrog/artifactory/artifactory-3.8.0.zip" 5 | sha1 "ade88a068f58a3847f9591ee0b9bfd0bcbd20049" 6 | 7 | depends_on :java => "1.7+" 8 | 9 | option "with-low-heap", "Run artifactory with low Java memory options. Useful for development machines. Do not use in production." 10 | option "with-java8", "Adjust memory settings for Java 8" 11 | 12 | def install 13 | # Remove Windows binaries 14 | rm_f Dir["bin/*.bat"] 15 | rm_f Dir["bin/*.exe"] 16 | 17 | # Set correct working directory 18 | inreplace "bin/artifactory.sh", 19 | 'export ARTIFACTORY_HOME="$(cd "$(dirname "${artBinDir}")" && pwd)"', 20 | "export ARTIFACTORY_HOME=#{libexec}" 21 | 22 | # Remove obsolete parameters for Java 8 23 | inreplace "bin/artifactory.default", 24 | "-server -Xms512m -Xmx2g -Xss256k -XX:PermSize=128m -XX:MaxPermSize=256m -XX:+UseG1GC", 25 | "-server -Xms512m -Xmx2g -Xss256k -XX:+UseG1GC" if build.with? "java8" 26 | 27 | # Reduce memory consumption for non production use 28 | inreplace "bin/artifactory.default", 29 | "-server -Xms512m -Xmx2g", 30 | "-Xms128m -Xmx768m" if build.with? "low-heap" 31 | 32 | libexec.install Dir["*"] 33 | 34 | # Launch Script 35 | bin.install_symlink libexec/"bin/artifactory.sh" 36 | # Memory Options 37 | bin.install_symlink libexec/"bin/artifactory.default" 38 | end 39 | 40 | def post_install 41 | # Create persistent data directory. Artifactory heavily relies on the data 42 | # directory being directly under ARTIFACTORY_HOME. 43 | # Therefore, we symlink the data dir to var. 44 | data = var/"artifactory" 45 | data.mkpath 46 | 47 | libexec.install_symlink data => "data" 48 | end 49 | 50 | plist_options :manual => "#{HOMEBREW_PREFIX}/opt/artifactory/libexec/bin/artifactory.sh" 51 | 52 | def plist; <<-EOS.undent 53 | 54 | 55 | 56 | 57 | Label 58 | com.jfrog.artifactory 59 | 60 | WorkingDirectory 61 | #{libexec} 62 | 63 | Program 64 | bin/artifactory.sh 65 | 66 | KeepAlive 67 | 68 | 69 | 70 | EOS 71 | end 72 | 73 | test do 74 | output = shell_output("#{bin}/artifactory.sh check 2>&1", 1) 75 | assert output.include?("Checking arguments to Artifactory") 76 | end 77 | end 78 | -------------------------------------------------------------------------------- /codeview/src/main/assets/training-set/ruby/jekyll_steps.rb: -------------------------------------------------------------------------------- 1 | def file_content_from_hash(input_hash) 2 | matter_hash = input_hash.reject { |k, v| k == "content" } 3 | matter = matter_hash.map { |k, v| "#{k}: #{v}\n" }.join.chomp 4 | 5 | content = if input_hash['input'] && input_hash['filter'] 6 | "{{ #{input_hash['input']} | #{input_hash['filter']} }}" 7 | else 8 | input_hash['content'] 9 | end 10 | 11 | <<-EOF 12 | --- 13 | #{matter} 14 | --- 15 | #{content} 16 | EOF 17 | end 18 | 19 | Before do 20 | FileUtils.mkdir_p(TEST_DIR) unless File.exist?(TEST_DIR) 21 | Dir.chdir(TEST_DIR) 22 | end 23 | 24 | After do 25 | FileUtils.rm_rf(TEST_DIR) if File.exist?(TEST_DIR) 26 | FileUtils.rm(JEKYLL_COMMAND_OUTPUT_FILE) if File.exist?(JEKYLL_COMMAND_OUTPUT_FILE) 27 | Dir.chdir(File.dirname(TEST_DIR)) 28 | end 29 | 30 | World do 31 | MinitestWorld.new 32 | end 33 | 34 | Given /^I have a blank site in "(.*)"$/ do |path| 35 | FileUtils.mkdir_p(path) unless File.exist?(path) 36 | end 37 | 38 | Given /^I do not have a "(.*)" directory$/ do |path| 39 | File.directory?("#{TEST_DIR}/#{path}") 40 | end 41 | 42 | # Like "I have a foo file" but gives a yaml front matter so jekyll actually processes it 43 | Given /^I have an? "(.*)" page(?: with (.*) "(.*)")? that contains "(.*)"$/ do |file, key, value, text| 44 | File.open(file, 'w') do |f| 45 | f.write <<-EOF 46 | --- 47 | #{key || 'layout'}: #{value || 'nil'} 48 | --- 49 | #{text} 50 | EOF 51 | end 52 | end 53 | 54 | Given /^I have an? "(.*)" file that contains "(.*)"$/ do |file, text| 55 | File.open(file, 'w') do |f| 56 | f.write(text) 57 | end 58 | end 59 | 60 | Given /^I have an? (.*) (layout|theme) that contains "(.*)"$/ do |name, type, text| 61 | folder = if type == 'layout' 62 | '_layouts' 63 | else 64 | '_theme' 65 | end 66 | destination_file = File.join(folder, name + '.html') 67 | destination_path = File.dirname(destination_file) 68 | unless File.exist?(destination_path) 69 | FileUtils.mkdir_p(destination_path) 70 | end 71 | File.open(destination_file, 'w') do |f| 72 | f.write(text) 73 | end 74 | end 75 | 76 | Given /^I have an? "(.*)" file with content:$/ do |file, text| 77 | File.open(file, 'w') do |f| 78 | f.write(text) 79 | end 80 | end 81 | 82 | Given /^I have an? (.*) directory$/ do |dir| 83 | FileUtils.mkdir_p(dir) 84 | end 85 | 86 | Given /^I have the following (draft|page|post)s?(?: (in|under) "([^"]+)")?:$/ do |status, direction, folder, table| 87 | table.hashes.each do |input_hash| 88 | title = slug(input_hash['title']) 89 | ext = input_hash['type'] || 'markdown' 90 | before, after = location(folder, direction) 91 | 92 | case status 93 | when "draft" 94 | dest_folder = '_drafts' 95 | filename = "#{title}.#{ext}" 96 | when "page" 97 | dest_folder = '' 98 | filename = "#{title}.#{ext}" 99 | when "post" 100 | parsed_date = Time.xmlschema(input_hash['date']) rescue Time.parse(input_hash['date']) 101 | dest_folder = '_posts' 102 | filename = "#{parsed_date.strftime('%Y-%m-%d')}-#{title}.#{ext}" 103 | end 104 | 105 | path = File.join(before, dest_folder, after, filename) 106 | File.open(path, 'w') do |f| 107 | f.write file_content_from_hash(input_hash) 108 | end 109 | end 110 | end 111 | 112 | Given /^I have a configuration file with "(.*)" set to "(.*)"$/ do |key, value| 113 | File.open('_config.yml', 'w') do |f| 114 | f.write("#{key}: #{value}\n") 115 | end 116 | end 117 | 118 | Given /^I have a configuration file with:$/ do |table| 119 | File.open('_config.yml', 'w') do |f| 120 | table.hashes.each do |row| 121 | f.write("#{row["key"]}: #{row["value"]}\n") 122 | end 123 | end 124 | end 125 | 126 | Given /^I have a configuration file with "([^\"]*)" set to:$/ do |key, table| 127 | File.open('_config.yml', 'w') do |f| 128 | f.write("#{key}:\n") 129 | table.hashes.each do |row| 130 | f.write("- #{row["value"]}\n") 131 | end 132 | end 133 | end 134 | 135 | Given /^I have fixture collections$/ do 136 | FileUtils.cp_r File.join(JEKYLL_SOURCE_DIR, "test", "source", "_methods"), source_dir 137 | end 138 | 139 | Given /^I wait (\d+) second(s?)$/ do |time, plural| 140 | sleep(time.to_f) 141 | end 142 | 143 | ################## 144 | # 145 | # Changing stuff 146 | # 147 | ################## 148 | 149 | When /^I run jekyll(.*)$/ do |args| 150 | status = run_jekyll(args) 151 | if args.include?("--verbose") || ENV['DEBUG'] 152 | puts jekyll_run_output 153 | end 154 | end 155 | 156 | When /^I run bundle(.*)$/ do |args| 157 | status = run_bundle(args) 158 | if args.include?("--verbose") || ENV['DEBUG'] 159 | puts jekyll_run_output 160 | end 161 | end 162 | 163 | When /^I change "(.*)" to contain "(.*)"$/ do |file, text| 164 | File.open(file, 'a') do |f| 165 | f.write(text) 166 | end 167 | end 168 | 169 | When /^I delete the file "(.*)"$/ do |file| 170 | File.delete(file) 171 | end 172 | 173 | ################## 174 | # 175 | # Checking stuff 176 | # 177 | ################## 178 | 179 | Then /^the (.*) directory should +exist$/ do |dir| 180 | assert File.directory?(dir), "The directory \"#{dir}\" does not exist" 181 | end 182 | 183 | Then /^the (.*) directory should not exist$/ do |dir| 184 | assert !File.directory?(dir), "The directory \"#{dir}\" exists" 185 | end 186 | 187 | Then /^I should see "(.*)" in "(.*)"$/ do |text, file| 188 | assert_match Regexp.new(text, Regexp::MULTILINE), file_contents(file) 189 | end 190 | 191 | Then /^I should see exactly "(.*)" in "(.*)"$/ do |text, file| 192 | assert_equal text, file_contents(file).strip 193 | end 194 | 195 | Then /^I should not see "(.*)" in "(.*)"$/ do |text, file| 196 | refute_match Regexp.new(text, Regexp::MULTILINE), file_contents(file) 197 | end 198 | 199 | Then /^I should see escaped "(.*)" in "(.*)"$/ do |text, file| 200 | assert_match Regexp.new(Regexp.escape(text)), file_contents(file) 201 | end 202 | 203 | Then /^the "(.*)" file should +exist$/ do |file| 204 | file_does_exist = File.file?(file) 205 | unless file_does_exist 206 | all_steps_to_path(file).each do |dir| 207 | STDERR.puts "" 208 | STDERR.puts "Dir #{dir}:" 209 | STDERR.puts Dir["#{dir}/**/*"] 210 | end 211 | end 212 | assert file_does_exist, "The file \"#{file}\" does not exist.\n" 213 | end 214 | 215 | Then /^the "(.*)" file should not exist$/ do |file| 216 | assert !File.exist?(file), "The file \"#{file}\" exists" 217 | end 218 | 219 | Then /^I should see today's time in "(.*)"$/ do |file| 220 | assert_match Regexp.new(seconds_agnostic_time(Time.now)), file_contents(file) 221 | end 222 | 223 | Then /^I should see today's date in "(.*)"$/ do |file| 224 | assert_match Regexp.new(Date.today.to_s), file_contents(file) 225 | end 226 | 227 | Then /^I should see "(.*)" in the build output$/ do |text| 228 | assert_match Regexp.new(text), jekyll_run_output 229 | end 230 | -------------------------------------------------------------------------------- /codeview/src/main/assets/training-set/ruby/travis.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'fileutils' 3 | include FileUtils 4 | 5 | commands = [ 6 | 'mysql -e "create database activerecord_unittest;"', 7 | 'mysql -e "create database activerecord_unittest2;"', 8 | 'psql -c "create database activerecord_unittest;" -U postgres', 9 | 'psql -c "create database activerecord_unittest2;" -U postgres' 10 | ] 11 | 12 | commands.each do |command| 13 | system("#{command} > /dev/null 2>&1") 14 | end 15 | 16 | class Build 17 | MAP = { 18 | 'railties' => 'railties', 19 | 'ap' => 'actionpack', 20 | 'am' => 'actionmailer', 21 | 'amo' => 'activemodel', 22 | 'as' => 'activesupport', 23 | 'ar' => 'activerecord', 24 | 'av' => 'actionview', 25 | 'aj' => 'activejob', 26 | 'guides' => 'guides' 27 | } 28 | 29 | attr_reader :component, :options 30 | 31 | def initialize(component, options = {}) 32 | @component = component 33 | @options = options 34 | end 35 | 36 | def run!(options = {}) 37 | self.options.update(options) 38 | Dir.chdir(dir) do 39 | announce(heading) 40 | if guides? 41 | run_bug_report_templates 42 | else 43 | rake(*tasks) 44 | end 45 | end 46 | end 47 | 48 | def announce(heading) 49 | puts "\n\e[1;33m[Travis CI] #{heading}\e[m\n" 50 | end 51 | 52 | def heading 53 | heading = [gem] 54 | heading << "with #{adapter}" if activerecord? 55 | heading << "in isolation" if isolated? 56 | heading << "integration" if integration? 57 | heading.join(' ') 58 | end 59 | 60 | def tasks 61 | if activerecord? 62 | ['db:mysql:rebuild', "#{adapter}:#{'isolated_' if isolated?}test"] 63 | else 64 | ["test", ('isolated' if isolated?), ('integration' if integration?)].compact.join(":") 65 | end 66 | end 67 | 68 | def key 69 | key = [gem] 70 | key << adapter if activerecord? 71 | key << 'isolated' if isolated? 72 | key.join(':') 73 | end 74 | 75 | def activerecord? 76 | gem == 'activerecord' 77 | end 78 | 79 | def guides? 80 | gem == 'guides' 81 | end 82 | 83 | def isolated? 84 | options[:isolated] 85 | end 86 | 87 | def integration? 88 | component.split(':').last == 'integration' 89 | end 90 | 91 | def gem 92 | MAP[component.split(':').first] 93 | end 94 | alias :dir :gem 95 | 96 | def adapter 97 | component.split(':').last 98 | end 99 | 100 | def rake(*tasks) 101 | tasks.each do |task| 102 | cmd = "bundle exec rake #{task}" 103 | puts "Running command: #{cmd}" 104 | return false unless system(cmd) 105 | end 106 | true 107 | end 108 | 109 | def run_bug_report_templates 110 | Dir.glob('bug_report_templates/*.rb').all? do |file| 111 | system(Gem.ruby, '-w', file) 112 | end 113 | end 114 | end 115 | 116 | if ENV['GEM']=='aj:integration' 117 | ENV['QC_DATABASE_URL'] = 'postgres://postgres@localhost/active_jobs_qc_int_test' 118 | ENV['QUE_DATABASE_URL'] = 'postgres://postgres@localhost/active_jobs_que_int_test' 119 | end 120 | 121 | results = {} 122 | 123 | ENV['GEM'].split(',').each do |gem| 124 | [false, true].each do |isolated| 125 | next if ENV['TRAVIS_PULL_REQUEST'] && ENV['TRAVIS_PULL_REQUEST'] != 'false' && isolated 126 | next if gem == 'railties' && isolated 127 | next if gem == 'aj:integration' && isolated 128 | next if gem == 'guides' && isolated 129 | 130 | build = Build.new(gem, :isolated => isolated) 131 | results[build.key] = build.run! 132 | 133 | end 134 | end 135 | 136 | # puts 137 | # puts "Build environment:" 138 | # puts " #{`cat /etc/issue`}" 139 | # puts " #{`uname -a`}" 140 | # puts " #{`ruby -v`}" 141 | # puts " #{`mysql --version`}" 142 | # puts " #{`pg_config --version`}" 143 | # puts " SQLite3: #{`sqlite3 -version`}" 144 | # `gem env`.each_line {|line| print " #{line}"} 145 | # puts " Bundled gems:" 146 | # `bundle show`.each_line {|line| print " #{line}"} 147 | # puts " Local gems:" 148 | # `gem list`.each_line {|line| print " #{line}"} 149 | 150 | failures = results.select { |key, value| !value } 151 | 152 | if failures.empty? 153 | puts 154 | puts "Rails build finished successfully" 155 | exit(true) 156 | else 157 | puts 158 | puts "Rails build FAILED" 159 | puts "Failed components: #{failures.map(&:first).join(', ')}" 160 | exit(false) 161 | end 162 | -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/Utils.kt: -------------------------------------------------------------------------------- 1 | package io.github.kbiakov.codeview 2 | 3 | import android.content.Context 4 | import android.os.Handler 5 | import android.os.Looper 6 | import android.text.Html 7 | import android.text.SpannableString 8 | import android.text.Spanned 9 | import android.text.TextUtils 10 | import android.util.TypedValue 11 | import java.io.BufferedReader 12 | import java.io.InputStreamReader 13 | import java.util.concurrent.Executors 14 | 15 | object Const { 16 | val DefaultDelay = 250L 17 | 18 | object Alpha { 19 | val Visible = 1f 20 | val Initial = 0.7f 21 | 22 | val AlmostInvisible = 0.1f 23 | val Invisible = 0f 24 | } 25 | } 26 | 27 | /** 28 | * Get px by dip value. 29 | * 30 | * @param context Context 31 | * @param dp Dip value 32 | * @return Converted to px value 33 | */ 34 | fun dpToPx(context: Context, dp: Int) = 35 | TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 36 | dp.toFloat(), context.resources.displayMetrics).toInt() 37 | 38 | /** 39 | * Split string by space. 40 | * 41 | * @param source Source 42 | * @return Split string 43 | */ 44 | fun spaceSplit(source: String) = source.split("\\s".toRegex()) 45 | 46 | /** 47 | * Split string for lines. 48 | * 49 | * @param source Source 50 | * @return Split string 51 | */ 52 | fun extractLines(source: String) = listOf(*source.split("\n").toTypedArray()) 53 | 54 | /** 55 | * Slice list by index. 56 | * 57 | * @param idx Index to slice 58 | * @return Pair of lists with head and tail 59 | */ 60 | fun List.slice(idx: Int) = Pair(subList(0, idx), subList(idx, lastIndex)) 61 | 62 | /** 63 | * Get HTML from string. 64 | * 65 | * @param content Source 66 | * @return Spanned HTML string 67 | */ 68 | @Suppress("deprecation") 69 | fun html(content: String): Spanned { 70 | val spanned = if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) 71 | Html.fromHtml(content, Html.FROM_HTML_MODE_LEGACY) 72 | else 73 | Html.fromHtml(content) 74 | val spaces = content.startSpacesForTaggedString() 75 | return SpannableString(TextUtils.concat(spaces, spanned)) 76 | } 77 | 78 | private fun String.startSpacesForTaggedString(): String { 79 | val startIdx = indexOf('>') + 1 80 | val escaped = substring(startIdx) 81 | val count = escaped.indexOf(escaped.trim()) 82 | return " ".repeat(count) 83 | } 84 | 85 | object Thread { 86 | /** 87 | * Perform async operation. 88 | * 89 | * @param body Operation body 90 | */ 91 | fun async(body: () -> Unit) { 92 | Executors.newSingleThreadExecutor().submit(body) 93 | } 94 | 95 | /** 96 | * Perform UI operation. 97 | * 98 | * @param body Operation body 99 | */ 100 | fun ui(body: () -> Unit) { 101 | Handler(Looper.getMainLooper()).post(body) 102 | } 103 | 104 | /** 105 | * Delayed block call. 106 | * 107 | * @param body Operation body 108 | * @param delayMs Delay in m 109 | */ 110 | fun delayed(delayMs: Long = Const.DefaultDelay, body: () -> Unit) { 111 | Handler().postDelayed(body, delayMs) 112 | } 113 | 114 | // - Extensions for block manipulations 115 | 116 | fun (() -> Unit).ui(isUi: Boolean = true) { 117 | if (isUi) ui(this) else this() 118 | } 119 | } 120 | 121 | object Files { 122 | /** 123 | * Get list of files in folder by path. 124 | * 125 | * @param context Context 126 | * @param path Path 127 | * @return List of files 128 | */ 129 | fun ls(context: Context, path: String) = context.assets.list(path) 130 | 131 | /** 132 | * Merge files into one string by path. 133 | * 134 | * @param context Context 135 | * @param path Path 136 | * @return Merged content 137 | */ 138 | fun content(context: Context, path: String): String { 139 | var content = "" 140 | 141 | ls(context, path).forEach { filename -> 142 | val input = context.assets.open("$path/$filename") 143 | 144 | BufferedReader(InputStreamReader(input, "UTF-8")).useLines { 145 | content += it.reduce { acc, line -> acc + line } 146 | } 147 | } 148 | return content 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/adapters/CodeWithDiffsAdapter.kt: -------------------------------------------------------------------------------- 1 | package io.github.kbiakov.codeview.adapters 2 | 3 | import android.content.Context 4 | import io.github.kbiakov.codeview.views.DiffModel 5 | import io.github.kbiakov.codeview.views.LineDiffView 6 | 7 | /** 8 | * @class CodeWithDiffsAdapter 9 | * 10 | * Code content adapter with ability to add diffs (additions & deletions) in footer. 11 | * 12 | * @author Kirill Biakov 13 | */ 14 | open class CodeWithDiffsAdapter : AbstractCodeAdapter { 15 | 16 | constructor(context: Context) : super(context) 17 | 18 | constructor(context: Context, code: String) : super(context, code) 19 | 20 | constructor(context: Context, options: Options) : super(context, options) 21 | 22 | /** 23 | * Create footer view. 24 | * 25 | * @param entity Note content 26 | * @param isFirst Is first footer 27 | */ 28 | override fun createFooter(context: Context, entity: DiffModel, isFirst: Boolean) = 29 | LineDiffView.create(context, entity) 30 | } 31 | -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/adapters/CodeWithNotesAdapter.kt: -------------------------------------------------------------------------------- 1 | package io.github.kbiakov.codeview.adapters 2 | 3 | import android.content.Context 4 | import io.github.kbiakov.codeview.highlight.color 5 | import io.github.kbiakov.codeview.views.LineNoteView 6 | 7 | /** 8 | * @class CodeWithNotesAdapter 9 | * 10 | * Default code content adapter. 11 | * 12 | * @author Kirill Biakov 13 | */ 14 | open class CodeWithNotesAdapter : AbstractCodeAdapter { 15 | 16 | constructor(context: Context) : super(context) 17 | 18 | constructor(context: Context, code: String) : super(context, code) 19 | 20 | constructor(context: Context, options: Options) : super(context, options) 21 | 22 | /** 23 | * Create footer view. 24 | * 25 | * @param entity Note content 26 | * @param isFirst Is first footer view 27 | */ 28 | override fun createFooter(context: Context, entity: String, isFirst: Boolean) = 29 | LineNoteView.create(context, 30 | text = entity, 31 | isFirst = isFirst, 32 | bgColor = options.theme.bgNum.color(), 33 | textColor = options.theme.noteColor.color()) 34 | } 35 | -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/classifier/CodeClassifier.kt: -------------------------------------------------------------------------------- 1 | package io.github.kbiakov.codeview.classifier 2 | 3 | import android.content.Context 4 | import android.util.Log 5 | import io.github.kbiakov.codeview.Files 6 | import io.github.kbiakov.codeview.spaceSplit 7 | 8 | /** 9 | * @class CodeClassifier 10 | * 11 | * Code classifier based on Naive Bayes Classifier is necessary to define 12 | * what language is used in presented code snippet. 13 | * 14 | * @author Kirill Biakov 15 | */ 16 | object CodeClassifier { 17 | 18 | const val TAG = "CodeClassifier" 19 | 20 | /** 21 | * Default is the most popular programming language - JavaScript, 22 | * because it covers most of keywords & syntax constructions. 23 | * 24 | * (Highlighting should work not so bad even if this is not yours.) 25 | */ 26 | const val DEFAULT_LANGUAGE = "js" 27 | 28 | private val TRAINING_SET_FOLDER = "training-set" 29 | 30 | private val classifier: BayesClassifier 31 | 32 | /** 33 | * Create Naive Bayes classifier at start. 34 | */ 35 | init { 36 | classifier = BayesClassifier() 37 | } 38 | 39 | /** 40 | * At this point all files with code listings prepared to process 41 | * by classifier. This operation often is very expensive & should 42 | * be performed asynchronously when app starts. 43 | * 44 | * @param context Context 45 | */ 46 | fun train(context: Context) { 47 | Files.ls(context, TRAINING_SET_FOLDER).forEach { language -> 48 | val path = "$TRAINING_SET_FOLDER/$language" 49 | val content = Files.content(context, path) 50 | classifier.learn(language, spaceSplit(content)) 51 | } 52 | 53 | Log.i(TAG, "Classifier trained") 54 | } 55 | 56 | /** 57 | * Try to define what language is used in code snippet. 58 | * 59 | * @param snippet Code snippet 60 | * @return Code language 61 | */ 62 | fun classify(snippet: String): String { 63 | val feature = classifier.classify(spaceSplit(snippet)) 64 | return feature?.category ?: DEFAULT_LANGUAGE 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/classifier/CodeProcessor.java: -------------------------------------------------------------------------------- 1 | package io.github.kbiakov.codeview.classifier; 2 | 3 | import android.content.Context; 4 | 5 | import java.util.concurrent.Callable; 6 | import java.util.concurrent.ExecutionException; 7 | import java.util.concurrent.ExecutorService; 8 | import java.util.concurrent.Executors; 9 | import java.util.concurrent.Future; 10 | 11 | /** 12 | * @class CodeProcessor 13 | * 14 | * Provides easy interface to code classifier. It response for train 15 | * code classifier & classifying code by code snippet. Both tasks 16 | * delegated to code classifier, but wrapped in extremely simple 17 | * interface to avoid possible errors. 18 | * 19 | * @author Kirill Biakov 20 | */ 21 | public class CodeProcessor { 22 | 23 | private static final String TAG = "CodeClassifier"; 24 | 25 | private static volatile CodeProcessor sInstance; 26 | private static Future sTrainingTaskFuture; 27 | 28 | /** 29 | * Thread-safe code processor getter. 30 | * 31 | * If instance was not created or trained, it performs necessary operations. 32 | * 33 | * @param context Context 34 | * @return Code processor instance 35 | */ 36 | public static CodeProcessor getInstance(Context context) { 37 | if (notInstanceAvailable()) { 38 | synchronized (CodeClassifier.class) { 39 | if (notInstanceAvailable()) { 40 | sInstance = new CodeProcessor(context); 41 | } 42 | } 43 | } 44 | return sInstance; 45 | } 46 | 47 | /** 48 | * Private (and only one) constructor. 49 | * 50 | * Code processor creation instantiate code classifier training task. 51 | * 52 | * @param context Context 53 | */ 54 | private CodeProcessor(Context context) { 55 | CodeClassifier.INSTANCE.train(context); 56 | } 57 | 58 | /** 59 | * Code processor should be created ones at start. But processor creation 60 | * is not guarantee that classifier is available. Not trained classifier 61 | * is not ready to use & must be trained soon as possible. 62 | * 63 | * The main cases why code processor is not available is: 64 | * 1) processor is not created yet & classifier not trained 65 | * 2) processor created, but occurs an error on classifier train 66 | * 3) processor created, classifier start train, but not finished 67 | * 68 | * (3rd case is ok, it's temporary unavailability & awaiting for training) 69 | * 70 | * In 3rd case, user awaiting for train accomplish to get code processor 71 | * and then take classifier to perform language classifying (see below). 72 | * 73 | * @return Flag indicates that classifier instance is not available. 74 | */ 75 | private static boolean notInstanceAvailable() { 76 | if (sInstance == null) { 77 | if (!sTrainingTaskFuture.isDone()) { 78 | try { 79 | sInstance = sTrainingTaskFuture.get(); 80 | return false; 81 | } catch (InterruptedException | ExecutionException e) { 82 | e.printStackTrace(); 83 | return true; 84 | } 85 | } else { 86 | return true; 87 | } 88 | } 89 | return false; 90 | } 91 | 92 | /** 93 | * If training task future is exists, then classifier was started 94 | * to train or already trained & classifier is ready to use. 95 | * 96 | * @return If classifier was trained. 97 | */ 98 | public boolean isTrained() { 99 | return sTrainingTaskFuture != null; 100 | } 101 | 102 | /** 103 | * Start point for apps that use code classifying. Called ones at app start. 104 | * It creates training task for code classifier. 105 | * 106 | * @param context Context 107 | */ 108 | public static void init(Context context) { 109 | if (sInstance == null) { 110 | final ExecutorService service = Executors.newSingleThreadExecutor(); 111 | sTrainingTaskFuture = service.submit(new TrainingTask(context)); 112 | } else { 113 | throw new IllegalStateException("Attempt to train code classifier twice.\n" + 114 | "It should be initialized once at start to make train asynchronously."); 115 | } 116 | } 117 | 118 | /** 119 | * Creates code snippet language classifying task. 120 | * 121 | * @param snippet Code snippet to classify. 122 | * @return Classified language wrapped in Future. 123 | */ 124 | public Future classify(String snippet) { 125 | final ExecutorService service = Executors.newSingleThreadExecutor(); 126 | return service.submit(new ClassifyingTask(snippet)); 127 | } 128 | 129 | /** 130 | * @class TrainingTask 131 | * 132 | * Classifier training task. 133 | * 134 | * @author Kirill Biakov 135 | */ 136 | private static class TrainingTask implements Callable { 137 | private Context context; 138 | 139 | public TrainingTask(Context context) { 140 | this.context = context; 141 | } 142 | 143 | @Override 144 | public CodeProcessor call() { 145 | return new CodeProcessor(context); 146 | } 147 | } 148 | 149 | /** 150 | * @class ClassifyingTask 151 | * 152 | * Language classifying task for presented code snippet. 153 | * 154 | * @author Kirill Biakov 155 | */ 156 | private static class ClassifyingTask implements Callable { 157 | private String snippet; 158 | 159 | public ClassifyingTask(String snippet) { 160 | this.snippet = snippet; 161 | } 162 | 163 | @Override 164 | public String call() { 165 | return CodeClassifier.INSTANCE.classify(snippet); 166 | } 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/highlight/FontCache.java: -------------------------------------------------------------------------------- 1 | package io.github.kbiakov.codeview.highlight; 2 | 3 | import android.content.Context; 4 | import android.graphics.Typeface; 5 | import android.util.Log; 6 | 7 | import java.util.Map; 8 | import java.util.WeakHashMap; 9 | 10 | import io.github.kbiakov.codeview.adapters.AbstractCodeAdapter; 11 | 12 | /** 13 | * Font cache. 14 | * 15 | * @see AbstractCodeAdapter 16 | * @author Kirill Biakov 17 | */ 18 | public class FontCache { 19 | 20 | private static volatile FontCache instance; 21 | 22 | public static FontCache get(Context context) { 23 | FontCache localInstance = instance; 24 | if (localInstance == null) { 25 | synchronized (FontCache.class) { 26 | localInstance = instance; 27 | if (localInstance == null) { 28 | instance = localInstance = new FontCache(context); 29 | } 30 | } 31 | } 32 | return localInstance; 33 | } 34 | 35 | private Map fonts; 36 | 37 | private FontCache(final Context context) { 38 | this.fonts = new WeakHashMap() {{ 39 | String fontPath = getLocalFontPath(Font.Companion.getDefault()); 40 | put(fontPath, loadFont(context, fontPath)); 41 | }}; 42 | } 43 | 44 | private static String getLocalFontPath(Font font) { 45 | return String.format("%s.ttf", getLocalFontPath(font.name())); 46 | } 47 | 48 | private static String getLocalFontPath(String fontName) { 49 | return String.format("fonts/%s", fontName); 50 | } 51 | 52 | private static Typeface loadFont(Context context, String fontPath) { 53 | return Typeface.createFromAsset(context.getAssets(), fontPath); 54 | } 55 | 56 | // - Public methods 57 | 58 | public Typeface getTypeface(Context context) { 59 | return getTypeface(context, Font.Companion.getDefault()); 60 | } 61 | 62 | public Typeface getTypeface(Context context, Font font) { 63 | return getTypeface(context, getLocalFontPath(font)); 64 | } 65 | 66 | public Typeface getLocalTypeface(Context context, String fontPath) { 67 | return getTypeface(context, getLocalFontPath(fontPath)); 68 | } 69 | 70 | public Typeface getTypeface(Context context, String fontPath) { 71 | Typeface font = fonts.get(fontPath); 72 | if (font != null) { 73 | return font; 74 | } else { 75 | font = loadFont(context, fontPath); 76 | fonts.put(fontPath, font); 77 | return font; 78 | } 79 | } 80 | 81 | public void saveTypeface(Typeface fontTypeface) { 82 | fonts.put(fontTypeface.toString(), fontTypeface); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/highlight/parser/ParseResult.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Chan Wai Shing 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining 4 | // a copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to 8 | // permit persons to whom the Software is furnished to do so, subject to 9 | // the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be 12 | // included in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | package io.github.kbiakov.codeview.highlight.parser; 22 | 23 | import java.util.ArrayList; 24 | import java.util.List; 25 | 26 | /** 27 | * The parser parsed result. 28 | * 29 | * This class include the information needed to highlight the syntax. 30 | * Information includes where the content located in the document (offset and 31 | * length) and what style(s) should be applied on that segment of content. 32 | * 33 | * @author Chan Wai Shing 34 | */ 35 | public class ParseResult { 36 | 37 | /** 38 | * The start position of the content. 39 | */ 40 | protected int offset; 41 | /** 42 | * The length of the content. 43 | */ 44 | protected int length; 45 | /** 46 | * The style keys of the content. The style at higher index of the list will 47 | * override the style of the lower index. 48 | */ 49 | protected List styleKeys; 50 | 51 | /** 52 | * Constructor. 53 | * 54 | * @param offset the start position of the content 55 | * @param length the length of the content 56 | * @param styleKeys the style keys of the content 57 | */ 58 | public ParseResult(int offset, int length, List styleKeys) { 59 | this.offset = offset; 60 | this.length = length; 61 | this.styleKeys = new ArrayList(styleKeys); 62 | } 63 | 64 | /** 65 | * The start position of the content. 66 | * @return the start position of the content 67 | */ 68 | public int getOffset() { 69 | return offset; 70 | } 71 | 72 | /** 73 | * The start position of the content. 74 | * @param offset the start position of the content 75 | */ 76 | public void setOffset(int offset) { 77 | this.offset = offset; 78 | } 79 | 80 | /** 81 | * The length of the content. 82 | * @return the length of the content 83 | */ 84 | public int getLength() { 85 | return length; 86 | } 87 | 88 | /** 89 | * The length of the content. 90 | * @param length the length of the content 91 | */ 92 | public void setLength(int length) { 93 | this.length = length; 94 | } 95 | 96 | /** 97 | * Get the style keys represented by one string key, see 98 | * {@link Theme#getStylesAttributeSet(String)}. 99 | * @return the style keys of the content 100 | */ 101 | public String getStyleKeysString() { 102 | StringBuilder sb = new StringBuilder(10); 103 | for (int i = 0, iEnd = styleKeys.size(); i < iEnd; i++) { 104 | if (i != 0) { 105 | sb.append(" "); 106 | } 107 | sb.append(styleKeys.get(i)); 108 | } 109 | return sb.toString(); 110 | } 111 | 112 | /** 113 | * The style keys of the content. 114 | * @param styleKeys the style keys of the content 115 | */ 116 | public void setStyleKeys(List styleKeys) { 117 | this.styleKeys = new ArrayList(styleKeys); 118 | } 119 | 120 | /** 121 | * The style keys of the content. 122 | * @param styleKey the style key 123 | * @return see the return value of {@link List#add(Object)} 124 | */ 125 | public boolean addStyleKey(String styleKey) { 126 | return styleKeys.add(styleKey); 127 | } 128 | 129 | /** 130 | * The style keys of the content. 131 | * @param styleKey the style key 132 | * @return see the return value of {@link List#remove(Object)} 133 | */ 134 | public boolean removeStyleKey(String styleKey) { 135 | return styleKeys.remove(styleKey); 136 | } 137 | 138 | /** 139 | * The style keys of the content. 140 | */ 141 | public void clearStyleKeys() { 142 | styleKeys.clear(); 143 | } 144 | 145 | /** 146 | * The style keys for this matched result, see {@link syntaxhighlighter.theme}. 147 | * @return the style keys 148 | */ 149 | public List getStyleKeys() { 150 | return new ArrayList(styleKeys); 151 | } 152 | 153 | /** 154 | * {@inheritDoc} 155 | */ 156 | @Override 157 | public String toString() { 158 | StringBuilder sb = new StringBuilder(); 159 | 160 | sb.append("["); 161 | sb.append(offset); 162 | sb.append("; "); 163 | sb.append(length); 164 | sb.append("; "); 165 | for (int i = 0, iEnd = styleKeys.size(); i < iEnd; i++) { 166 | if (i != 0) { 167 | sb.append(", "); 168 | } 169 | sb.append(styleKeys.get(i)); 170 | } 171 | sb.append("]"); 172 | 173 | return sb.toString(); 174 | } 175 | } -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/highlight/parser/Parser.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Chan Wai Shing 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining 4 | // a copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to 8 | // permit persons to whom the Software is furnished to do so, subject to 9 | // the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be 12 | // included in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | package io.github.kbiakov.codeview.highlight.parser; 22 | 23 | import java.util.List; 24 | 25 | /** 26 | * The parser for syntax highlight. 27 | * 28 | * @author Chan Wai Shing 29 | */ 30 | public interface Parser { 31 | 32 | /** 33 | * Parse the {@code content} and return the parsed result. 34 | * @param fileExtension the file extension of the content, null means not 35 | * provided 36 | * @param content the content 37 | * @return the parsed result 38 | */ 39 | List parse(String fileExtension, String content); 40 | } 41 | -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/PrettifyParser.java: -------------------------------------------------------------------------------- 1 | package io.github.kbiakov.codeview.highlight.prettify; 2 | 3 | import io.github.kbiakov.codeview.highlight.prettify.parser.Job; 4 | import io.github.kbiakov.codeview.highlight.prettify.parser.Prettify; 5 | import io.github.kbiakov.codeview.highlight.parser.ParseResult; 6 | import io.github.kbiakov.codeview.highlight.parser.Parser; 7 | 8 | import java.util.ArrayList; 9 | import java.util.Arrays; 10 | import java.util.List; 11 | 12 | /** 13 | * The prettify parser for syntax highlight. 14 | * @author Chan Wai Shing 15 | */ 16 | public class PrettifyParser implements Parser { 17 | 18 | /** 19 | * The prettify parser. 20 | */ 21 | protected Prettify prettify; 22 | 23 | /** 24 | * Constructor. 25 | */ 26 | public PrettifyParser() { 27 | prettify = new Prettify(); 28 | } 29 | 30 | @Override 31 | public List parse(String fileExtension, String content) { 32 | Job job = new Job(0, content); 33 | prettify.langHandlerForExtension(fileExtension, content).decorate(job); 34 | List decorations = job.getDecorations(); 35 | 36 | 37 | List returnList = new ArrayList(); 38 | 39 | // apply style according to the style list 40 | for (int i = 0, iEnd = decorations.size(); i < iEnd; i += 2) { 41 | int endPos = i + 2 < iEnd ? (Integer) decorations.get(i + 2) : content.length(); 42 | int startPos = (Integer) decorations.get(i); 43 | returnList.add(new ParseResult(startPos, endPos - startPos, Arrays.asList(new String[]{(String) decorations.get(i + 1)}))); 44 | } 45 | 46 | return returnList; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/Lang.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2011 Chan Wai Shing 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | package io.github.kbiakov.codeview.highlight.prettify.lang; 15 | 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | 19 | /** 20 | * Lang class for Java Prettify. 21 | * Note that the method {@link #getFileExtensions()} should be overridden. 22 | * 23 | * @author Chan Wai Shing 24 | */ 25 | public abstract class Lang { 26 | 27 | /** 28 | * Similar to those in JavaScript prettify.js. 29 | */ 30 | protected List> shortcutStylePatterns; 31 | /** 32 | * Similar to those in JavaScript prettify.js. 33 | */ 34 | protected List> fallthroughStylePatterns; 35 | /** 36 | * See {@link io.github.kbiakov.codeview.highlight.prettify.lang.LangCss} for example. 37 | */ 38 | protected List extendedLangs; 39 | 40 | /** 41 | * Constructor. 42 | */ 43 | public Lang() { 44 | shortcutStylePatterns = new ArrayList>(); 45 | fallthroughStylePatterns = new ArrayList>(); 46 | extendedLangs = new ArrayList(); 47 | } 48 | 49 | /** 50 | * This method should be overridden by the child class. 51 | * This provide the file extensions list to help the parser to determine which 52 | * {@link Lang} to use. See JavaScript prettify.js. 53 | * 54 | * @return the list of file extensions 55 | */ 56 | public static List getFileExtensions() { 57 | return new ArrayList(); 58 | } 59 | 60 | public List> getShortcutStylePatterns() { 61 | List> returnList = new ArrayList>(); 62 | for (List shortcutStylePattern : shortcutStylePatterns) { 63 | returnList.add(new ArrayList(shortcutStylePattern)); 64 | } 65 | return returnList; 66 | } 67 | 68 | public void setShortcutStylePatterns(List> shortcutStylePatterns) { 69 | if (shortcutStylePatterns == null) { 70 | this.shortcutStylePatterns = new ArrayList>(); 71 | return; 72 | } 73 | List> cloneList = new ArrayList>(); 74 | for (List shortcutStylePattern : shortcutStylePatterns) { 75 | cloneList.add(new ArrayList(shortcutStylePattern)); 76 | } 77 | this.shortcutStylePatterns = cloneList; 78 | } 79 | 80 | public List> getFallthroughStylePatterns() { 81 | List> returnList = new ArrayList>(); 82 | for (List fallthroughStylePattern : fallthroughStylePatterns) { 83 | returnList.add(new ArrayList(fallthroughStylePattern)); 84 | } 85 | return returnList; 86 | } 87 | 88 | public void setFallthroughStylePatterns(List> fallthroughStylePatterns) { 89 | if (fallthroughStylePatterns == null) { 90 | this.fallthroughStylePatterns = new ArrayList>(); 91 | return; 92 | } 93 | List> cloneList = new ArrayList>(); 94 | for (List fallthroughStylePattern : fallthroughStylePatterns) { 95 | cloneList.add(new ArrayList(fallthroughStylePattern)); 96 | } 97 | this.fallthroughStylePatterns = cloneList; 98 | } 99 | 100 | /** 101 | * Get the extended languages list. 102 | * @return the list 103 | */ 104 | public List getExtendedLangs() { 105 | return new ArrayList(extendedLangs); 106 | } 107 | 108 | /** 109 | * Set extended languages. Because we cannot register multiple languages 110 | * within one {@link prettify.lang.Lang}, so it is used as an solution. See 111 | * {@link prettify.lang.LangCss} for example. 112 | * 113 | * @param extendedLangs the list of {@link prettify.lang.Lang}s 114 | */ 115 | public void setExtendedLangs(List extendedLangs) { 116 | this.extendedLangs = new ArrayList(extendedLangs); 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangAppollo.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 Onno Hommes. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | package io.github.kbiakov.codeview.highlight.prettify.lang; 15 | 16 | import java.util.ArrayList; 17 | import java.util.Arrays; 18 | import java.util.List; 19 | import java.util.regex.Pattern; 20 | import io.github.kbiakov.codeview.highlight.prettify.parser.Prettify; 21 | 22 | /** 23 | * This is similar to the lang-appollo.js in JavaScript Prettify. 24 | * 25 | * All comments are adapted from the JavaScript Prettify. 26 | * 27 | *

28 | * Registers a language handler for the AGC/AEA Assembly Language as described 29 | * at http://virtualagc.googlecode.com 30 | *

31 | * This file could be used by goodle code to allow syntax highlight for 32 | * Virtual AGC SVN repository or if you don't want to commonize 33 | * the header for the agc/aea html assembly listing. 34 | * 35 | * @author ohommes@alumni.cmu.edu 36 | */ 37 | public class LangAppollo extends Lang { 38 | 39 | public LangAppollo() { 40 | List> _shortcutStylePatterns = new ArrayList>(); 41 | List> _fallthroughStylePatterns = new ArrayList>(); 42 | 43 | // A line comment that starts with ; 44 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^#[^\r\n]*"), null, "#"})); 45 | // Whitespace 46 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[\t\n\r \\xA0]+"), null, "\t\n\r " + Character.toString((char) 0xA0)})); 47 | // A double quoted, possibly multi-line, string. 48 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^\\\"(?:[^\\\"\\\\]|\\\\[\\s\\S])*(?:\\\"|$)"), null, "\""})); 49 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^(?:ADS|AD|AUG|BZF|BZMF|CAE|CAF|CA|CCS|COM|CS|DAS|DCA|DCOM|DCS|DDOUBL|DIM|DOUBLE|DTCB|DTCF|DV|DXCH|EDRUPT|EXTEND|INCR|INDEX|NDX|INHINT|LXCH|MASK|MSK|MP|MSU|NOOP|OVSK|QXCH|RAND|READ|RELINT|RESUME|RETURN|ROR|RXOR|SQUARE|SU|TCR|TCAA|OVSK|TCF|TC|TS|WAND|WOR|WRITE|XCH|XLQ|XXALQ|ZL|ZQ|ADD|ADZ|SUB|SUZ|MPY|MPR|MPZ|DVP|COM|ABS|CLA|CLZ|LDQ|STO|STQ|ALS|LLS|LRS|TRA|TSQ|TMI|TOV|AXT|TIX|DLY|INP|OUT)\\s"), null})); 50 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_TYPE, Pattern.compile("^(?:-?GENADR|=MINUS|2BCADR|VN|BOF|MM|-?2CADR|-?[1-6]DNADR|ADRES|BBCON|[SE]?BANK\\=?|BLOCK|BNKSUM|E?CADR|COUNT\\*?|2?DEC\\*?|-?DNCHAN|-?DNPTR|EQUALS|ERASE|MEMORY|2?OCT|REMADR|SETLOC|SUBRO|ORG|BSS|BES|SYN|EQU|DEFINE|END)\\s"), null})); 51 | // A single quote possibly followed by a word that optionally ends with 52 | // = ! or ?. 53 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^\\'(?:-*(?:\\w|\\\\[\\x21-\\x7e])(?:[\\w-]*|\\\\[\\x21-\\x7e])[=!?]?)?")})); 54 | // Any word including labels that optionally ends with = ! or ?. 55 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^-*(?:[!-z_]|\\\\[\\x21-\\x7e])(?:[\\w-]*|\\\\[\\x21-\\x7e])[=!?]?", Pattern.CASE_INSENSITIVE)})); 56 | // A printable non-space non-special character 57 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^[^\\w\\t\\n\\r \\xA0()\\\"\\\\\\';]+")})); 58 | 59 | setShortcutStylePatterns(_shortcutStylePatterns); 60 | setFallthroughStylePatterns(_fallthroughStylePatterns); 61 | } 62 | 63 | public static List getFileExtensions() { 64 | return Arrays.asList(new String[]{"apollo", "agc", "aea"}); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangBasic.java: -------------------------------------------------------------------------------- 1 | // Contributed by peter dot kofler at code minus cop dot org 2 | package io.github.kbiakov.codeview.highlight.prettify.lang; 3 | 4 | import io.github.kbiakov.codeview.highlight.prettify.parser.Prettify; 5 | 6 | import java.util.ArrayList; 7 | import java.util.Arrays; 8 | import java.util.List; 9 | import java.util.regex.Pattern; 10 | 11 | /** 12 | * This is similar to the lang-basic.js in JavaScript Prettify. 13 | *

14 | * To use, include prettify.js and this file in your HTML page. 15 | * Then put your code in an HTML tag like 16 | *

(my BASIC code)
17 | * 18 | * @author peter dot kofler at code minus cop dot org 19 | */ 20 | public class LangBasic extends Lang { 21 | 22 | public LangBasic() { 23 | List> _shortcutStylePatterns = new ArrayList>(); 24 | List> _fallthroughStylePatterns = new ArrayList>(); 25 | 26 | // "single-line-string" 27 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^(?:\"(?:[^\\\\\"\\r\\n]|\\\\.)*(?:\"|$))"), null, "\""})); 28 | // Whitespace 29 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^\\s+"), null, "\t\n\r " + Character.toString((char) 0xA0)})); 30 | 31 | // A line comment that starts with REM 32 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^REM[^\\r\\n]*"), null})); 33 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^\\b(?:AND|CLOSE|CLR|CMD|CONT|DATA|DEF ?FN|DIM|END|FOR|GET|GOSUB|GOTO|IF|INPUT|LET|LIST|LOAD|NEW|NEXT|NOT|ON|OPEN|OR|POKE|PRINT|READ|RESTORE|RETURN|RUN|SAVE|STEP|STOP|SYS|THEN|TO|VERIFY|WAIT)\\b"), null})); 34 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[A-Z][A-Z0-9]?(?:\\$|%)?", Pattern.CASE_INSENSITIVE), null})); 35 | // Literals .0, 0, 0.0 0E13 36 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:e[+\\-]?\\d+)?", Pattern.CASE_INSENSITIVE), null, "0123456789"})); 37 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^.[^\\s\\w\\.$%\"]*"), null})); 38 | 39 | setShortcutStylePatterns(_shortcutStylePatterns); 40 | setFallthroughStylePatterns(_fallthroughStylePatterns); 41 | } 42 | 43 | public static List getFileExtensions() { 44 | return Arrays.asList(new String[]{"basic", "cbm"}); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangClj.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @license Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.github.kbiakov.codeview.highlight.prettify.lang; 17 | 18 | import java.util.ArrayList; 19 | import java.util.Arrays; 20 | import java.util.List; 21 | import java.util.regex.Pattern; 22 | import io.github.kbiakov.codeview.highlight.prettify.parser.Prettify; 23 | 24 | /** 25 | * This is similar to the lang-clj.js in JavaScript Prettify. 26 | * 27 | * All comments are adapted from the JavaScript Prettify. 28 | * 29 | *

30 | * Registers a language handler for Clojure. 31 | * 32 | * 33 | * To use, include prettify.js and this file in your HTML page. 34 | * Then put your code in an HTML tag like 35 | *

(my lisp code)
36 | * The lang-cl class identifies the language as common lisp. 37 | * This file supports the following language extensions: 38 | * lang-clj - Clojure 39 | * 40 | * 41 | * I used lang-lisp.js as the basis for this adding the clojure specific 42 | * keywords and syntax. 43 | * 44 | * "Name" = 'Clojure' 45 | * "Author" = 'Rich Hickey' 46 | * "Version" = '1.2' 47 | * "About" = 'Clojure is a lisp for the jvm with concurrency primitives and a richer set of types.' 48 | * 49 | * 50 | * I used Clojure.org Reference as 51 | * the basis for the reserved word list. 52 | * 53 | * 54 | * @author jwall@google.com 55 | */ 56 | public class LangClj extends Lang { 57 | 58 | public LangClj() { 59 | List> _shortcutStylePatterns = new ArrayList>(); 60 | List> _fallthroughStylePatterns = new ArrayList>(); 61 | 62 | // clojure has more paren types than minimal lisp. 63 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{"opn", Pattern.compile("^[\\(\\{\\[]+"), null, "([{"})); 64 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{"clo", Pattern.compile("^[\\)\\}\\]]+"), null, ")]}"})); 65 | // A line comment that starts with ; 66 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^;[^\r\n]*"), null, ";"})); 67 | // Whitespace 68 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[\t\n\r \\xA0]+"), null, "\t\n\r " + Character.toString((char) 0xA0)})); 69 | // A double quoted, possibly multi-line, string. 70 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^\\\"(?:[^\\\"\\\\]|\\\\[\\s\\S])*(?:\\\"|$)"), null, "\""})); 71 | // clojure has a much larger set of keywords 72 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^(?:def|if|do|let|quote|var|fn|loop|recur|throw|try|monitor-enter|monitor-exit|defmacro|defn|defn-|macroexpand|macroexpand-1|for|doseq|dosync|dotimes|and|or|when|not|assert|doto|proxy|defstruct|first|rest|cons|defprotocol|deftype|defrecord|reify|defmulti|defmethod|meta|with-meta|ns|in-ns|create-ns|import|intern|refer|alias|namespace|resolve|ref|deref|refset|new|set!|memfn|to-array|into-array|aset|gen-class|reduce|map|filter|find|nil?|empty?|hash-map|hash-set|vec|vector|seq|flatten|reverse|assoc|dissoc|list|list?|disj|get|union|difference|intersection|extend|extend-type|extend-protocol|prn)\\b"), null})); 73 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_TYPE, Pattern.compile("^:[0-9a-zA-Z\\-]+")})); 74 | 75 | setShortcutStylePatterns(_shortcutStylePatterns); 76 | setFallthroughStylePatterns(_fallthroughStylePatterns); 77 | } 78 | 79 | public static List getFileExtensions() { 80 | return Arrays.asList(new String[]{"clj"}); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangCss.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | package io.github.kbiakov.codeview.highlight.prettify.lang; 15 | 16 | import java.util.ArrayList; 17 | import java.util.Arrays; 18 | import java.util.List; 19 | import java.util.regex.Pattern; 20 | import io.github.kbiakov.codeview.highlight.prettify.parser.Prettify; 21 | 22 | /** 23 | * This is similar to the lang-css.js in JavaScript Prettify. 24 | * 25 | * All comments are adapted from the JavaScript Prettify. 26 | * 27 | *

28 | * Registers a language handler for CSS. 29 | * 30 | * 31 | * To use, include prettify.js and this file in your HTML page. 32 | * Then put your code in an HTML tag like 33 | *


 34 |  *
 35 |  *
 36 |  * http://www.w3.org/TR/CSS21/grammar.html Section G2 defines the lexical
 37 |  * grammar.  This scheme does not recognize keywords containing escapes.
 38 |  *
 39 |  * @author mikesamuel@gmail.com
 40 |  */
 41 | public class LangCss extends Lang {
 42 | 
 43 |   public LangCss() {
 44 |     List> _shortcutStylePatterns = new ArrayList>();
 45 |     List> _fallthroughStylePatterns = new ArrayList>();
 46 | 
 47 |     // The space production 
 48 |     _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[ \t\r\n\f]+"), null, " \t\r\n\f"}));
 49 |     // Quoted strings.   and 
 50 |     _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^\\\"(?:[^\n\r\f\\\\\\\"]|\\\\(?:\r\n?|\n|\f)|\\\\[\\s\\S])*\\\""), null}));
 51 |     _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^\\'(?:[^\n\r\f\\\\\\']|\\\\(?:\r\n?|\n|\f)|\\\\[\\s\\S])*\\'"), null}));
 52 |     _fallthroughStylePatterns.add(Arrays.asList(new Object[]{"lang-css-str", Pattern.compile("^url\\(([^\\)\\\"\\']+)\\)", Pattern.CASE_INSENSITIVE)}));
 53 |     _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^(?:url|rgb|\\!important|@import|@page|@media|@charset|inherit)(?=[^\\-\\w]|$)", Pattern.CASE_INSENSITIVE), null}));
 54 |     // A property name -- an identifier followed by a colon.
 55 |     _fallthroughStylePatterns.add(Arrays.asList(new Object[]{"lang-css-kw", Pattern.compile("^(-?(?:[_a-z]|(?:\\\\[0-9a-f]+ ?))(?:[_a-z0-9\\-]|\\\\(?:\\\\[0-9a-f]+ ?))*)\\s*:", Pattern.CASE_INSENSITIVE)}));
 56 |     // A C style block comment.  The  production.
 57 |     _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^\\/\\*[^*]*\\*+(?:[^\\/*][^*]*\\*+)*\\/")}));
 58 |     // Escaping text spans
 59 |     _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^(?:)")}));
 60 |     // A number possibly containing a suffix.
 61 |     _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^(?:\\d+|\\d*\\.\\d+)(?:%|[a-z]+)?", Pattern.CASE_INSENSITIVE)}));
 62 |     // A hex color
 63 |     _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^#(?:[0-9a-f]{3}){1,2}\\b", Pattern.CASE_INSENSITIVE)}));
 64 |     // An identifier
 65 |     _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^-?(?:[_a-z]|(?:\\\\[\\da-f]+ ?))(?:[_a-z\\d\\-]|\\\\(?:\\\\[\\da-f]+ ?))*", Pattern.CASE_INSENSITIVE)}));
 66 |     // A run of punctuation
 67 |     _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^[^\\s\\w\\'\\\"]+", Pattern.CASE_INSENSITIVE)}));
 68 | 
 69 |     setShortcutStylePatterns(_shortcutStylePatterns);
 70 |     setFallthroughStylePatterns(_fallthroughStylePatterns);
 71 | 
 72 |     setExtendedLangs(Arrays.asList(new Lang[]{new LangCssKeyword(), new LangCssString()}));
 73 |   }
 74 | 
 75 |   public static List getFileExtensions() {
 76 |     return Arrays.asList(new String[]{"css"});
 77 |   }
 78 | 
 79 |   protected static class LangCssKeyword extends Lang {
 80 | 
 81 |     public LangCssKeyword() {
 82 |       List> _shortcutStylePatterns = new ArrayList>();
 83 |       List> _fallthroughStylePatterns = new ArrayList>();
 84 | 
 85 |       _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^-?(?:[_a-z]|(?:\\\\[\\da-f]+ ?))(?:[_a-z\\d\\-]|\\\\(?:\\\\[\\da-f]+ ?))*", Pattern.CASE_INSENSITIVE)}));
 86 | 
 87 |       setShortcutStylePatterns(_shortcutStylePatterns);
 88 |       setFallthroughStylePatterns(_fallthroughStylePatterns);
 89 |     }
 90 | 
 91 |     public static List getFileExtensions() {
 92 |       return Arrays.asList(new String[]{"css-kw"});
 93 |     }
 94 |   }
 95 | 
 96 |   protected static class LangCssString extends Lang {
 97 | 
 98 |     public LangCssString() {
 99 |       List> _shortcutStylePatterns = new ArrayList>();
100 |       List> _fallthroughStylePatterns = new ArrayList>();
101 | 
102 |       _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^[^\\)\\\"\\']+")}));
103 | 
104 |       setShortcutStylePatterns(_shortcutStylePatterns);
105 |       setFallthroughStylePatterns(_fallthroughStylePatterns);
106 |     }
107 | 
108 |     public static List getFileExtensions() {
109 |       return Arrays.asList(new String[]{"css-str"});
110 |     }
111 |   }
112 | }
113 | 


--------------------------------------------------------------------------------
/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangDart.java:
--------------------------------------------------------------------------------
 1 | /**
 2 |  * @license Copyright (C) 2013 Google Inc.
 3 |  *
 4 |  * Licensed under the Apache License, Version 2.0 (the "License");
 5 |  * you may not use this file except in compliance with the License.
 6 |  * You may obtain a copy of the License at
 7 |  *
 8 |  *      http://www.apache.org/licenses/LICENSE-2.0
 9 |  *
10 |  * Unless required by applicable law or agreed to in writing, software
11 |  * distributed under the License is distributed on an "AS IS" BASIS,
12 |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 |  * See the License for the specific language governing permissions and
14 |  * limitations under the License.
15 |  */
16 | package io.github.kbiakov.codeview.highlight.prettify.lang;
17 | 
18 | import java.util.ArrayList;
19 | import java.util.Arrays;
20 | import java.util.List;
21 | import java.util.regex.Pattern;
22 | import io.github.kbiakov.codeview.highlight.prettify.parser.Prettify;
23 | 
24 | /**
25 |  * This is similar to the lang-dart.js in JavaScript Prettify.
26 |  * 
27 |  * All comments are adapted from the JavaScript Prettify.
28 |  * 
29 |  * 

30 | * Registers a language handler for Dart. 31 | * 32 | * 33 | * Loosely structured based on the DartLexer in Pygments: http://pygments.org/. 34 | * 35 | * To use, include prettify.js and this file in your HTML page. 36 | * Then put your code in an HTML tag like 37 | *

(Dart code)
38 | * 39 | * @author armstrong.timothy@gmail.com 40 | */ 41 | public class LangDart extends Lang { 42 | 43 | public LangDart() { 44 | List> _shortcutStylePatterns = new ArrayList>(); 45 | List> _fallthroughStylePatterns = new ArrayList>(); 46 | 47 | // Whitespace. 48 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[\t\n\r \\xA0]+"), null, "\t\n\r " + Character.toString((char) 0xA0)})); 49 | 50 | // Script tag. 51 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^#!(?:.*)")})); 52 | // `import`, `library`, `part of`, `part`, `as`, `show`, and `hide` 53 | // keywords. 54 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^\\b(?:import|library|part of|part|as|show|hide)\\b", Pattern.CASE_INSENSITIVE)})); 55 | // Single-line comments. 56 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^\\/\\/(?:.*)")})); 57 | // Multiline comments. 58 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^\\/\\*[^*]*\\*+(?:[^\\/*][^*]*\\*+)*\\/")})); 59 | // `class` and `interface` keywords. 60 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^\\b(?:class|interface)\\b", Pattern.CASE_INSENSITIVE)})); 61 | // General keywords. 62 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^\\b(?:assert|break|case|catch|continue|default|do|else|finally|for|if|in|is|new|return|super|switch|this|throw|try|while)\\b", Pattern.CASE_INSENSITIVE)})); 63 | // Declaration keywords. 64 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^\\b(?:abstract|const|extends|factory|final|get|implements|native|operator|set|static|typedef|var)\\b", Pattern.CASE_INSENSITIVE)})); 65 | // Keywords for types. 66 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_TYPE, Pattern.compile("^\\b(?:bool|double|Dynamic|int|num|Object|String|void)\\b", Pattern.CASE_INSENSITIVE)})); 67 | // Keywords for constants. 68 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("\\b(?:false|null|true)\\b", Pattern.CASE_INSENSITIVE)})); 69 | // Multiline strings, single- and double-quoted. 70 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^r?[\\']{3}[\\s|\\S]*?[^\\\\][\\']{3}")})); 71 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^r?[\\\"]{3}[\\s|\\S]*?[^\\\\][\\\"]{3}")})); 72 | // Normal and raw strings, single- and double-quoted. 73 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^r?\\'(\\'|(?:[^\\n\\r\\f])*?[^\\\\]\\')")})); 74 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^r?\\\"(\\\"|(?:[^\\n\\r\\f])*?[^\\\\]\\\")")})); 75 | // Identifiers. 76 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[a-z_$][a-z0-9_]*", Pattern.CASE_INSENSITIVE)})); 77 | // Operators. 78 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^[~!%^&*+=|?:<>/-]")})); 79 | // Hex numbers. 80 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^\\b0x[0-9a-f]+", Pattern.CASE_INSENSITIVE)})); 81 | // Decimal numbers. 82 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^\\b\\d+(?:\\.\\d*)?(?:e[+-]?\\d+)?", Pattern.CASE_INSENSITIVE)})); 83 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^\\b\\.\\d+(?:e[+-]?\\d+)?", Pattern.CASE_INSENSITIVE)})); 84 | // Punctuation. 85 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^[(){}\\[\\],.;]")})); 86 | 87 | setShortcutStylePatterns(_shortcutStylePatterns); 88 | setFallthroughStylePatterns(_fallthroughStylePatterns); 89 | } 90 | 91 | public static List getFileExtensions() { 92 | return Arrays.asList(new String[]{"dart"}); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangErlang.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2013 Andrew Allen 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | package io.github.kbiakov.codeview.highlight.prettify.lang; 15 | 16 | import io.github.kbiakov.codeview.highlight.prettify.parser.Prettify; 17 | 18 | import java.util.ArrayList; 19 | import java.util.Arrays; 20 | import java.util.List; 21 | import java.util.regex.Pattern; 22 | 23 | /** 24 | * This is similar to the lang-erlang.js in JavaScript Prettify. 25 | *

26 | * All comments are adapted from the JavaScript Prettify. 27 | *

28 | *

29 | *

30 | * Derived from https://raw.github.com/erlang/otp/dev/lib/compiler/src/core_parse.yrl 31 | * Modified from Mike Samuel's Haskell plugin for google-code-prettify 32 | * 33 | * @author achew22@gmail.com 34 | */ 35 | public class LangErlang extends Lang { 36 | 37 | public LangErlang() { 38 | List> _shortcutStylePatterns = new ArrayList>(); 39 | List> _fallthroughStylePatterns = new ArrayList>(); 40 | 41 | // Whitespace 42 | // whitechar -> newline | vertab | space | tab | uniWhite 43 | // newline -> return linefeed | return | linefeed | formfeed 44 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("\\t\\n\\x0B\\x0C\\r ]+"), null, "\t\n" + Character.toString((char) 0x0B) + Character.toString((char) 0x0C) + "\r "})); 45 | // Single line double-quoted strings. 46 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^\\\"(?:[^\\\"\\\\\\n\\x0C\\r]|\\\\[\\s\\S])*(?:\\\"|$)"), null, "\""})); 47 | 48 | // Handle atoms 49 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^[a-z][a-zA-Z0-9_]*")})); 50 | // Handle single quoted atoms 51 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^\\'(?:[^\\'\\\\\\n\\x0C\\r]|\\\\[^&])+\\'?"), null, "'"})); 52 | 53 | // Handle macros. Just to be extra clear on this one, it detects the ? 54 | // then uses the regexp to end it so be very careful about matching 55 | // all the terminal elements 56 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^\\?[^ \\t\\n({]+"), null, "?"})); 57 | 58 | // decimal -> digit{digit} 59 | // octal -> octit{octit} 60 | // hexadecimal -> hexit{hexit} 61 | // integer -> decimal 62 | // | 0o octal | 0O octal 63 | // | 0x hexadecimal | 0X hexadecimal 64 | // float -> decimal . decimal [exponent] 65 | // | decimal exponent 66 | // exponent -> (e | E) [+ | -] decimal 67 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^(?:0o[0-7]+|0x[\\da-f]+|\\d+(?:\\.\\d+)?(?:e[+\\-]?\\d+)?)", Pattern.CASE_INSENSITIVE), null, "0123456789"})); 68 | 69 | 70 | // TODO: catch @declarations inside comments 71 | 72 | // Comments in erlang are started with % and go till a newline 73 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^%[^\\n\\r]*")})); 74 | 75 | // Catch macros 76 | //[PR['PR_TAG'], /?[^( \n)]+/], 77 | 78 | /** 79 | * %% Keywords (atoms are assumed to always be single-quoted). 80 | * 'module' 'attributes' 'do' 'let' 'in' 'letrec' 81 | * 'apply' 'call' 'primop' 82 | * 'case' 'of' 'end' 'when' 'fun' 'try' 'catch' 'receive' 'after' 83 | */ 84 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^(?:module|attributes|do|let|in|letrec|apply|call|primop|case|of|end|when|fun|try|catch|receive|after|char|integer|float,atom,string,var)\\b")})); 85 | 86 | /** 87 | * Catch definitions (usually defined at the top of the file) 88 | * Anything that starts -something 89 | */ 90 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^-[a-z_]+")})); 91 | 92 | // Catch variables 93 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_TYPE, Pattern.compile("^[A-Z_][a-zA-Z0-9_]*")})); 94 | 95 | // matches the symbol production 96 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^[.,;]")})); 97 | 98 | setShortcutStylePatterns(_shortcutStylePatterns); 99 | setFallthroughStylePatterns(_fallthroughStylePatterns); 100 | } 101 | 102 | public static List getFileExtensions() { 103 | return Arrays.asList(new String[]{"erlang", "erl"}); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangGo.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | package io.github.kbiakov.codeview.highlight.prettify.lang; 15 | 16 | import java.util.ArrayList; 17 | import java.util.Arrays; 18 | import java.util.List; 19 | import java.util.regex.Pattern; 20 | import io.github.kbiakov.codeview.highlight.prettify.parser.Prettify; 21 | 22 | /** 23 | * This is similar to the lang-go.js in JavaScript Prettify. 24 | * 25 | * All comments are adapted from the JavaScript Prettify. 26 | * 27 | *

28 | * Registers a language handler for the Go language.. 29 | *

30 | * Based on the lexical grammar at 31 | * http://golang.org/doc/go_spec.html#Lexical_elements 32 | *

33 | * Go uses a minimal style for highlighting so the below does not distinguish 34 | * strings, keywords, literals, etc. by design. 35 | * From a discussion with the Go designers: 36 | *

37 |  * On Thursday, July 22, 2010, Mike Samuel <...> wrote:
38 |  * > On Thu, Jul 22, 2010, Rob 'Commander' Pike <...> wrote:
39 |  * >> Personally, I would vote for the subdued style godoc presents at http://golang.org
40 |  * >>
41 |  * >> Not as fancy as some like, but a case can be made it's the official style.
42 |  * >> If people want more colors, I wouldn't fight too hard, in the interest of
43 |  * >> encouragement through familiarity, but even then I would ask to shy away
44 |  * >> from technicolor starbursts.
45 |  * >
46 |  * > Like http://golang.org/pkg/go/scanner/ where comments are blue and all
47 |  * > other content is black?  I can do that.
48 |  * 
49 | * 50 | * @author mikesamuel@gmail.com 51 | */ 52 | public class LangGo extends Lang { 53 | 54 | public LangGo() { 55 | List> _shortcutStylePatterns = new ArrayList>(); 56 | List> _fallthroughStylePatterns = new ArrayList>(); 57 | 58 | // Whitespace is made up of spaces, tabs and newline characters. 59 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[\\t\\n\\r \\xA0]+"), null, "\t\n\r " + Character.toString((char) 0xA0)})); 60 | // Not escaped as a string. See note on minimalism above. 61 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^(?:\\\"(?:[^\\\"\\\\]|\\\\[\\s\\S])*(?:\\\"|$)|\\'(?:[^\\'\\\\]|\\\\[\\s\\S])+(?:\\'|$)|`[^`]*(?:`|$))"), null, "\"'"})); 62 | // Block comments are delimited by /* and */. 63 | // Single-line comments begin with // and extend to the end of a line. 64 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^(?:\\/\\/[^\\r\\n]*|\\/\\*[\\s\\S]*?\\*\\/)")})); 65 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^(?:[^\\/\\\"\\'`]|\\/(?![\\/\\*]))+", Pattern.CASE_INSENSITIVE)})); 66 | 67 | setShortcutStylePatterns(_shortcutStylePatterns); 68 | setFallthroughStylePatterns(_fallthroughStylePatterns); 69 | } 70 | 71 | public static List getFileExtensions() { 72 | return Arrays.asList(new String[]{"go"}); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangHs.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | package io.github.kbiakov.codeview.highlight.prettify.lang; 15 | 16 | import java.util.ArrayList; 17 | import java.util.Arrays; 18 | import java.util.List; 19 | import java.util.regex.Pattern; 20 | import io.github.kbiakov.codeview.highlight.prettify.parser.Prettify; 21 | 22 | /** 23 | * This is similar to the lang-hs.js in JavaScript Prettify. 24 | * 25 | * All comments are adapted from the JavaScript Prettify. 26 | * 27 | *

28 | * Registers a language handler for Haskell. 29 | * 30 | * 31 | * To use, include prettify.js and this file in your HTML page. 32 | * Then put your code in an HTML tag like 33 | *

(my lisp code)
34 | * The lang-cl class identifies the language as common lisp. 35 | * This file supports the following language extensions: 36 | * lang-cl - Common Lisp 37 | * lang-el - Emacs Lisp 38 | * lang-lisp - Lisp 39 | * lang-scm - Scheme 40 | * 41 | * 42 | * I used http://www.informatik.uni-freiburg.de/~thiemann/haskell/haskell98-report-html/syntax-iso.html 43 | * as the basis, but ignore the way the ncomment production nests since this 44 | * makes the lexical grammar irregular. It might be possible to support 45 | * ncomments using the lookbehind filter. 46 | * 47 | * 48 | * @author mikesamuel@gmail.com 49 | */ 50 | public class LangHs extends Lang { 51 | 52 | public LangHs() { 53 | List> _shortcutStylePatterns = new ArrayList>(); 54 | List> _fallthroughStylePatterns = new ArrayList>(); 55 | 56 | // Whitespace 57 | // whitechar -> newline | vertab | space | tab | uniWhite 58 | // newline -> return linefeed | return | linefeed | formfeed 59 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[\\t\\n\\x0B\\x0C\\r ]+"), null, "\t\n" + Character.toString((char) 0x0B) + Character.toString((char) 0x0C) + "\r "})); 60 | // Single line double and single-quoted strings. 61 | // char -> ' (graphic<' | \> | space | escape<\&>) ' 62 | // string -> " {graphic<" | \> | space | escape | gap}" 63 | // escape -> \ ( charesc | ascii | decimal | o octal 64 | // | x hexadecimal ) 65 | // charesc -> a | b | f | n | r | t | v | \ | " | ' | & 66 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^\\\"(?:[^\\\"\\\\\\n\\x0C\\r]|\\\\[\\s\\S])*(?:\\\"|$)"), null, "\""})); 67 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^\\'(?:[^\\'\\\\\\n\\x0C\\r]|\\\\[^&])\\'?"), null, "'"})); 68 | // decimal -> digit{digit} 69 | // octal -> octit{octit} 70 | // hexadecimal -> hexit{hexit} 71 | // integer -> decimal 72 | // | 0o octal | 0O octal 73 | // | 0x hexadecimal | 0X hexadecimal 74 | // float -> decimal . decimal [exponent] 75 | // | decimal exponent 76 | // exponent -> (e | E) [+ | -] decimal 77 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^(?:0o[0-7]+|0x[\\da-f]+|\\d+(?:\\.\\d+)?(?:e[+\\-]?\\d+)?)", Pattern.CASE_INSENSITIVE), null, "0123456789"})); 78 | // Haskell does not have a regular lexical grammar due to the nested 79 | // ncomment. 80 | // comment -> dashes [ any {any}] newline 81 | // ncomment -> opencom ANYseq {ncomment ANYseq}closecom 82 | // dashes -> '--' {'-'} 83 | // opencom -> '{-' 84 | // closecom -> '-}' 85 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^(?:(?:--+(?:[^\\r\\n\\x0C]*)?)|(?:\\{-(?:[^-]|-+[^-\\}])*-\\}))")})); 86 | // reservedid -> case | class | data | default | deriving | do 87 | // | else | if | import | in | infix | infixl | infixr 88 | // | instance | let | module | newtype | of | then 89 | // | type | where | _ 90 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^(?:case|class|data|default|deriving|do|else|if|import|in|infix|infixl|infixr|instance|let|module|newtype|of|then|type|where|_)(?=[^a-zA-Z0-9\\']|$)"), null})); 91 | // qvarid -> [ modid . ] varid 92 | // qconid -> [ modid . ] conid 93 | // varid -> (small {small | large | digit | ' }) 94 | // conid -> large {small | large | digit | ' } 95 | // modid -> conid 96 | // small -> ascSmall | uniSmall | _ 97 | // ascSmall -> a | b | ... | z 98 | // uniSmall -> any Unicode lowercase letter 99 | // large -> ascLarge | uniLarge 100 | // ascLarge -> A | B | ... | Z 101 | // uniLarge -> any uppercase or titlecase Unicode letter 102 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^(?:[A-Z][\\w\\']*\\.)*[a-zA-Z][\\w\\']*")})); 103 | // matches the symbol production 104 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^[^\\t\\n\\x0B\\x0C\\r a-zA-Z0-9\\'\\\"]+")})); 105 | 106 | setShortcutStylePatterns(_shortcutStylePatterns); 107 | setFallthroughStylePatterns(_fallthroughStylePatterns); 108 | } 109 | 110 | public static List getFileExtensions() { 111 | return Arrays.asList(new String[]{"hs"}); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangLisp.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2008 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | package io.github.kbiakov.codeview.highlight.prettify.lang; 15 | 16 | import java.util.ArrayList; 17 | import java.util.Arrays; 18 | import java.util.List; 19 | import java.util.regex.Pattern; 20 | import io.github.kbiakov.codeview.highlight.prettify.parser.Prettify; 21 | 22 | /** 23 | * This is similar to the lang-lisp.js in JavaScript Prettify. 24 | * 25 | * All comments are adapted from the JavaScript Prettify. 26 | * 27 | *

28 | * Registers a language handler for Common Lisp and related languages. 29 | * 30 | * 31 | * To use, include prettify.js and this file in your HTML page. 32 | * Then put your code in an HTML tag like 33 | *

(my lisp code)
34 | * The lang-cl class identifies the language as common lisp. 35 | * This file supports the following language extensions: 36 | * lang-cl - Common Lisp 37 | * lang-el - Emacs Lisp 38 | * lang-lisp - Lisp 39 | * lang-scm - Scheme 40 | * lang-lsp - FAT 8.3 filename version of lang-lisp. 41 | * 42 | * 43 | * I used http://www.devincook.com/goldparser/doc/meta-language/grammar-LISP.htm 44 | * as the basis, but added line comments that start with ; and changed the atom 45 | * production to disallow unquoted semicolons. 46 | * 47 | * "Name" = 'LISP' 48 | * "Author" = 'John McCarthy' 49 | * "Version" = 'Minimal' 50 | * "About" = 'LISP is an abstract language that organizes ALL' 51 | * | 'data around "lists".' 52 | * 53 | * "Start Symbol" = [s-Expression] 54 | * 55 | * {Atom Char} = {Printable} - {Whitespace} - [()"\''] 56 | * 57 | * Atom = ( {Atom Char} | '\'{Printable} )+ 58 | * 59 | * [s-Expression] ::= [Quote] Atom 60 | * | [Quote] '(' [Series] ')' 61 | * | [Quote] '(' [s-Expression] '.' [s-Expression] ')' 62 | * 63 | * [Series] ::= [s-Expression] [Series] 64 | * | 65 | * 66 | * [Quote] ::= '' !Quote = do not evaluate 67 | * | 68 | * 69 | * 70 | * I used Practical Common Lisp as 71 | * the basis for the reserved word list. 72 | * 73 | * 74 | * @author mikesamuel@gmail.com 75 | */ 76 | public class LangLisp extends Lang { 77 | 78 | public LangLisp() { 79 | List> _shortcutStylePatterns = new ArrayList>(); 80 | List> _fallthroughStylePatterns = new ArrayList>(); 81 | 82 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{"opn", Pattern.compile("^\\(+"), null, "("})); 83 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{"clo", Pattern.compile("^\\)+"), null, ")"})); 84 | // A line comment that starts with ; 85 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^;[^\r\n]*"), null, ";"})); 86 | // Whitespace 87 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[\t\n\r \\xA0]+"), null, "\t\n\r " + Character.toString((char) 0xA0)})); 88 | // A double quoted, possibly multi-line, string. 89 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^\\\"(?:[^\\\"\\\\]|\\\\[\\s\\S])*(?:\\\"|$)"), null, "\""})); 90 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^(?:block|c[ad]+r|catch|con[ds]|def(?:ine|un)|do|eq|eql|equal|equalp|eval-when|flet|format|go|if|labels|lambda|let|load-time-value|locally|macrolet|multiple-value-call|nil|progn|progv|quote|require|return-from|setq|symbol-macrolet|t|tagbody|the|throw|unwind)\\b", Pattern.CASE_INSENSITIVE), null})); 91 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^[+\\-]?(?:[0#]x[0-9a-f]+|\\d+\\/\\d+|(?:\\.\\d+|\\d+(?:\\.\\d*)?)(?:[ed][+\\-]?\\d+)?)", Pattern.CASE_INSENSITIVE)})); 92 | // A single quote possibly followed by a word that optionally ends with 93 | // = ! or ?. 94 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^\\'(?:-*(?:\\w|\\\\[\\x21-\\x7e])(?:[\\w-]*|\\\\[\\x21-\\x7e])[=!?]?)?")})); 95 | // A word that optionally ends with = ! or ?. 96 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^-*(?:[a-z_]|\\\\[\\x21-\\x7e])(?:[\\w-]*|\\\\[\\x21-\\x7e])[=!?]?", Pattern.CASE_INSENSITIVE)})); 97 | // A printable non-space non-special character 98 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^[^\\w\\t\\n\\r \\xA0()\\\"\\\\\\';]+")})); 99 | 100 | setShortcutStylePatterns(_shortcutStylePatterns); 101 | setFallthroughStylePatterns(_fallthroughStylePatterns); 102 | } 103 | 104 | public static List getFileExtensions() { 105 | return Arrays.asList(new String[]{"cl", "el", "lisp", "lsp", "scm", "ss", "rkt"}); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangLlvm.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2013 Nikhil Dabas 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | package io.github.kbiakov.codeview.highlight.prettify.lang; 15 | 16 | import java.util.ArrayList; 17 | import java.util.Arrays; 18 | import java.util.List; 19 | import java.util.regex.Pattern; 20 | import io.github.kbiakov.codeview.highlight.prettify.parser.Prettify; 21 | 22 | /** 23 | * This is similar to the lang-ml.js in JavaScript Prettify. 24 | * 25 | * All comments are adapted from the JavaScript Prettify. 26 | * 27 | *

Registers a language handler for LLVM. From 28 | * https://gist.github.com/ndabas/2850418 29 | * 30 | * 31 | * To use, include prettify.js and this file in your HTML page. Then put your 32 | * code in an HTML tag like

(my LLVM code)
33 | * 34 | * 35 | * The regular expressions were adapted from: 36 | * https://github.com/hansstimer/llvm.tmbundle/blob/76fedd8f50fd6108b1780c51d79fbe3223de5f34/Syntaxes/LLVM.tmLanguage 37 | * 38 | * http://llvm.org/docs/LangRef.html#constants describes the language grammar. 39 | * 40 | * @author Nikhil Dabas 41 | */ 42 | public class LangLlvm extends Lang { 43 | 44 | public LangLlvm() { 45 | List> _shortcutStylePatterns = new ArrayList>(); 46 | List> _fallthroughStylePatterns = new ArrayList>(); 47 | 48 | // Whitespace 49 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[\t\n\r \\xA0]+"), null, "\t\n\r " + Character.toString((char) 0xA0)})); 50 | // A double quoted, possibly multi-line, string. 51 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^!?\\\"(?:[^\\\"\\\\]|\\\\[\\s\\S])*(?:\\\"|$)"), null, "\""})); 52 | // comment.llvm 53 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^;[^\r\n]*"), null, ";"})); 54 | // variable.llvm 55 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[%@!](?:[-a-zA-Z$._][-a-zA-Z$._0-9]*|\\d+)")})); 56 | // According to http://llvm.org/docs/LangRef.html#well-formedness 57 | // These reserved words cannot conflict with variable names, because none of them start with a prefix character ('%' or '@'). 58 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^[A-Za-z_][0-9A-Za-z_]*"), null})); 59 | // constant.numeric.float.llvm 60 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^\\d+\\.\\d+")})); 61 | // constant.numeric.integer.llvm 62 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^(?:\\d+|0[xX][a-fA-F0-9]+)")})); 63 | // punctuation 64 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^[()\\[\\]{},=*<>:]|\\.\\.\\.$")})); 65 | 66 | setShortcutStylePatterns(_shortcutStylePatterns); 67 | setFallthroughStylePatterns(_fallthroughStylePatterns); 68 | } 69 | 70 | public static List getFileExtensions() { 71 | return Arrays.asList(new String[]{"llvm", "ll"}); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangLua.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2008 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | package io.github.kbiakov.codeview.highlight.prettify.lang; 15 | 16 | import java.util.ArrayList; 17 | import java.util.Arrays; 18 | import java.util.List; 19 | import java.util.regex.Pattern; 20 | import io.github.kbiakov.codeview.highlight.prettify.parser.Prettify; 21 | 22 | /** 23 | * This is similar to the lang-lua.js in JavaScript Prettify. 24 | * 25 | * All comments are adapted from the JavaScript Prettify. 26 | * 27 | *

28 | * Registers a language handler for Lua. 29 | * 30 | * 31 | * To use, include prettify.js and this file in your HTML page. 32 | * Then put your code in an HTML tag like 33 | *

(my Lua code)
34 | * 35 | * 36 | * I used http://www.lua.org/manual/5.1/manual.html#2.1 37 | * Because of the long-bracket concept used in strings and comments, Lua does 38 | * not have a regular lexical grammar, but luckily it fits within the space 39 | * of irregular grammars supported by javascript regular expressions. 40 | * 41 | * @author mikesamuel@gmail.com 42 | */ 43 | public class LangLua extends Lang { 44 | 45 | public LangLua() { 46 | List> _shortcutStylePatterns = new ArrayList>(); 47 | List> _fallthroughStylePatterns = new ArrayList>(); 48 | 49 | // Whitespace 50 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[\t\n\r \\xA0]+"), null, "\t\n\r " + Character.toString((char) 0xA0)})); 51 | // A double or single quoted, possibly multi-line, string. 52 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^(?:\\\"(?:[^\\\"\\\\]|\\\\[\\s\\S])*(?:\\\"|$)|\\'(?:[^\\'\\\\]|\\\\[\\s\\S])*(?:\\'|$))"), null, "\"'"})); 53 | // A comment is either a line comment that starts with two dashes, or 54 | // two dashes preceding a long bracketed block. 55 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^--(?:\\[(=*)\\[[\\s\\S]*?(?:\\]\\1\\]|$)|[^\\r\\n]*)")})); 56 | // A long bracketed block not preceded by -- is a string. 57 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^\\[(=*)\\[[\\s\\S]*?(?:\\]\\1\\]|$)")})); 58 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^(?:and|break|do|else|elseif|end|false|for|function|if|in|local|nil|not|or|repeat|return|then|true|until|while)\\b"), null})); 59 | // A number is a hex integer literal, a decimal real literal, or in 60 | // scientific notation. 61 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^[+-]?(?:0x[\\da-f]+|(?:(?:\\.\\d+|\\d+(?:\\.\\d*)?)(?:e[+\\-]?\\d+)?))", Pattern.CASE_INSENSITIVE)})); 62 | // An identifier 63 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[a-z_]\\w*", Pattern.CASE_INSENSITIVE)})); 64 | // A run of punctuation 65 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^[^\\w\\t\\n\\r \\xA0][^\\w\\n\\r \\xA0\\\"\\'\\-\\+=]*")})); 66 | 67 | setShortcutStylePatterns(_shortcutStylePatterns); 68 | setFallthroughStylePatterns(_fallthroughStylePatterns); 69 | } 70 | 71 | public static List getFileExtensions() { 72 | return Arrays.asList(new String[]{"lua"}); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangMd.java: -------------------------------------------------------------------------------- 1 | package io.github.kbiakov.codeview.highlight.prettify.lang; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | import java.util.regex.Pattern; 7 | import io.github.kbiakov.codeview.highlight.prettify.parser.Prettify; 8 | 9 | /** 10 | * Registers a language handler for markdown. 11 | * 12 | * @author Kirill Biakov (kbiakov@gmail.com) 13 | */ 14 | public class LangMd extends Lang { 15 | 16 | public LangMd() { 17 | List> _shortcutStylePatterns = new ArrayList>(); 18 | List> _fallthroughStylePatterns = new ArrayList>(); 19 | 20 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_DECLARATION, Pattern.compile("^#.*?[\\n\\r]")})); 21 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^```[\\s\\S]*?(?:```|$)")})); 22 | 23 | setShortcutStylePatterns(_shortcutStylePatterns); 24 | setFallthroughStylePatterns(_fallthroughStylePatterns); 25 | } 26 | 27 | public static List getFileExtensions() { 28 | return Arrays.asList(new String[]{"md", "markdown"}); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangMl.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2008 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | package io.github.kbiakov.codeview.highlight.prettify.lang; 15 | 16 | import java.util.ArrayList; 17 | import java.util.Arrays; 18 | import java.util.List; 19 | import java.util.regex.Pattern; 20 | import io.github.kbiakov.codeview.highlight.prettify.parser.Prettify; 21 | 22 | /** 23 | * This is similar to the lang-ml.js in JavaScript Prettify. 24 | * 25 | * All comments are adapted from the JavaScript Prettify. 26 | * 27 | *

28 | * Registers a language handler for OCaml, SML, F# and similar languages. 29 | * 30 | * Based on the lexical grammar at 31 | * http://research.microsoft.com/en-us/um/cambridge/projects/fsharp/manual/spec.html#_Toc270597388 32 | * 33 | * @author mikesamuel@gmail.com 34 | */ 35 | public class LangMl extends Lang { 36 | 37 | public LangMl() { 38 | List> _shortcutStylePatterns = new ArrayList>(); 39 | List> _fallthroughStylePatterns = new ArrayList>(); 40 | 41 | // Whitespace is made up of spaces, tabs and newline characters. 42 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[\\t\\n\\r \\xA0]+"), null, "\t\n\r " + Character.toString((char) 0xA0)})); 43 | // #if ident/#else/#endif directives delimit conditional compilation 44 | // sections 45 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^#(?:if[\\t\\n\\r \\xA0]+(?:[a-z_$][\\w\\']*|``[^\\r\\n\\t`]*(?:``|$))|else|endif|light)", Pattern.CASE_INSENSITIVE), null, "#"})); 46 | // A double or single quoted, possibly multi-line, string. 47 | // F# allows escaped newlines in strings. 48 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^(?:\\\"(?:[^\\\"\\\\]|\\\\[\\s\\S])*(?:\\\"|$)|\\'(?:[^\\'\\\\]|\\\\[\\s\\S])(?:\\'|$))"), null, "\"'"})); 49 | // Block comments are delimited by (* and *) and may be 50 | // nested. Single-line comments begin with // and extend to 51 | // the end of a line. 52 | // TODO: (*...*) comments can be nested. This does not handle that. 53 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^(?:\\/\\/[^\\r\\n]*|\\(\\*[\\s\\S]*?\\*\\))")})); 54 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^(?:abstract|and|as|assert|begin|class|default|delegate|do|done|downcast|downto|elif|else|end|exception|extern|false|finally|for|fun|function|if|in|inherit|inline|interface|internal|lazy|let|match|member|module|mutable|namespace|new|null|of|open|or|override|private|public|rec|return|static|struct|then|to|true|try|type|upcast|use|val|void|when|while|with|yield|asr|land|lor|lsl|lsr|lxor|mod|sig|atomic|break|checked|component|const|constraint|constructor|continue|eager|event|external|fixed|functor|global|include|method|mixin|object|parallel|process|protected|pure|sealed|trait|virtual|volatile)\\b")})); 55 | // A number is a hex integer literal, a decimal real literal, or in 56 | // scientific notation. 57 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^[+\\-]?(?:0x[\\da-f]+|(?:(?:\\.\\d+|\\d+(?:\\.\\d*)?)(?:e[+\\-]?\\d+)?))", Pattern.CASE_INSENSITIVE)})); 58 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^(?:[a-z_][\\w']*[!?#]?|``[^\\r\\n\\t`]*(?:``|$))", Pattern.CASE_INSENSITIVE)})); 59 | // A printable non-space non-special character 60 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^[^\\t\\n\\r \\xA0\\\"\\'\\w]+")})); 61 | 62 | setShortcutStylePatterns(_shortcutStylePatterns); 63 | setFallthroughStylePatterns(_fallthroughStylePatterns); 64 | } 65 | 66 | public static List getFileExtensions() { 67 | return Arrays.asList(new String[]{"fs", "ml"}); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangMumps.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2011 Kitware Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | package io.github.kbiakov.codeview.highlight.prettify.lang; 15 | 16 | import io.github.kbiakov.codeview.highlight.prettify.parser.Prettify; 17 | 18 | import java.util.ArrayList; 19 | import java.util.Arrays; 20 | import java.util.List; 21 | import java.util.regex.Pattern; 22 | 23 | /** 24 | * This is similar to the lang-mumps.js in JavaScript Prettify. 25 | *

26 | * All comments are adapted from the JavaScript Prettify. 27 | *

28 | *

29 | * To use, include prettify.js and this file in your HTML page. 30 | * Then put your code in an HTML tag like 31 | *

(my SQL code)
32 | *

33 | * Commands, intrinsic functions and variables taken from ISO/IEC 11756:1999(E) 34 | * 35 | * @author chris.harris@kitware.com 36 | *

37 | * Known issues: 38 | *

39 | * - Currently can't distinguish between keywords and local or global variables having the same name 40 | * for exampe SET IF="IF?" 41 | * - m file are already used for MatLab hence using mumps. 42 | */ 43 | public class LangMumps extends Lang { 44 | 45 | public LangMumps() { 46 | List> _shortcutStylePatterns = new ArrayList>(); 47 | List> _fallthroughStylePatterns = new ArrayList>(); 48 | 49 | final String commands = "B|BREAK|" + 50 | "C|CLOSE|" + 51 | "D|DO|" + 52 | "E|ELSE|" + 53 | "F|FOR|" + 54 | "G|GOTO|" + 55 | "H|HALT|" + 56 | "H|HANG|" + 57 | "I|IF|" + 58 | "J|JOB|" + 59 | "K|KILL|" + 60 | "L|LOCK|" + 61 | "M|MERGE|" + 62 | "N|NEW|" + 63 | "O|OPEN|" + 64 | "Q|QUIT|" + 65 | "R|READ|" + 66 | "S|SET|" + 67 | "TC|TCOMMIT|" + 68 | "TRE|TRESTART|" + 69 | "TRO|TROLLBACK|" + 70 | "TS|TSTART|" + 71 | "U|USE|" + 72 | "V|VIEW|" + 73 | "W|WRITE|" + 74 | "X|XECUTE"; 75 | 76 | final String intrinsicVariables = "D|DEVICE|" + 77 | "EC|ECODE|" + 78 | "ES|ESTACK|" + 79 | "ET|ETRAP|" + 80 | "H|HOROLOG|" + 81 | "I|IO|" + 82 | "J|JOB|" + 83 | "K|KEY|" + 84 | "P|PRINCIPAL|" + 85 | "Q|QUIT|" + 86 | "ST|STACK|" + 87 | "S|STORAGE|" + 88 | "SY|SYSTEM|" + 89 | "T|TEST|" + 90 | "TL|TLEVEL|" + 91 | "TR|TRESTART|" + 92 | "X|" + 93 | "Y|" + 94 | "Z[A-Z]*|"; 95 | 96 | final String intrinsicFunctions = "A|ASCII|" + 97 | "C|CHAR|" + 98 | "D|DATA|" + 99 | "E|EXTRACT|" + 100 | "F|FIND|" + 101 | "FN|FNUMBER|" + 102 | "G|GET|" + 103 | "J|JUSTIFY|" + 104 | "L|LENGTH|" + 105 | "NA|NAME|" + 106 | "O|ORDER|" + 107 | "P|PIECE|" + 108 | "QL|QLENGTH|" + 109 | "QS|QSUBSCRIPT|" + 110 | "Q|QUERY|" + 111 | "R|RANDOM|" + 112 | "RE|REVERSE|" + 113 | "S|SELECT|" + 114 | "ST|STACK|" + 115 | "T|TEXT|" + 116 | "TR|TRANSLATE|" + 117 | "V|VIEW|" + 118 | "Z[A-Z]*|"; 119 | 120 | final String intrinsic = intrinsicVariables + intrinsicFunctions; 121 | 122 | // Whitespace 123 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[\t\n\r \\xA0]+"), null, "\t\n\r " + Character.toString((char) 0xA0)})); 124 | // A double or single quoted, possibly multi-line, string. 125 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^(?:\"(?:[^\"]|\\\\.)*\")"), null, "\""})); 126 | 127 | // A line comment that starts with ; 128 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^;[^\\r\\n]*"), null, ";"})); 129 | // Add intrinsic variables and functions as declarations, there not really but it mean 130 | // they will hilighted differently from commands. 131 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_DECLARATION, Pattern.compile("^(?:\\$(?:" + intrinsic + "))\\b", Pattern.CASE_INSENSITIVE), null})); 132 | // Add commands as keywords 133 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^(?:[^\\$]" + commands + ")\\b", Pattern.CASE_INSENSITIVE), null})); 134 | // A number is a decimal real literal or in scientific notation. 135 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^[+-]?(?:(?:\\.\\d+|\\d+(?:\\.\\d*)?)(?:E[+\\-]?\\d+)?)", Pattern.CASE_INSENSITIVE)})); 136 | // An identifier 137 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[a-z][a-zA-Z0-9]*", Pattern.CASE_INSENSITIVE)})); 138 | // Exclude $ % and ^ 139 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^[^\\w\\t\\n\\r\\xA0\\\"\\$;%\\^]|_")})); 140 | 141 | setShortcutStylePatterns(_shortcutStylePatterns); 142 | setFallthroughStylePatterns(_fallthroughStylePatterns); 143 | } 144 | 145 | public static List getFileExtensions() { 146 | return Arrays.asList(new String[]{"mumps"}); 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangN.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2011 Zimin A.V. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | package io.github.kbiakov.codeview.highlight.prettify.lang; 15 | 16 | import java.util.ArrayList; 17 | import java.util.Arrays; 18 | import java.util.List; 19 | import java.util.regex.Pattern; 20 | import io.github.kbiakov.codeview.highlight.prettify.parser.Prettify; 21 | 22 | /** 23 | * This is similar to the lang-n.js in JavaScript Prettify. 24 | * 25 | * All comments are adapted from the JavaScript Prettify. 26 | * 27 | *

28 | * Registers a language handler for the Nemerle language. 29 | * http://nemerle.org 30 | * @author Zimin A.V. 31 | */ 32 | public class LangN extends Lang { 33 | 34 | protected static String keywords = "abstract|and|as|base|catch|class|def|delegate|enum|event|extern|false|finally|" 35 | + "fun|implements|interface|internal|is|macro|match|matches|module|mutable|namespace|new|" 36 | + "null|out|override|params|partial|private|protected|public|ref|sealed|static|struct|" 37 | + "syntax|this|throw|true|try|type|typeof|using|variant|virtual|volatile|when|where|with|" 38 | + "assert|assert2|async|break|checked|continue|do|else|ensures|for|foreach|if|late|lock|new|nolate|" 39 | + "otherwise|regexp|repeat|requires|return|surroundwith|unchecked|unless|using|while|yield"; 40 | 41 | public LangN() { 42 | List> _shortcutStylePatterns = new ArrayList>(); 43 | List> _fallthroughStylePatterns = new ArrayList>(); 44 | 45 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^(?:\\'(?:[^\\\\\\'\\r\\n]|\\\\.)*\\'|\\\"(?:[^\\\\\\\"\\r\\n]|\\\\.)*(?:\\\"|$))"), null, "\""})); 46 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\\b|[^\\r\\n]*)"), null, "#"})); 47 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^\\s+"), null, " \r\n\t" + Character.toString((char) 0xA0)})); 48 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^@\\\"(?:[^\\\"]|\\\"\\\")*(?:\\\"|$)"), null})); 49 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^<#(?:[^#>])*(?:#>|$)"), null})); 50 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^<(?:(?:(?:\\.\\.\\/)*|\\/?)(?:[\\w-]+(?:\\/[\\w-]+)+)?[\\w-]+\\.h|[a-z]\\w*)>"), null,})); 51 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^\\/\\/[^\\r\\n]*"), null})); 52 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^\\/\\*[\\s\\S]*?(?:\\*\\/|$)"), null})); 53 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^(?:" + keywords + ")\\\\b"), null})); 54 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_TYPE, Pattern.compile("^(?:array|bool|byte|char|decimal|double|float|int|list|long|object|sbyte|short|string|ulong|uint|ufloat|ulong|ushort|void)\\b"), null})); 55 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^@[a-z_$][a-z_$@0-9]*", Pattern.CASE_INSENSITIVE), null})); 56 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_TYPE, Pattern.compile("^@[A-Z]+[a-z][A-Za-z_$@0-9]*"), null})); 57 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^'?[A-Za-z_$][a-z_$@0-9]*", Pattern.CASE_INSENSITIVE), null})); 58 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^(?:" 59 | // A hex number 60 | + "0x[a-f0-9]+" 61 | // or an octal or decimal number, 62 | + "|(?:\\\\d(?:_\\\\d+)*\\\\d*(?:\\\\.\\\\d*)?|\\\\.\\\\d\\\\+)" 63 | // possibly in scientific notation 64 | + "(?:e[+\\\\-]?\\\\d+)?" 65 | + ")" 66 | // with an optional modifier like UL for unsigned long 67 | + "[a-z]*", Pattern.CASE_INSENSITIVE), null, "0123456789"})); 68 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^.[^\\s\\w\\.$@\\'\\\"\\`\\/\\#]*"), null})); 69 | 70 | setShortcutStylePatterns(_shortcutStylePatterns); 71 | setFallthroughStylePatterns(_fallthroughStylePatterns); 72 | } 73 | 74 | public static List getFileExtensions() { 75 | return Arrays.asList(new String[]{"n", "nemerle"}); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangPascal.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 Onno Hommes. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | package io.github.kbiakov.codeview.highlight.prettify.lang; 15 | 16 | import io.github.kbiakov.codeview.highlight.prettify.parser.Prettify; 17 | 18 | import java.util.ArrayList; 19 | import java.util.Arrays; 20 | import java.util.List; 21 | import java.util.regex.Pattern; 22 | 23 | /** 24 | * This is similar to the lang-appollo.js in JavaScript Prettify. 25 | *

26 | * All comments are adapted from the JavaScript Prettify. 27 | *

28 | *

29 | * Registers a language handler for the AGC/AEA Assembly Language as described 30 | * at http://virtualagc.googlecode.com 31 | *

32 | * This file could be used by goodle code to allow syntax highlight for 33 | * Virtual AGC SVN repository or if you don't want to commonize 34 | * the header for the agc/aea html assembly listing. 35 | * 36 | * @author ohommes@alumni.cmu.edu 37 | */ 38 | public class LangPascal extends Lang { 39 | 40 | public LangPascal() { 41 | List> _shortcutStylePatterns = new ArrayList>(); 42 | List> _fallthroughStylePatterns = new ArrayList>(); 43 | 44 | // 'single-line-string' 45 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^(?:\\'(?:[^\\\\\\'\\r\\n]|\\\\.)*(?:\\'|$))"), null, "'"})); 46 | // Whitespace 47 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^\\s+"), null, " \r\n\t" + Character.toString((char) 0xA0)})); 48 | 49 | // A cStyleComments comment (* *) or {} 50 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^\\(\\*[\\s\\S]*?(?:\\*\\)|$)|^\\{[\\s\\S]*?(?:\\}|$)"), null})); 51 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^(?:ABSOLUTE|AND|ARRAY|ASM|ASSEMBLER|BEGIN|CASE|CONST|CONSTRUCTOR|DESTRUCTOR|DIV|DO|DOWNTO|ELSE|END|EXTERNAL|FOR|FORWARD|FUNCTION|GOTO|IF|IMPLEMENTATION|IN|INLINE|INTERFACE|INTERRUPT|LABEL|MOD|NOT|OBJECT|OF|OR|PACKED|PROCEDURE|PROGRAM|RECORD|REPEAT|SET|SHL|SHR|THEN|TO|TYPE|UNIT|UNTIL|USES|VAR|VIRTUAL|WHILE|WITH|XOR)\\b", Pattern.CASE_INSENSITIVE), null})); 52 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^(?:true|false|self|nil)", Pattern.CASE_INSENSITIVE), null})); 53 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[a-z][a-z0-9]*", Pattern.CASE_INSENSITIVE), null})); 54 | // Literals .0, 0, 0.0 0E13 55 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^(?:\\$[a-f0-9]+|(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:e[+\\-]?\\d+)?)", Pattern.CASE_INSENSITIVE), null, "0123456789"})); 56 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^.[^\\s\\w\\.$@\\'\\/]*"), null})); 57 | 58 | setShortcutStylePatterns(_shortcutStylePatterns); 59 | setFallthroughStylePatterns(_fallthroughStylePatterns); 60 | } 61 | 62 | public static List getFileExtensions() { 63 | return Arrays.asList(new String[]{"pascal"}); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangProto.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | package io.github.kbiakov.codeview.highlight.prettify.lang; 15 | 16 | /** 17 | * It is included directly in the {@link io.github.kbiakov.codeview.highlight.prettify.parser.Prettify}. 18 | */ 19 | public class LangProto { 20 | } 21 | -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangR.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2012 Jeffrey B. Arnold 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | package io.github.kbiakov.codeview.highlight.prettify.lang; 15 | 16 | import io.github.kbiakov.codeview.highlight.prettify.parser.Prettify; 17 | 18 | import java.util.ArrayList; 19 | import java.util.Arrays; 20 | import java.util.List; 21 | import java.util.regex.Pattern; 22 | 23 | /** 24 | * This is similar to the lang-r.js in JavaScript Prettify. 25 | *

26 | * To use, include prettify.js and this file in your HTML page. 27 | * Then put your code in an HTML tag like 28 | *

 code 
29 | *

30 | * Language definition from 31 | * http://cran.r-project.org/doc/manuals/R-lang.html. 32 | * Many of the regexes are shared with the pygments SLexer, 33 | * http://pygments.org/. 34 | *

35 | * Original: https://raw.github.com/jrnold/prettify-lang-r-bugs/master/lang-r.js 36 | * 37 | * @author jeffrey.arnold@gmail.com 38 | */ 39 | public class LangR extends Lang { 40 | 41 | public LangR() { 42 | List> _shortcutStylePatterns = new ArrayList>(); 43 | List> _fallthroughStylePatterns = new ArrayList>(); 44 | 45 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[\\t\\n\\r \\xA0]+"), null, "\t\n\r " + Character.toString((char) 0xA0)})); 46 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^\\\"(?:[^\\\"\\\\]|\\\\[\\s\\S])*(?:\\\"|$)"), null, "\""})); 47 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^\\'(?:[^\\'\\\\]|\\\\[\\s\\S])*(?:\\'|$)"), null, "'"})); 48 | 49 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^#.*")})); 50 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^(?:if|else|for|while|repeat|in|next|break|return|switch|function)(?![A-Za-z0-9_.])")})); 51 | // hex numbes 52 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^0[xX][a-fA-F0-9]+([pP][0-9]+)?[Li]?")})); 53 | // Decimal numbers 54 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^[+-]?([0-9]+(\\.[0-9]+)?|\\.[0-9]+)([eE][+-]?[0-9]+)?[Li]?")})); 55 | // builtin symbols 56 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^(?:NULL|NA(?:_(?:integer|real|complex|character)_)?|Inf|TRUE|FALSE|NaN|\\.\\.(?:\\.|[0-9]+))(?![A-Za-z0-9_.])")})); 57 | // assignment, operators, and parens, etc. 58 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^(?:<>?|-|==|<=|>=|<|>|&&?|!=|\\|\\|?|\\*|\\+|\\^|\\/|!|%.*?%|=|~|\\$|@|:{1,3}|[\\[\\](){};,?])")})); 59 | // valid variable names 60 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^(?:[A-Za-z]+[A-Za-z0-9_.]*|\\.[a-zA-Z_][0-9a-zA-Z\\._]*)(?![A-Za-z0-9_.])")})); 61 | // string backtick 62 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^`.+`")})); 63 | 64 | setShortcutStylePatterns(_shortcutStylePatterns); 65 | setFallthroughStylePatterns(_fallthroughStylePatterns); 66 | } 67 | 68 | public static List getFileExtensions() { 69 | return Arrays.asList(new String[]{"r", "s", "R", "S", "Splus"}); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangRd.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2012 Jeffrey Arnold 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | package io.github.kbiakov.codeview.highlight.prettify.lang; 15 | 16 | import io.github.kbiakov.codeview.highlight.prettify.parser.Prettify; 17 | 18 | import java.util.ArrayList; 19 | import java.util.Arrays; 20 | import java.util.List; 21 | import java.util.regex.Pattern; 22 | 23 | /** 24 | * This is similar to the lang-rd.js in JavaScript Prettify. 25 | *

26 | * Support for R documentation (Rd) files 27 | *

28 | * Minimal highlighting or Rd files, basically just highlighting 29 | * macros. It does not try to identify verbatim or R-like regions of 30 | * macros as that is too complicated for a lexer. Descriptions of the 31 | * Rd format can be found 32 | * http://cran.r-project.org/doc/manuals/R-exts.html and 33 | * http://developer.r-project.org/parseRd.pdf. 34 | * 35 | * @author Jeffrey Arnold 36 | */ 37 | public class LangRd extends Lang { 38 | 39 | public LangRd() { 40 | List> _shortcutStylePatterns = new ArrayList>(); 41 | List> _fallthroughStylePatterns = new ArrayList>(); 42 | 43 | // whitespace 44 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[\\t\\n\\r \\xA0]+"), null, "\t\n\r " + Character.toString((char) 0xA0)})); 45 | // all comments begin with '%' 46 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^%[^\\r\\n]*"), null, "%"})); 47 | 48 | // special macros with no args 49 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^\\\\(?:cr|l?dots|R|tab)\\b")})); 50 | // macros 51 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^\\\\[a-zA-Z@]+")})); 52 | // highlighted as macros, since technically they are 53 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^#(?:ifn?def|endif)")})); 54 | // catch escaped brackets 55 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^\\\\[{}]")})); 56 | // punctuation 57 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^[{}()\\[\\]]+")})); 58 | 59 | setShortcutStylePatterns(_shortcutStylePatterns); 60 | setFallthroughStylePatterns(_fallthroughStylePatterns); 61 | } 62 | 63 | public static List getFileExtensions() { 64 | return Arrays.asList(new String[]{"Rd", "rd"}); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangScala.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | package io.github.kbiakov.codeview.highlight.prettify.lang; 15 | 16 | import java.util.ArrayList; 17 | import java.util.Arrays; 18 | import java.util.List; 19 | import java.util.regex.Pattern; 20 | import io.github.kbiakov.codeview.highlight.prettify.parser.Prettify; 21 | 22 | /** 23 | * This is similar to the lang-scala.js in JavaScript Prettify. 24 | * 25 | * All comments are adapted from the JavaScript Prettify. 26 | * 27 | *

28 | * Registers a language handler for Scala. 29 | * 30 | * Derived from http://lampsvn.epfl.ch/svn-repos/scala/scala-documentation/trunk/src/reference/SyntaxSummary.tex 31 | * 32 | * @author mikesamuel@gmail.com 33 | */ 34 | public class LangScala extends Lang { 35 | 36 | public LangScala() { 37 | List> _shortcutStylePatterns = new ArrayList>(); 38 | List> _fallthroughStylePatterns = new ArrayList>(); 39 | 40 | // Whitespace 41 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[\\t\\n\\r \\xA0]+"), null, "\t\n\r " + Character.toString((char) 0xA0)})); 42 | // A double or single quoted string 43 | // or a triple double-quoted multi-line string. 44 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^(?:\"(?:(?:\"\"(?:\"\"?(?!\")|[^\\\\\"]|\\\\.)*\"{0,3})|(?:[^\"\\r\\n\\\\]|\\\\.)*\"?))"), null, "\""})); 45 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^`(?:[^\\r\\n\\\\`]|\\\\.)*`?"), null, "`"})); 46 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^[!#%&()*+,\\-:;<=>?@\\[\\\\\\]^{|}~]+"), null, "!#%&()*+,-:;<=>?@[\\\\]^{|}~"})); 47 | // A symbol literal is a single quote followed by an identifier with no 48 | // single quote following 49 | // A character literal has single quotes on either side 50 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^'(?:[^\\r\\n\\\\']|\\\\(?:'|[^\\r\\n']+))'")})); 51 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^'[a-zA-Z_$][\\w$]*(?!['$\\w])")})); 52 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^(?:abstract|case|catch|class|def|do|else|extends|final|finally|for|forSome|if|implicit|import|lazy|match|new|object|override|package|private|protected|requires|return|sealed|super|throw|trait|try|type|val|var|while|with|yield)\\b")})); 53 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^(?:true|false|null|this)\\b")})); 54 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^(?:(?:0(?:[0-7]+|X[0-9A-F]+))L?|(?:(?:0|[1-9][0-9]*)(?:(?:\\.[0-9]+)?(?:E[+\\-]?[0-9]+)?F?|L?))|\\\\.[0-9]+(?:E[+\\-]?[0-9]+)?F?)", Pattern.CASE_INSENSITIVE)})); 55 | // Treat upper camel case identifiers as types. 56 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_TYPE, Pattern.compile("^[$_]*[A-Z][_$A-Z0-9]*[a-z][\\w$]*")})); 57 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[$a-zA-Z_][\\w$]*")})); 58 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^\\/(?:\\/.*|\\*(?:\\/|\\**[^*/])*(?:\\*+\\/?)?)")})); 59 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^(?:\\.+|\\/)")})); 60 | 61 | setShortcutStylePatterns(_shortcutStylePatterns); 62 | setFallthroughStylePatterns(_fallthroughStylePatterns); 63 | } 64 | 65 | public static List getFileExtensions() { 66 | return Arrays.asList(new String[]{"scala"}); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangSql.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2008 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | package io.github.kbiakov.codeview.highlight.prettify.lang; 15 | 16 | import java.util.ArrayList; 17 | import java.util.Arrays; 18 | import java.util.List; 19 | import java.util.regex.Pattern; 20 | import io.github.kbiakov.codeview.highlight.prettify.parser.Prettify; 21 | 22 | /** 23 | * This is similar to the lang-sql.js in JavaScript Prettify. 24 | * 25 | * All comments are adapted from the JavaScript Prettify. 26 | * 27 | *

28 | * Registers a language handler for SQL. 29 | * 30 | * 31 | * To use, include prettify.js and this file in your HTML page. 32 | * Then put your code in an HTML tag like 33 | *

(my SQL code)
34 | * 35 | * 36 | * http://savage.net.au/SQL/sql-99.bnf.html is the basis for the grammar, and 37 | * http://msdn.microsoft.com/en-us/library/aa238507(SQL.80).aspx and 38 | * http://meta.stackoverflow.com/q/92352/137403 as the bases for the keyword 39 | * list. 40 | * 41 | * @author mikesamuel@gmail.com 42 | */ 43 | public class LangSql extends Lang { 44 | 45 | public LangSql() { 46 | List> _shortcutStylePatterns = new ArrayList>(); 47 | List> _fallthroughStylePatterns = new ArrayList>(); 48 | 49 | // Whitespace 50 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[\\t\\n\\r \\xA0]+"), null, "\t\n\r " + Character.toString((char) 0xA0)})); 51 | // A double or single quoted, possibly multi-line, string. 52 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^(?:\"(?:[^\\\"\\\\]|\\\\.)*\"|'(?:[^\\'\\\\]|\\\\.)*')"), null, "\"'"})); 53 | // A comment is either a line comment that starts with two dashes, or 54 | // two dashes preceding a long bracketed block. 55 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^(?:--[^\\r\\n]*|\\/\\*[\\s\\S]*?(?:\\*\\/|$))")})); 56 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^(?:ADD|ALL|ALTER|AND|ANY|APPLY|AS|ASC|AUTHORIZATION|BACKUP|BEGIN|BETWEEN|BREAK|BROWSE|BULK|BY|CASCADE|CASE|CHECK|CHECKPOINT|CLOSE|CLUSTERED|COALESCE|COLLATE|COLUMN|COMMIT|COMPUTE|CONNECT|CONSTRAINT|CONTAINS|CONTAINSTABLE|CONTINUE|CONVERT|CREATE|CROSS|CURRENT|CURRENT_DATE|CURRENT_TIME|CURRENT_TIMESTAMP|CURRENT_USER|CURSOR|DATABASE|DBCC|DEALLOCATE|DECLARE|DEFAULT|DELETE|DENY|DESC|DISK|DISTINCT|DISTRIBUTED|DOUBLE|DROP|DUMMY|DUMP|ELSE|END|ERRLVL|ESCAPE|EXCEPT|EXEC|EXECUTE|EXISTS|EXIT|FETCH|FILE|FILLFACTOR|FOLLOWING|FOR|FOREIGN|FREETEXT|FREETEXTTABLE|FROM|FULL|FUNCTION|GOTO|GRANT|GROUP|HAVING|HOLDLOCK|IDENTITY|IDENTITYCOL|IDENTITY_INSERT|IF|IN|INDEX|INNER|INSERT|INTERSECT|INTO|IS|JOIN|KEY|KILL|LEFT|LIKE|LINENO|LOAD|MATCH|MERGE|NATIONAL|NOCHECK|NONCLUSTERED|NOT|NULL|NULLIF|OF|OFF|OFFSETS|ON|OPEN|OPENDATASOURCE|OPENQUERY|OPENROWSET|OPENXML|OPTION|OR|ORDER|OUTER|OVER|PERCENT|PLAN|PRECEDING|PRECISION|PRIMARY|PRINT|PROC|PROCEDURE|PUBLIC|RAISERROR|READ|READTEXT|RECONFIGURE|REFERENCES|REPLICATION|RESTORE|RESTRICT|RETURN|REVOKE|RIGHT|ROLLBACK|ROWCOUNT|ROWGUIDCOL|ROWS?|RULE|SAVE|SCHEMA|SELECT|SESSION_USER|SET|SETUSER|SHUTDOWN|SOME|STATISTICS|SYSTEM_USER|TABLE|TEXTSIZE|THEN|TO|TOP|TRAN|TRANSACTION|TRIGGER|TRUNCATE|TSEQUAL|UNBOUNDED|UNION|UNIQUE|UPDATE|UPDATETEXT|USE|USER|USING|VALUES|VARYING|VIEW|WAITFOR|WHEN|WHERE|WHILE|WITH|WRITETEXT)(?=[^\\w-]|$)", Pattern.CASE_INSENSITIVE), null})); 57 | // A number is a hex integer literal, a decimal real literal, or in 58 | // scientific notation. 59 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^[+-]?(?:0x[\\da-f]+|(?:(?:\\.\\d+|\\d+(?:\\.\\d*)?)(?:e[+\\-]?\\d+)?))", Pattern.CASE_INSENSITIVE)})); 60 | // An identifier 61 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[a-z_][\\w-]*", Pattern.CASE_INSENSITIVE)})); 62 | // A run of punctuation 63 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^[^\\w\\t\\n\\r \\xA0\\\"\\'][^\\w\\t\\n\\r \\xA0+\\-\\\"\\']*")})); 64 | 65 | setShortcutStylePatterns(_shortcutStylePatterns); 66 | setFallthroughStylePatterns(_fallthroughStylePatterns); 67 | } 68 | 69 | public static List getFileExtensions() { 70 | return Arrays.asList(new String[]{"sql"}); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangTcl.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2012 Pyrios. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | package io.github.kbiakov.codeview.highlight.prettify.lang; 15 | 16 | import io.github.kbiakov.codeview.highlight.prettify.parser.Prettify; 17 | 18 | import java.util.ArrayList; 19 | import java.util.Arrays; 20 | import java.util.List; 21 | import java.util.regex.Pattern; 22 | 23 | /** 24 | * This is similar to the lang-tcl.js in JavaScript Prettify. 25 | * 26 | * All comments are adapted from the JavaScript Prettify. 27 | * 28 | * To use, include prettify.js and this file in your HTML page. 29 | * Then put your code in an HTML tag like 30 | *
proc foo {} {puts bar}
31 | * 32 | * I copy-pasted lang-lisp.js, so this is probably not 100% accurate. 33 | * I used http://wiki.tcl.tk/1019 for the keywords, but tried to only 34 | * include as keywords that had more impact on the program flow 35 | * rather than providing convenience. For example, I included 'if' 36 | * since that provides branching, but left off 'open' since that is more 37 | * like a proc. Add more if it makes sense. 38 | * 39 | * @author pyrios@gmail.com 40 | */ 41 | public class LangTcl extends Lang { 42 | 43 | public LangTcl() { 44 | List> _shortcutStylePatterns = new ArrayList>(); 45 | List> _fallthroughStylePatterns = new ArrayList>(); 46 | 47 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{"opn", Pattern.compile("^\\{+"), null, "{"})); 48 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{"clo", Pattern.compile("^\\}+"), null, "}"})); 49 | // A line comment that starts with ; 50 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^#[^\\r\\n]*"), null, "#"})); 51 | // Whitespace 52 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[\\t\\n\\r \\xA0]+"), null, "\t\n\r " + Character.toString((char) 0xA0)})); 53 | // A double quoted, possibly multi-line, string. 54 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^\\\"(?:[^\\\"\\\\]|\\\\[\\s\\S])*(?:\\\"|$)"), null, "\""})); 55 | 56 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^(?:after|append|apply|array|break|case|catch|continue|error|eval|exec|exit|expr|for|foreach|if|incr|info|proc|return|set|switch|trace|uplevel|upvar|while)\\b"), null})); 57 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^[+\\-]?(?:[0#]x[0-9a-f]+|\\d+\\/\\d+|(?:\\.\\d+|\\d+(?:\\.\\d*)?)(?:[ed][+\\-]?\\d+)?)", Pattern.CASE_INSENSITIVE)})); 58 | // A single quote possibly followed by a word that optionally ends with 59 | // = ! or ?. 60 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^\\'(?:-*(?:\\w|\\\\[\\x21-\\x7e])(?:[\\w-]*|\\\\[\\x21-\\x7e])[=!?]?)?")})); 61 | // A word that optionally ends with = ! or ?. 62 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^-*(?:[a-z_]|\\\\[\\x21-\\x7e])(?:[\\w-]*|\\\\[\\x21-\\x7e])[=!?]?")})); 63 | // A printable non-space non-special character 64 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^[^\\w\\t\\n\\r \\xA0()\\\"\\\\\\';]+")})); 65 | 66 | setShortcutStylePatterns(_shortcutStylePatterns); 67 | setFallthroughStylePatterns(_fallthroughStylePatterns); 68 | } 69 | 70 | public static List getFileExtensions() { 71 | return Arrays.asList(new String[]{"tcl"}); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangTex.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2011 Martin S. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | package io.github.kbiakov.codeview.highlight.prettify.lang; 15 | 16 | import java.util.ArrayList; 17 | import java.util.Arrays; 18 | import java.util.List; 19 | import java.util.regex.Pattern; 20 | import io.github.kbiakov.codeview.highlight.prettify.parser.Prettify; 21 | 22 | /** 23 | * This is similar to the lang-tex.js in JavaScript Prettify. 24 | * 25 | * All comments are adapted from the JavaScript Prettify. 26 | * 27 | *

28 | * Support for tex highlighting as discussed on 29 | * meta.tex.stackexchange.com. 30 | * 31 | * @author Martin S. 32 | */ 33 | public class LangTex extends Lang { 34 | 35 | public LangTex() { 36 | List> _shortcutStylePatterns = new ArrayList>(); 37 | List> _fallthroughStylePatterns = new ArrayList>(); 38 | 39 | // whitespace 40 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[\\t\\n\\r \\xA0]+"), null, "\t\n\r " + Character.toString((char) 0xA0)})); 41 | // all comments begin with '%' 42 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^%[^\\r\\n]*"), null, "%"})); 43 | //[PR['PR_DECLARATION'], /^\\([egx]?def|(new|renew|provide)(command|environment))\b/], 44 | // any command starting with a \ and contains 45 | // either only letters (a-z,A-Z), '@' (internal macros) 46 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^\\\\[a-zA-Z@]+")})); 47 | // or contains only one character 48 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^\\\\.")})); 49 | // Highlight dollar for math mode and ampersam for tabular 50 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_TYPE, Pattern.compile("^[$&]")})); 51 | // numeric measurement values with attached units 52 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("[+-]?(?:\\.\\d+|\\d+(?:\\.\\d*)?)(cm|em|ex|in|pc|pt|bp|mm)", Pattern.CASE_INSENSITIVE)})); 53 | // punctuation usually occurring within commands 54 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^[{}()\\[\\]=]+")})); 55 | 56 | setShortcutStylePatterns(_shortcutStylePatterns); 57 | setFallthroughStylePatterns(_fallthroughStylePatterns); 58 | } 59 | 60 | public static List getFileExtensions() { 61 | return Arrays.asList(new String[]{"latex", "tex"}); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangVb.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | package io.github.kbiakov.codeview.highlight.prettify.lang; 15 | 16 | import java.util.ArrayList; 17 | import java.util.Arrays; 18 | import java.util.List; 19 | import java.util.regex.Pattern; 20 | import io.github.kbiakov.codeview.highlight.prettify.parser.Prettify; 21 | 22 | /** 23 | * This is similar to the lang-vb.js in JavaScript Prettify. 24 | * 25 | * All comments are adapted from the JavaScript Prettify. 26 | * 27 | *

28 | * Registers a language handler for various flavors of basic. 29 | * 30 | * 31 | * To use, include prettify.js and this file in your HTML page. 32 | * Then put your code in an HTML tag like 33 | *


34 |  *
35 |  *
36 |  * http://msdn.microsoft.com/en-us/library/aa711638(VS.71).aspx defines the
37 |  * visual basic grammar lexical grammar.
38 |  *
39 |  * @author mikesamuel@gmail.com
40 |  */
41 | public class LangVb extends Lang {
42 | 
43 |   public LangVb() {
44 |     List> _shortcutStylePatterns = new ArrayList>();
45 |     List> _fallthroughStylePatterns = new ArrayList>();
46 | 
47 |     // Whitespace
48 |     _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[\\t\\n\\r \\xA0\\u2028\\u2029]+"), null, "\t\n\r " + Character.toString((char) 0xA0) + "\u2028\u2029"}));
49 |     // A double quoted string with quotes escaped by doubling them.
50 |     // A single character can be suffixed with C.
51 |     _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^(?:[\\\"\\u201C\\u201D](?:[^\\\"\\u201C\\u201D]|[\\\"\\u201C\\u201D]{2})(?:[\\\"\\u201C\\u201D]c|$)|[\\\"\\u201C\\u201D](?:[^\\\"\\u201C\\u201D]|[\\\"\\u201C\\u201D]{2})*(?:[\\\"\\u201C\\u201D]|$))", Pattern.CASE_INSENSITIVE), null, "\"\u201C\u201D"}));
52 |     // A comment starts with a single quote and runs until the end of the line.
53 |     // VB6 apparently allows _ as an escape sequence for newlines though
54 |     // this is not a documented feature of VB.net.
55 |     // http://meta.stackoverflow.com/q/121497/137403
56 |     _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^[\\'\\u2018\\u2019](?:_(?:\r\n?|[^\r]?)|[^\\r\\n_\\u2028\\u2029])*"), null, "'\u2018\u2019"}));
57 |     _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^(?:AddHandler|AddressOf|Alias|And|AndAlso|Ansi|As|Assembly|Auto|Boolean|ByRef|Byte|ByVal|Call|Case|Catch|CBool|CByte|CChar|CDate|CDbl|CDec|Char|CInt|Class|CLng|CObj|Const|CShort|CSng|CStr|CType|Date|Decimal|Declare|Default|Delegate|Dim|DirectCast|Do|Double|Each|Else|ElseIf|End|EndIf|Enum|Erase|Error|Event|Exit|Finally|For|Friend|Function|Get|GetType|GoSub|GoTo|Handles|If|Implements|Imports|In|Inherits|Integer|Interface|Is|Let|Lib|Like|Long|Loop|Me|Mod|Module|MustInherit|MustOverride|MyBase|MyClass|Namespace|New|Next|Not|NotInheritable|NotOverridable|Object|On|Option|Optional|Or|OrElse|Overloads|Overridable|Overrides|ParamArray|Preserve|Private|Property|Protected|Public|RaiseEvent|ReadOnly|ReDim|RemoveHandler|Resume|Return|Select|Set|Shadows|Shared|Short|Single|Static|Step|Stop|String|Structure|Sub|SyncLock|Then|Throw|To|Try|TypeOf|Unicode|Until|Variant|Wend|When|While|With|WithEvents|WriteOnly|Xor|EndIf|GoSub|Let|Variant|Wend)\\b", Pattern.CASE_INSENSITIVE), null}));
58 |     // A second comment form
59 |     _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^REM\\b[^\\r\\n\\u2028\\u2029]*", Pattern.CASE_INSENSITIVE)}));
60 |     // A boolean, numeric, or date literal.
61 |     _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^(?:True\\b|False\\b|Nothing\\b|\\d+(?:E[+\\-]?\\d+[FRD]?|[FRDSIL])?|(?:&H[0-9A-F]+|&O[0-7]+)[SIL]?|\\d*\\.\\d+(?:E[+\\-]?\\d+)?[FRD]?|#\\s+(?:\\d+[\\-\\/]\\d+[\\-\\/]\\d+(?:\\s+\\d+:\\d+(?::\\d+)?(\\s*(?:AM|PM))?)?|\\d+:\\d+(?::\\d+)?(\\s*(?:AM|PM))?)\\s+#)", Pattern.CASE_INSENSITIVE)}));
62 |     // An identifier.  Keywords can be turned into identifers
63 |     // with square brackets, and there may be optional type
64 |     // characters after a normal identifier in square brackets.
65 |     _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^(?:(?:[a-z]|_\\w)\\w*(?:\\[[%&@!#]+\\])?|\\[(?:[a-z]|_\\w)\\w*\\])", Pattern.CASE_INSENSITIVE)}));
66 |     // A run of punctuation
67 |     _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^[^\\w\\t\\n\\r \\\"\\'\\[\\]\\xA0\\u2018\\u2019\\u201C\\u201D\\u2028\\u2029]+")}));
68 |     // Square brackets
69 |     _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^(?:\\[|\\])")}));
70 | 
71 |     setShortcutStylePatterns(_shortcutStylePatterns);
72 |     setFallthroughStylePatterns(_fallthroughStylePatterns);
73 |   }
74 | 
75 |   public static List getFileExtensions() {
76 |     return Arrays.asList(new String[]{"vb", "vbs"});
77 |   }
78 | }
79 | 


--------------------------------------------------------------------------------
/codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangVhdl.java:
--------------------------------------------------------------------------------
 1 | // Copyright (C) 2010 benoit@ryder.fr
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the "License");
 4 | // you may not use this file except in compliance with the License.
 5 | // You may obtain a copy of the License at
 6 | //
 7 | //      http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | package io.github.kbiakov.codeview.highlight.prettify.lang;
15 | 
16 | import java.util.ArrayList;
17 | import java.util.Arrays;
18 | import java.util.List;
19 | import java.util.regex.Pattern;
20 | import io.github.kbiakov.codeview.highlight.prettify.parser.Prettify;
21 | 
22 | /**
23 |  * This is similar to the lang-vhdl.js in JavaScript Prettify.
24 |  * 
25 |  * All comments are adapted from the JavaScript Prettify.
26 |  * 
27 |  * 

28 | * Registers a language handler for VHDL '93. 29 | * 30 | * Based on the lexical grammar and keywords at 31 | * http://www.iis.ee.ethz.ch/~zimmi/download/vhdl93_syntax.html 32 | * 33 | * @author benoit@ryder.fr 34 | */ 35 | public class LangVhdl extends Lang { 36 | 37 | public LangVhdl() { 38 | List> _shortcutStylePatterns = new ArrayList>(); 39 | List> _fallthroughStylePatterns = new ArrayList>(); 40 | 41 | // Whitespace 42 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[\\t\\n\\r \\xA0]+"), null, "\t\n\r " + Character.toString((char) 0xA0)})); 43 | // String, character or bit string 44 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^(?:[BOX]?\"(?:[^\\\"]|\"\")*\"|'.')", Pattern.CASE_INSENSITIVE)})); 45 | // Comment, from two dashes until end of line. 46 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^--[^\\r\\n]*")})); 47 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^(?:abs|access|after|alias|all|and|architecture|array|assert|attribute|begin|block|body|buffer|bus|case|component|configuration|constant|disconnect|downto|else|elsif|end|entity|exit|file|for|function|generate|generic|group|guarded|if|impure|in|inertial|inout|is|label|library|linkage|literal|loop|map|mod|nand|new|next|nor|not|null|of|on|open|or|others|out|package|port|postponed|procedure|process|pure|range|record|register|reject|rem|report|return|rol|ror|select|severity|shared|signal|sla|sll|sra|srl|subtype|then|to|transport|type|unaffected|units|until|use|variable|wait|when|while|with|xnor|xor)(?=[^\\w-]|$)", Pattern.CASE_INSENSITIVE), null})); 48 | // Type, predefined or standard 49 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_TYPE, Pattern.compile("^(?:bit|bit_vector|character|boolean|integer|real|time|string|severity_level|positive|natural|signed|unsigned|line|text|std_u?logic(?:_vector)?)(?=[^\\w-]|$)", Pattern.CASE_INSENSITIVE), null})); 50 | // Predefined attributes 51 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_TYPE, Pattern.compile("^\\'(?:ACTIVE|ASCENDING|BASE|DELAYED|DRIVING|DRIVING_VALUE|EVENT|HIGH|IMAGE|INSTANCE_NAME|LAST_ACTIVE|LAST_EVENT|LAST_VALUE|LEFT|LEFTOF|LENGTH|LOW|PATH_NAME|POS|PRED|QUIET|RANGE|REVERSE_RANGE|RIGHT|RIGHTOF|SIMPLE_NAME|STABLE|SUCC|TRANSACTION|VAL|VALUE)(?=[^\\w-]|$)", Pattern.CASE_INSENSITIVE), null})); 52 | // Number, decimal or based literal 53 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^\\d+(?:_\\d+)*(?:#[\\w\\\\.]+#(?:[+\\-]?\\d+(?:_\\d+)*)?|(?:\\.\\d+(?:_\\d+)*)?(?:E[+\\-]?\\d+(?:_\\d+)*)?)", Pattern.CASE_INSENSITIVE)})); 54 | // Identifier, basic or extended 55 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^(?:[a-z]\\w*|\\\\[^\\\\]*\\\\)", Pattern.CASE_INSENSITIVE)})); 56 | // Punctuation 57 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^[^\\w\\t\\n\\r \\xA0\\\"\\'][^\\w\\t\\n\\r \\xA0\\-\\\"\\']*")})); 58 | 59 | setShortcutStylePatterns(_shortcutStylePatterns); 60 | setFallthroughStylePatterns(_fallthroughStylePatterns); 61 | } 62 | 63 | public static List getFileExtensions() { 64 | return Arrays.asList(new String[]{"vhdl", "vhd"}); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangWiki.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | package io.github.kbiakov.codeview.highlight.prettify.lang; 15 | 16 | import java.util.ArrayList; 17 | import java.util.Arrays; 18 | import java.util.List; 19 | import java.util.regex.Pattern; 20 | import io.github.kbiakov.codeview.highlight.prettify.parser.Prettify; 21 | 22 | /** 23 | * This is similar to the lang-wiki.js in JavaScript Prettify. 24 | * 25 | * All comments are adapted from the JavaScript Prettify. 26 | * 27 | *

28 | * Registers a language handler for Wiki pages. 29 | * 30 | * Based on WikiSyntax at http://code.google.com/p/support/wiki/WikiSyntax 31 | * 32 | * @author mikesamuel@gmail.com 33 | */ 34 | public class LangWiki extends Lang { 35 | 36 | public LangWiki() { 37 | List> _shortcutStylePatterns = new ArrayList>(); 38 | List> _fallthroughStylePatterns = new ArrayList>(); 39 | 40 | // Whitespace 41 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[\\t \\xA0a-gi-z0-9]+"), null, "\t " + Character.toString((char) 0xA0) + "abcdefgijklmnopqrstuvwxyz0123456789"})); 42 | // Wiki formatting 43 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^[=*~\\^\\[\\]]+"), null, "=*~^[]"})); 44 | // Meta-info like #summary, #labels, etc. 45 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{"lang-wiki.meta", Pattern.compile("(?:^^|\r\n?|\n)(#[a-z]+)\\b")})); 46 | // A WikiWord 47 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^(?:[A-Z][a-z][a-z0-9]+[A-Z][a-z][a-zA-Z0-9]+)\\b")})); 48 | // A preformatted block in an unknown language 49 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{"lang-", Pattern.compile("^\\{\\{\\{([\\s\\S]+?)\\}\\}\\}")})); 50 | // A block of source code in an unknown language 51 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{"lang-", Pattern.compile("^`([^\r\n`]+)`")})); 52 | // An inline URL. 53 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^https?:\\/\\/[^\\/?#\\s]*(?:\\/[^?#\\s]*)?(?:\\?[^#\\s]*)?(?:#\\S*)?", Pattern.CASE_INSENSITIVE)})); 54 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^(?:\r\n|[\\s\\S])[^#=*~^A-Zh\\{`\\[\r\n]*")})); 55 | 56 | setShortcutStylePatterns(_shortcutStylePatterns); 57 | setFallthroughStylePatterns(_fallthroughStylePatterns); 58 | 59 | setExtendedLangs(Arrays.asList(new Lang[]{new LangWikiMeta()})); 60 | } 61 | 62 | public static List getFileExtensions() { 63 | return Arrays.asList(new String[]{"wiki"}); 64 | } 65 | 66 | protected static class LangWikiMeta extends Lang { 67 | 68 | public LangWikiMeta() { 69 | List> _shortcutStylePatterns = new ArrayList>(); 70 | List> _fallthroughStylePatterns = new ArrayList>(); 71 | 72 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^#[a-z]+", Pattern.CASE_INSENSITIVE), null, "#"})); 73 | 74 | setShortcutStylePatterns(_shortcutStylePatterns); 75 | setFallthroughStylePatterns(_fallthroughStylePatterns); 76 | } 77 | 78 | public static List getFileExtensions() { 79 | return Arrays.asList(new String[]{"wiki.meta"}); 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/LangYaml.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2010 ribrdb @ code.google.com 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | package io.github.kbiakov.codeview.highlight.prettify.lang; 15 | 16 | import java.util.ArrayList; 17 | import java.util.Arrays; 18 | import java.util.List; 19 | import java.util.regex.Pattern; 20 | import io.github.kbiakov.codeview.highlight.prettify.parser.Prettify; 21 | 22 | /** 23 | * This is similar to the lang-yaml.js in JavaScript Prettify. 24 | * 25 | * All comments are adapted from the JavaScript Prettify. 26 | * 27 | *

28 | * Registers a language handler for YAML. 29 | * 30 | * @author ribrdb 31 | */ 32 | public class LangYaml extends Lang { 33 | 34 | public LangYaml() { 35 | List> _shortcutStylePatterns = new ArrayList>(); 36 | List> _fallthroughStylePatterns = new ArrayList>(); 37 | 38 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^[:|>?]+"), null, ":|>?"})); 39 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_DECLARATION, Pattern.compile("^%(?:YAML|TAG)[^#\\r\\n]+"), null, "%"})); 40 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_TYPE, Pattern.compile("^[&]\\S+"), null, "&"})); 41 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_TYPE, Pattern.compile("^!\\S*"), null, "!"})); 42 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^\"(?:[^\\\\\"]|\\\\.)*(?:\"|$)"), null, "\""})); 43 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^'(?:[^']|'')*(?:'|$)"), null, "'"})); 44 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^#[^\\r\\n]*"), null, "#"})); 45 | _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^\\s+"), null, " \t\r\n"})); 46 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_DECLARATION, Pattern.compile("^(?:---|\\.\\.\\.)(?:[\\r\\n]|$)")})); 47 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^-")})); 48 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^\\w+:[ \\r\\n]")})); 49 | _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^\\w+")})); 50 | 51 | setShortcutStylePatterns(_shortcutStylePatterns); 52 | setFallthroughStylePatterns(_fallthroughStylePatterns); 53 | } 54 | 55 | public static List getFileExtensions() { 56 | return Arrays.asList(new String[]{"yaml", "yml"}); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/lang/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * All languages that comes with release. 3 | */ 4 | package prettify.lang; -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/highlight/prettify/parser/Job.java: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2006 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | package io.github.kbiakov.codeview.highlight.prettify.parser; 15 | 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | 19 | /** 20 | * This is the job object that similar to those in JavaScript Prettify. 21 | * 22 | * @author Chan Wai Shing 23 | */ 24 | public class Job { 25 | 26 | /** 27 | * The starting point of the source code. 28 | */ 29 | protected int basePos; 30 | /** 31 | * The source code. 32 | */ 33 | protected String sourceCode; 34 | /** 35 | * The parsed results. nth items are starting position position, 36 | * n+1th items are the three-letter style keyword, where n start 37 | * from 0. 38 | */ 39 | protected List decorations; 40 | 41 | /** 42 | * Constructor. 43 | */ 44 | public Job() { 45 | this(0, ""); 46 | } 47 | 48 | /** 49 | * Constructor. 50 | * 51 | * @param basePos the starting point of the source code 52 | * @param sourceCode the source code 53 | */ 54 | public Job(int basePos, String sourceCode) { 55 | if (sourceCode == null) { 56 | throw new NullPointerException("argument 'sourceCode' cannot be null"); 57 | } 58 | this.basePos = basePos; 59 | this.sourceCode = sourceCode; 60 | decorations = new ArrayList(); 61 | } 62 | 63 | /** 64 | * Set the starting point of the source code. 65 | * 66 | * @return the position 67 | */ 68 | public int getBasePos() { 69 | return basePos; 70 | } 71 | 72 | /** 73 | * Set the starting point of the source code. 74 | * 75 | * @param basePos the position 76 | */ 77 | public void setBasePos(int basePos) { 78 | this.basePos = basePos; 79 | } 80 | 81 | /** 82 | * Get the source code. 83 | * 84 | * @return the source code 85 | */ 86 | public String getSourceCode() { 87 | return sourceCode; 88 | } 89 | 90 | /** 91 | * Set the source code. 92 | * 93 | * @param sourceCode the source code 94 | */ 95 | public void setSourceCode(String sourceCode) { 96 | if (sourceCode == null) { 97 | throw new NullPointerException("argument 'sourceCode' cannot be null"); 98 | } 99 | this.sourceCode = sourceCode; 100 | } 101 | 102 | /** 103 | * Get the parsed results. see {@link #decorations}. 104 | * 105 | * @return the parsed results 106 | */ 107 | public List getDecorations() { 108 | return new ArrayList(decorations); 109 | } 110 | 111 | /** 112 | * Set the parsed results. see {@link #decorations}. 113 | * 114 | * @param decorations the parsed results 115 | */ 116 | public void setDecorations(List decorations) { 117 | if (decorations == null) { 118 | this.decorations = new ArrayList(); 119 | return; 120 | } 121 | this.decorations = new ArrayList(decorations); 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/views/BidirectionalScrollView.kt: -------------------------------------------------------------------------------- 1 | package io.github.kbiakov.codeview.views 2 | 3 | import android.content.Context 4 | import android.util.AttributeSet 5 | import android.view.MotionEvent 6 | import android.view.View 7 | import android.view.View.MeasureSpec.makeMeasureSpec 8 | import android.widget.HorizontalScrollView 9 | import io.github.kbiakov.codeview.dpToPx 10 | 11 | /** 12 | * @class BidirectionalScrollView 13 | * 14 | * Combines vertical & horizontal scroll to implement bidirectional 15 | * scrolling behavior (like a map view, for example). 16 | * 17 | * @author Kirill Biakov 18 | */ 19 | class BidirectionalScrollView : HorizontalScrollView { 20 | 21 | private var currentX = 0 22 | private var currentY = 0 23 | private var isMoved = false 24 | 25 | constructor(context: Context) : super(context) 26 | constructor(context: Context, attrs: AttributeSet) : super(context, attrs) 27 | constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) 28 | 29 | override fun dispatchTouchEvent(event: MotionEvent): Boolean { 30 | when (event.action) { 31 | MotionEvent.ACTION_DOWN -> { 32 | currentX = event.rawX.toInt() 33 | currentY = event.rawY.toInt() 34 | return super.dispatchTouchEvent(event) 35 | } 36 | MotionEvent.ACTION_MOVE -> { 37 | val deltaX = Math.abs(currentX - event.rawX) 38 | val deltaY = Math.abs(currentY - event.rawY) 39 | scroll(event) 40 | 41 | val movedOnDistance = dpToPx(context, 2) 42 | if (deltaX > movedOnDistance || deltaY > movedOnDistance) { 43 | isMoved = true 44 | } 45 | } 46 | MotionEvent.ACTION_UP -> { 47 | if (!isMoved) { 48 | return super.dispatchTouchEvent(event) 49 | } 50 | isMoved = false 51 | } 52 | MotionEvent.ACTION_CANCEL -> { 53 | isMoved = false 54 | } 55 | } 56 | return true 57 | } 58 | 59 | private fun scroll(event: MotionEvent) { 60 | val x2 = event.rawX.toInt() 61 | val y2 = event.rawY.toInt() 62 | val posX = currentX - x2 63 | val posY = currentY - y2 64 | scrollBy(posX, posY) 65 | 66 | currentX = x2 67 | currentY = y2 68 | } 69 | 70 | override fun measureChild(child: View, parentWidthMeasureSpec: Int, parentHeightMeasureSpec: Int) { 71 | val zeroMeasureSpec = makeMeasureSpec(0) 72 | child.measure(zeroMeasureSpec, zeroMeasureSpec) 73 | } 74 | 75 | override fun measureChildWithMargins( 76 | child: View, 77 | parentWidthMeasureSpec: Int, widthUsed: Int, 78 | parentHeightMeasureSpec: Int, heightUsed: Int 79 | ) = with(child.layoutParams as MarginLayoutParams) { 80 | val widthMeasureSpec = makeMeasureSpec(leftMargin + rightMargin, MeasureSpec.UNSPECIFIED) 81 | val heightMeasureSpec = makeMeasureSpec(topMargin + bottomMargin, MeasureSpec.UNSPECIFIED) 82 | child.measure(widthMeasureSpec, heightMeasureSpec) 83 | } 84 | 85 | private fun makeMeasureSpec(size: Int) = makeMeasureSpec(size, MeasureSpec.UNSPECIFIED) 86 | } 87 | -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/views/LineDiffView.kt: -------------------------------------------------------------------------------- 1 | package io.github.kbiakov.codeview.views 2 | 3 | import android.content.Context 4 | import android.support.v4.content.ContextCompat 5 | import android.view.LayoutInflater 6 | import android.widget.RelativeLayout 7 | import android.widget.TextView 8 | import io.github.kbiakov.codeview.R 9 | import io.github.kbiakov.codeview.highlight.FontCache 10 | 11 | /** 12 | * @class CodeDiffView 13 | * 14 | * View to present code difference (additions & deletions). 15 | * 16 | * @author Kirill Biakov 17 | */ 18 | class LineDiffView(context: Context) : RelativeLayout(context) { 19 | 20 | private val tvLineDiff: TextView 21 | private val tvLineContent: TextView 22 | 23 | init { 24 | val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater 25 | inflater.inflate(R.layout.item_code_diff, this, true) 26 | 27 | tvLineDiff = findViewById(R.id.tv_line_diff) as TextView 28 | tvLineContent = findViewById(R.id.tv_line_content) as TextView 29 | } 30 | 31 | companion object Factory { 32 | /** 33 | * Simple factory method to create code diff view. 34 | * 35 | * @param context Context 36 | * @param model Diff model 37 | * @return Created line diff view 38 | */ 39 | fun create(context: Context, model: DiffModel) = LineDiffView(context).apply { 40 | tvLineDiff.text = if (model.isAddition) "+" else "-" 41 | tvLineContent.text = model.content 42 | tvLineContent.typeface = FontCache.get(context).getTypeface(context) 43 | 44 | setBackgroundColor(ContextCompat.getColor(context, 45 | if (model.isAddition) 46 | R.color.diff_add_background 47 | else 48 | R.color.diff_del_background)) 49 | } 50 | } 51 | } 52 | 53 | /** 54 | * Model for code difference (additions & deletions). 55 | * 56 | * @author Kirill Biakov 57 | */ 58 | data class DiffModel(val content: String, val isAddition: Boolean = true) 59 | -------------------------------------------------------------------------------- /codeview/src/main/java/io/github/kbiakov/codeview/views/LineNoteView.kt: -------------------------------------------------------------------------------- 1 | package io.github.kbiakov.codeview.views 2 | 3 | import android.content.Context 4 | import android.widget.TextView 5 | import io.github.kbiakov.codeview.R 6 | import io.github.kbiakov.codeview.dpToPx 7 | 8 | /** 9 | * @class LineNoteView 10 | * 11 | * Note view for code line. Default footer view. 12 | * 13 | * @author Kirill Biakov 14 | */ 15 | class LineNoteView(context: Context?) : TextView(context) { 16 | 17 | companion object Factory { 18 | /** 19 | * Simple factory method to create note view. 20 | * 21 | * @param context Context 22 | * @param text Note text 23 | * @param isFirst Is first footer view 24 | * @param bgColor Background color 25 | * @param textColor Text Color 26 | * @return Created line note view 27 | */ 28 | fun create(context: Context, text: String, isFirst: Boolean, bgColor: Int, textColor: Int): LineNoteView { 29 | val noteView = LineNoteView(context) 30 | noteView.textSize = 12f 31 | noteView.text = text 32 | noteView.setTextColor(textColor) 33 | noteView.setBackgroundColor(bgColor) 34 | 35 | val dp8 = dpToPx(context, 8) 36 | 37 | val leftPadding = context.resources.getDimension( 38 | R.dimen.line_num_width).toInt() + dpToPx(context, 14) 39 | 40 | val topPadding = if (isFirst) dp8 else 0 41 | 42 | noteView.setPadding(leftPadding, topPadding, dp8, dp8) 43 | 44 | return noteView 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /codeview/src/main/res/layout/item_code_diff.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 14 | 15 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /codeview/src/main/res/layout/item_code_line.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 15 | 16 | 28 | 29 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /codeview/src/main/res/layout/layout_code_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 19 | 20 | 21 | 22 | 28 | 29 | 34 | 35 | 39 | 40 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /codeview/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /codeview/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #EAFFEA 4 | #FFECEC 5 | 6 | -------------------------------------------------------------------------------- /codeview/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 32dp 5 | 24dp 6 | 4dp 7 | 12sp 8 | 24dp 9 | 16dp 10 | 11 | -------------------------------------------------------------------------------- /codeview/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | CodeView 3 | 4 | 1 5 | public static final int main(String[] args) { 6 | Show all 7 | ... 8 | 9 | -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /example/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | 4 | android { 5 | compileSdkVersion compileSdk 6 | buildToolsVersion buildTools 7 | 8 | defaultConfig { 9 | applicationId 'io.github.kbiakov.codeviewexample' 10 | minSdkVersion minSdk 11 | targetSdkVersion compileSdk 12 | versionCode 1 13 | versionName '1.0' 14 | } 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | lintOptions { 22 | abortOnError false 23 | } 24 | } 25 | 26 | dependencies { 27 | implementation project(':codeview') 28 | 29 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion" 30 | implementation "com.android.support:appcompat-v7:$supportLibrary" 31 | implementation "com.android.support:recyclerview-v7:$supportLibrary" 32 | } 33 | repositories { 34 | mavenCentral() 35 | } 36 | -------------------------------------------------------------------------------- /example/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/macuser/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /example/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /example/src/main/java/io/github/kbiakov/codeviewexample/BaseApplication.java: -------------------------------------------------------------------------------- 1 | package io.github.kbiakov.codeviewexample; 2 | 3 | import android.app.Application; 4 | 5 | import io.github.kbiakov.codeview.classifier.CodeProcessor; 6 | 7 | public class BaseApplication extends Application { 8 | 9 | @Override 10 | public void onCreate() { 11 | super.onCreate(); 12 | 13 | // train classifier on app start 14 | CodeProcessor.init(this); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /example/src/main/java/io/github/kbiakov/codeviewexample/CustomAdapter.java: -------------------------------------------------------------------------------- 1 | package io.github.kbiakov.codeviewexample; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.widget.TextView; 7 | 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | import io.github.kbiakov.codeview.adapters.AbstractCodeAdapter; 11 | import io.github.kbiakov.codeview.adapters.Options; 12 | import io.github.kbiakov.codeview.highlight.ColorTheme; 13 | 14 | public class CustomAdapter extends AbstractCodeAdapter { 15 | 16 | public CustomAdapter(@NotNull Context context, @NotNull String code) { 17 | super(context, Options.Default.get(context) 18 | .withCode(code) 19 | .withTheme(ColorTheme.SOLARIZED_LIGHT)); 20 | } 21 | 22 | @NotNull 23 | @Override 24 | public View createFooter(@NotNull Context context, CustomModel entity, boolean isFirst) { 25 | View footerView = LayoutInflater.from(context).inflate(R.layout.custom_footer, null); 26 | ((TextView) footerView.findViewById(R.id.tv_footer_title)).setText(entity.firstName); 27 | ((TextView) footerView.findViewById(R.id.tv_footer_description)).setText(entity.lastName); 28 | return footerView; 29 | } 30 | 31 | public static class CustomModel { 32 | private String firstName; 33 | private String lastName; 34 | 35 | public CustomModel(String firstName, String lastName) { 36 | this.firstName = firstName; 37 | this.lastName = lastName; 38 | } 39 | 40 | public String getFirstName() { 41 | return firstName; 42 | } 43 | 44 | public String getLastName() { 45 | return lastName; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /example/src/main/res/layout/activity_listings.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /example/src/main/res/layout/custom_footer.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 14 | 15 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /example/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbiakov/CodeView-Android/91ec9008effbfc1e82335ad568f177043eb9881a/example/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbiakov/CodeView-Android/91ec9008effbfc1e82335ad568f177043eb9881a/example/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbiakov/CodeView-Android/91ec9008effbfc1e82335ad568f177043eb9881a/example/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbiakov/CodeView-Android/91ec9008effbfc1e82335ad568f177043eb9881a/example/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbiakov/CodeView-Android/91ec9008effbfc1e82335ad568f177043eb9881a/example/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /example/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | CodeViewExample 4 | 5 | 6 | <SCRIPT language=\"JavaScript\" type=\"text/javascript\"> \r\n 7 | function fulltime () { \r\n 8 | var time=new Date(); // create a variable of the current time in our code\r\n 9 | var Event=new Date(\"dec,31,2015,10:10:10\"); // date and time of our event\r\n 10 | var totalRemains=(Event.getTime()-time.getTime()); // compute the difference\r\n 11 | \r\n 12 | if (totalRemains>1){ // if have time alittle bit...\r\n 13 | var RemainsSec = (parseInt(totalRemains/1000)); // then compute rest time\r\n 14 | var RemainsFullDays=(parseInt(RemainsSec)); // extract full days\r\n 15 | var secInLastDay=RemainsSec-RemainsFullDays*24*3600; \r\n 16 | var RemainsFullHours=(parseInt(secInLastDay/3600)); // full hours\r\n 17 | if (RemainsFullHours<10){RemainsFullHours=\"0\"+Remains FullHours}; \r\n 18 | var secInLastHour=secInLastDay-RemainsFullHours*3600; \r\n 19 | var RemainsMinutes=(parseInt(secInLastHour/60)); // minutes\r\n 20 | if (RemainsMinutes<10){RemainsMinutes=\"0\"+RemainsMinu tes}; \r\n 21 | var lastSec=secInLastHour-RemainsMinutes*60; // seconds\r\n 22 | if (lastSec<10){lastSec=\"0\"+lastSec}; \r\n 23 | \r\n 24 | document.getElementById(\"RemainsFullDays\").innerHTML=RemainsFullDays+\" seconds\"; \r\n 25 | setTimeout(\'fulltime()\',10) \r\n 26 | }\r\n 27 | \r\n 28 | else{ \r\n 29 | document.getElementById(\"clock\").innerHTML=\"Go to main page to full inforamtion\"; // if have no time, change time to our string\r\n 30 | }\r\n 31 | }\r\n 32 | </SCRIPT> \r\n 33 | \r\n 34 | <body>// script is can be runned on page\r\n 35 | <div align=\"center\"><span id=\"clock\"> 36 | </div> \r\n 37 | <div align=\"center\"><b><span id=\"RemainsFullDays\"> 38 | </span></b></div><br>\r\n 39 | </span> \r\n 40 | \r\n 41 | <SCRIPT language=\"JavaScript\">fulltime();</SCRIPT> 42 | 43 | 44 | 45 | 3. CodeView and related adapter.\n 46 | \n 47 | ## Download\n 48 | Add it in your root ```build.gradle``` at the end of repositories:\n 49 | ```groovy\n 50 | allprojects {\n 51 | repositories {\n 52 | ...\n 53 | maven { url \"https://jitpack.io\" }\n 54 | }\n 55 | }\n 56 | ```\n 57 | \n 58 | Add the dependency: 59 | 60 | 61 | 62 | package io.github.kbiakov.codeviewexample;\n 63 | \n 64 | import android.os.Bundle;\n 65 | import android.support.annotation.Nullable;\n 66 | import android.support.v4.content.ContextCompat;\n 67 | import android.support.v7.app.AppCompatActivity;\n 68 | \n 69 | import io.github.kbiakov.codeview.CodeView;\n 70 | import io.github.kbiakov.codeview.highlight.ColorTheme;\n 71 | \n 72 | public class ListingsActivity extends AppCompatActivity {\n 73 | \n 74 | @Override\n 75 | protected void onCreate(@Nullable Bundle savedInstanceState) {\n 76 | super.onCreate(savedInstanceState);\n 77 | setContentView(R.layout.activity_listings);\n 78 | \n 79 | int myColor = ContextCompat.getColor(this, R.color.code_content_background);\n 80 | \n 81 | CodeView codeView = (CodeView) findViewById(R.id.code_view);\n 82 | \n 83 | // use chaining to build view\n 84 | codeView.highlightCode(\"js\")\n 85 | .setColorTheme(ColorTheme.SOLARIZED_LIGHT.withBgContent(myColor))\n 86 | .setCodeContent(getString(R.string.listing_js));\n 87 | \n 88 | // do not use chaining for built view\n 89 | // (you can, but follow it should be performed sequentially)\n 90 | codeView.setCodeContent(getString(R.string.listing_java));\n 91 | codeView.highlightCode("java");\n 92 | }\n 93 | } 94 | 95 | 96 | 97 | from timeit import Timer\n 98 | \n 99 | tmp = \"Python 3.2.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32.\"\n 100 | \n 101 | def case1(): # A. Incremental concatenations in cycle\n 102 | s = \"\"\n 103 | for i in range(10000):\n 104 | s += tmp\n 105 | \n 106 | def case2(): # Б. temporary list and join\n 107 | s = []\n 108 | for i in range(10000):\n 109 | s.append(tmp)\n 110 | s = \"\".join(s)\n 111 | \n 112 | def case3(): # C. list expression and join\n 113 | return \"\".join([tmp for i in range(10000)])\n 114 | \n 115 | def case4(): # D. generator expression join\n 116 | return \"\".join(tmp for i in range(10000))\n 117 | \n 118 | for v in range(1,5):\n 119 | print (Timer(\"func()\",\"from __main__ import case%s as func\" % v).timeit(200))\n 120 | 121 | 122 | 123 | return \"\".join([tmp for i in range(10000)]) 124 | 125 | 126 | 127 | for i in range(100500): 128 | 129 | 130 | 131 | -------------------------------------------------------------------------------- /example/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbiakov/CodeView-Android/91ec9008effbfc1e82335ad568f177043eb9881a/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Jan 17 15:59:44 MSK 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':example', ':codeview' 2 | --------------------------------------------------------------------------------