├── .gitignore ├── icon.png ├── Images ├── Colorful-Comments.png └── Logo │ ├── Colorful_Comments(1).jpeg │ ├── Colorful_Comments(2).jpeg │ ├── Colorful_Comments(3).jpeg │ ├── Colorful_Comments(4).jpeg │ ├── Colorful_Comments(5).jpeg │ ├── Colorful_Comments(6).png │ ├── Colorful_Comments(7).png │ ├── Colorful_Comments(8).png │ └── Colorful_Comments(9).png ├── .vscodeignore ├── src ├── test │ ├── samples │ │ ├── Not Tested │ │ │ ├── plantuml.pu │ │ │ ├── asciidoc.adoc │ │ │ ├── plaintext.txt │ │ │ ├── stylus.styl │ │ │ ├── puppet.pp │ │ │ ├── matlab.m │ │ │ ├── cfc.cfc │ │ │ ├── coldfusion.cfm │ │ │ ├── d.d │ │ │ ├── fortran.f03 │ │ │ ├── elixer.ex │ │ │ ├── terraform.hcl │ │ │ ├── twig.twig │ │ │ ├── apex.cls │ │ │ ├── bibreference.bib │ │ │ ├── sas.sas │ │ │ ├── hive.q │ │ │ ├── gdscript.gd │ │ │ ├── haskell.hs │ │ │ ├── genstat.gen │ │ │ ├── stata.do │ │ │ ├── pascal.pas │ │ │ ├── elm.elm │ │ │ ├── tcl.tcl │ │ │ ├── pig.pig │ │ │ ├── verilog.v │ │ │ ├── dart.dart │ │ │ ├── vuejs.vue │ │ │ ├── modernpascal.pp │ │ │ ├── AL.al │ │ │ ├── racket.rkt │ │ │ ├── nim.nim │ │ │ └── lisp.lisp │ │ ├── scss.scss │ │ ├── jsonc.jsonc │ │ ├── css.css │ │ ├── lua.lua │ │ ├── markdown.md │ │ ├── groovy.groovy │ │ ├── php.php │ │ ├── yaml.yaml │ │ ├── javascript.js │ │ ├── powershell.ps1 │ │ ├── html.html │ │ ├── typescriptreact.tsx │ │ ├── Unsupported │ │ │ └── cobol.cbl │ │ ├── nested.cs │ │ ├── test.py │ │ ├── typescript.ts │ │ └── clojure.clj │ └── index.ts ├── Built-In Test │ ├── suite │ │ ├── extension.test.ts │ │ └── index.ts │ └── runTest.ts ├── extension.ts └── parser.ts ├── .vscode ├── extensions.json ├── tasks.json ├── settings.json └── launch.json ├── tsconfig.json ├── CHANGELOG.md ├── .eslintrc.json ├── LICENSE.md ├── Readme.md └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | out 2 | node_modules 3 | .vscode-test/ 4 | *.vsix 5 | -------------------------------------------------------------------------------- /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Parth2031/Colorful-Comments/HEAD/icon.png -------------------------------------------------------------------------------- /Images/Colorful-Comments.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Parth2031/Colorful-Comments/HEAD/Images/Colorful-Comments.png -------------------------------------------------------------------------------- /Images/Logo/Colorful_Comments(1).jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Parth2031/Colorful-Comments/HEAD/Images/Logo/Colorful_Comments(1).jpeg -------------------------------------------------------------------------------- /Images/Logo/Colorful_Comments(2).jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Parth2031/Colorful-Comments/HEAD/Images/Logo/Colorful_Comments(2).jpeg -------------------------------------------------------------------------------- /Images/Logo/Colorful_Comments(3).jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Parth2031/Colorful-Comments/HEAD/Images/Logo/Colorful_Comments(3).jpeg -------------------------------------------------------------------------------- /Images/Logo/Colorful_Comments(4).jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Parth2031/Colorful-Comments/HEAD/Images/Logo/Colorful_Comments(4).jpeg -------------------------------------------------------------------------------- /Images/Logo/Colorful_Comments(5).jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Parth2031/Colorful-Comments/HEAD/Images/Logo/Colorful_Comments(5).jpeg -------------------------------------------------------------------------------- /Images/Logo/Colorful_Comments(6).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Parth2031/Colorful-Comments/HEAD/Images/Logo/Colorful_Comments(6).png -------------------------------------------------------------------------------- /Images/Logo/Colorful_Comments(7).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Parth2031/Colorful-Comments/HEAD/Images/Logo/Colorful_Comments(7).png -------------------------------------------------------------------------------- /Images/Logo/Colorful_Comments(8).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Parth2031/Colorful-Comments/HEAD/Images/Logo/Colorful_Comments(8).png -------------------------------------------------------------------------------- /Images/Logo/Colorful_Comments(9).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Parth2031/Colorful-Comments/HEAD/Images/Logo/Colorful_Comments(9).png -------------------------------------------------------------------------------- /.vscodeignore: -------------------------------------------------------------------------------- 1 | .vscode/** 2 | .vscode-test/** 3 | out/test/** 4 | src/** 5 | .gitignore 6 | **/tsconfig.json 7 | **/.eslintrc.json 8 | **/*.map 9 | # **/*.ts 10 | -------------------------------------------------------------------------------- /src/test/samples/Not Tested/plantuml.pu: -------------------------------------------------------------------------------- 1 | 2 | @startuml 3 | ' This is a comment on a single line 4 | Bob->Alice : hello 5 | ' ! You quote alors use slash-and-quote 6 | ' * hello world 7 | @enduml -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See http://go.microsoft.com/fwlink/?LinkId=827846 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "dbaeumer.vscode-eslint" 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /src/test/samples/Not Tested/asciidoc.adoc: -------------------------------------------------------------------------------- 1 | 2 | This is asciidoc 3 | = This does something 4 | 5 | // ! comment 6 | 7 | //// 8 | 9 | Block comment 10 | ! hello world 11 | * this is a comment 12 | 13 | //// -------------------------------------------------------------------------------- /src/test/samples/Not Tested/plaintext.txt: -------------------------------------------------------------------------------- 1 | 2 | Hello world 3 | this is some plain text 4 | and here is a comment of my own design 5 | 6 | ! My Comment 7 | ? Comment 8 | ^ Not Important 9 | 10 | This is some more text -------------------------------------------------------------------------------- /src/test/samples/scss.scss: -------------------------------------------------------------------------------- 1 | 2 | .topClass 3 | { 4 | height: 100px; 5 | width: 100px; 6 | 7 | /* 8 | ! Hello World 9 | ^ Comment 10 | */ 11 | 12 | // * This class is nested 13 | 14 | .innerClass { 15 | color: pink; 16 | } 17 | } -------------------------------------------------------------------------------- /src/test/samples/jsonc.jsonc: -------------------------------------------------------------------------------- 1 | { 2 | // ^ This is a comment in JSONC 3 | // ! This one is Colorful 4 | "item1": 1, 5 | "item2": { 6 | "child": "" 7 | } 8 | 9 | /* 10 | * Some Comments 11 | & Nice Comments 12 | ~ Thank you 13 | */ 14 | } -------------------------------------------------------------------------------- /src/test/samples/Not Tested/stylus.styl: -------------------------------------------------------------------------------- 1 | 2 | .topClass 3 | { 4 | height: 100px; 5 | width: 100px; 6 | 7 | /* 8 | ! Hello World 9 | ^ Comment 10 | */ 11 | 12 | // * This class is nested 13 | 14 | .innerClass { 15 | color: pink; 16 | } 17 | } -------------------------------------------------------------------------------- /src/test/samples/css.css: -------------------------------------------------------------------------------- 1 | 2 | .myclass 3 | { 4 | /* 5 | ! This is a comment 6 | ? Hi, what's up 7 | * Nice Colour 8 | & Colorful 9 | ~ Testing 10 | TODO Important 11 | */ 12 | 13 | /* ^ Hello */ 14 | 15 | height: 100px; 16 | width: 100px; 17 | } -------------------------------------------------------------------------------- /src/test/samples/lua.lua: -------------------------------------------------------------------------------- 1 | 2 | function entry0 (o) 3 | N=N + 1 4 | local title = o.title or '(no title)' 5 | fwrite('
  • %s\n', N, title) 6 | end 7 | -- ! Some Comments 8 | 9 | --[[ 10 | ? Hello World 11 | ^ More Comments 12 | ~ Extra logic 13 | --]] -------------------------------------------------------------------------------- /src/test/samples/Not Tested/puppet.pp: -------------------------------------------------------------------------------- 1 | 2 | # This is a simple smoke test 3 | # of the file_line resource type. 4 | # ! alert 5 | # ? question 6 | file { '/tmp/dansfile': 7 | ensure => file, 8 | } 9 | -> file_line { 'dans_line': 10 | line => 'dan is awesome', 11 | path => '/tmp/dansfile', 12 | } 13 | -------------------------------------------------------------------------------- /src/test/samples/markdown.md: -------------------------------------------------------------------------------- 1 | ### Some Markdown 2 | ## Some other header 3 | 4 | * bullet point 5 | * bullet point 2 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/test/samples/Not Tested/matlab.m: -------------------------------------------------------------------------------- 1 | 2 | function output = my_fun(input) 3 | % 4 | % description. 5 | % 6 | % @since 1.0.0 7 | % @param {type} [name] description. 8 | % @return {type} [name] description. 9 | % @see dependencies 10 | % 11 | 12 | 13 | for index = 1 : n 14 | 15 | end 16 | 17 | end 18 | -------------------------------------------------------------------------------- /src/test/samples/Not Tested/cfc.cfc: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | No, it didn't 7 | 8 | 9 | 10 | No, it didn't 11 | 12 | 13 | 14 | No, it didn't 15 | -------------------------------------------------------------------------------- /src/test/samples/Not Tested/coldfusion.cfm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | No, it didn't 7 | 8 | 9 | 10 | No, it didn't 11 | 12 | 13 | 14 | No, it didn't 15 | -------------------------------------------------------------------------------- /src/test/samples/Not Tested/d.d: -------------------------------------------------------------------------------- 1 | 2 | //version(none) // ! this is the original version line 3 | version(all) // ? the code is now enabled 4 | void brokenFunc() { 5 | 6 | /* 7 | ! Comment freely here 8 | */ 9 | 10 | int x=123; 11 | int y=321; /+ to your heart's content +/ 12 | } 13 | 14 | void workingFunc() { 15 | 16 | } -------------------------------------------------------------------------------- /src/test/samples/Not Tested/fortran.f03: -------------------------------------------------------------------------------- 1 | 2 | program circle 3 | real r, area 4 | 5 | c ! This program reads a real number r and prints 6 | c * the area of a circle with radius r. 7 | 8 | write (*,*) 'Give radius r:' 9 | read (*,*) r 10 | area = 3.14159*r*r 11 | write (*,*) 'Area = ', area 12 | 13 | stop 14 | end -------------------------------------------------------------------------------- /src/test/samples/groovy.groovy: -------------------------------------------------------------------------------- 1 | 2 | class Example 3 | { 4 | static void main(String[] args) 5 | { 6 | // ! Hello World 7 | // * Another Comment 8 | // ? and Another 9 | One can see the use of a semi-colon after each statement 10 | def x = 5; 11 | println('Hello World'); 12 | } 13 | } 14 | 15 | /* 16 | ^ Block Comments are the Same 17 | */ -------------------------------------------------------------------------------- /src/test/samples/Not Tested/elixer.ex: -------------------------------------------------------------------------------- 1 | 2 | @moduledoc """" 3 | Some description 4 | ! ALERT 5 | """ 6 | 7 | ["T", "e", "s", "t"] = String.graphemes("Test") 8 | 9 | # Contrast this with codepoints which may return 10 | # multiple codepoints for a single character 11 | # ! alert 12 | # ? question 13 | # ^ 14 | ["ö"] = String.graphemes("ö") 15 | ["o", "̈"] = String.codepoints("ö") -------------------------------------------------------------------------------- /src/test/samples/Not Tested/terraform.hcl: -------------------------------------------------------------------------------- 1 | 2 | # ! An AMI 3 | variable "ami" { 4 | description = "the AMI to use" 5 | } 6 | 7 | /** 8 | * A multi 9 | * ? line comment 10 | */ 11 | resource "aws_instance" "web" { 12 | ami = "${var.ami}" 13 | count = 2 14 | source_dest_check = false 15 | 16 | connection { 17 | user = "root" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/test/samples/php.php: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/test/samples/Not Tested/twig.twig: -------------------------------------------------------------------------------- 1 | 2 | {% if cons.inConsGroup(1) %} 3 | Thank you for your volunteer efforts thus far! 4 | {% else %} 5 | According to our records associated with this email address, you haven't volunteered. 6 | {% endif %} 7 | {% if cons.inConsGroup(2) %} 8 | Please setup a recurring gift today: 9 | {% endif %} 10 | 11 | {# 12 | ! This is a comment 13 | #} -------------------------------------------------------------------------------- /src/test/samples/yaml.yaml: -------------------------------------------------------------------------------- 1 | 2 | # ^ Comments 3 | # & Colorful Comments 4 | # ~ Attractive 5 | 6 | # ! Employee records 7 | 8 | - martin: 9 | name: Martin D'vloper 10 | job: Developer 11 | skills: 12 | - python 13 | - perl 14 | - pascal 15 | - tabitha: 16 | name: Tabitha Bitumen 17 | job: Developer 18 | skills: 19 | - lisp 20 | - fortran 21 | - erlang -------------------------------------------------------------------------------- /src/test/samples/Not Tested/apex.cls: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Some comments 4 | * ! alert 5 | */ 6 | 7 | public class SelectableAsset 8 | { 9 | // * note 10 | public Asset asset {get; set;} 11 | 12 | public Boolean selected {get; set;} 13 | 14 | public SelectableAsset(Asset ast) 15 | { 16 | asset = ast; 17 | 18 | // ^ add more 19 | selected = false; 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /src/test/samples/javascript.js: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | ? My Class 4 | ! Creating some Copyright Notes 5 | */ 6 | 7 | /* 8 | & My Function 9 | ! Some Alert 10 | ^ Some stuff 11 | ? Questions 12 | * Highlights 13 | ~ Arrow Function 14 | TODO Colorful 15 | */ 16 | 17 | var myFunction = function(myParam) { 18 | return myParam; 19 | // ^ Tested all Cases 20 | } 21 | 22 | //// removed code 23 | 24 | // * End of the file 25 | 26 | -------------------------------------------------------------------------------- /src/test/samples/powershell.ps1: -------------------------------------------------------------------------------- 1 | 2 | # Convert any text file to ASCII 3 | 4 | param( [string] $infile = $(throw "Please specify a filename.") ) 5 | 6 | $outfile = "$infile.ascii" 7 | 8 | get-content -path $infile | out-file $outfile -encoding ascii 9 | 10 | # ! Comment here 11 | # ? Another comment 12 | # ^ Some other comment 13 | # * Highlighted comment 14 | 15 | <# 16 | & Hello world 17 | ~ Hello world 18 | // Hello world 19 | #> -------------------------------------------------------------------------------- /src/test/samples/Not Tested/bibreference.bib: -------------------------------------------------------------------------------- 1 | 2 | % This is a Bibtex MWE 3 | % ? Question 4 | % ! Warning 5 | % ^ Task 6 | % * Comment 7 | % //deprecated 8 | % * Bibtex style 9 | @misc{ RefKey1, 10 | author = "Bruce Banner", 11 | title = "Anger management", 12 | year = "2001" 13 | } 14 | % * Biber style 15 | @misc{ RefKey2, 16 | author = {Tony Stark}, 17 | title = {Introduction to Engineering}, 18 | year = {2006} 19 | } -------------------------------------------------------------------------------- /src/test/samples/Not Tested/sas.sas: -------------------------------------------------------------------------------- 1 | 2 | * ! This is a comment; 3 | /* ? Also this is too */ 4 | 5 | DATA CLASS; 6 | INPUT NAME $ 1-8 SEX $ 10 AGE 12-13 HEIGHT 15-16 WEIGHT 18-22; 7 | CARDS; 8 | JOHN M 12 59 99.5 9 | JAMES M 12 57 83.0 10 | ALFRED M 14 69 112.5 11 | ALICE F 13 56 84.0 12 | 13 | PROC MEANS; 14 | VAR AGE HEIGHT WEIGHT; 15 | PROC PLOT; 16 | PLOT WEIGHT*HEIGHT; 17 | ENDSAS; 18 | ; -------------------------------------------------------------------------------- /src/test/samples/Not Tested/hive.q: -------------------------------------------------------------------------------- 1 | 2 | DROP TABLE IF EXISTS docs; 3 | 4 | -- ! this is a comment 5 | CREATE TABLE docs (line STRING); 6 | 7 | -- * some highlighted comment 8 | LOAD DATA INPATH 'input_file' OVERWRITE INTO TABLE docs; 9 | 10 | -- ^ create schema 11 | CREATE TABLE word_counts AS 12 | 13 | SELECT word, count(1) AS count FROM 14 | 15 | (SELECT explode(split(line, '\s')) AS word FROM docs) temp 16 | 17 | GROUP BY word 18 | 19 | ORDER BY word; -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | // See https://go.microsoft.com/fwlink/?LinkId=733558 2 | // for the documentation about the tasks.json format 3 | { 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "type": "npm", 8 | "script": "watch", 9 | "problemMatcher": "$tsc-watch", 10 | "isBackground": true, 11 | "presentation": { 12 | "reveal": "never" 13 | }, 14 | "group": { 15 | "kind": "build", 16 | "isDefault": true 17 | } 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "strict": true, 4 | "alwaysStrict": true, 5 | "module": "commonjs", 6 | "target": "es6", 7 | "outDir": "out", 8 | "noImplicitAny": true, 9 | "noImplicitReturns": true, 10 | "lib": [ 11 | "es6" 12 | ], 13 | "sourceMap": true, 14 | "strictNullChecks": true, 15 | "rootDir": "src", 16 | "noUnusedLocals": true 17 | }, 18 | "exclude": [ 19 | "src/test*", 20 | "node_modules", 21 | ".vscode-test" 22 | ] 23 | } -------------------------------------------------------------------------------- /src/test/samples/Not Tested/gdscript.gd: -------------------------------------------------------------------------------- 1 | 2 | extends StaticBody2D 3 | 4 | # ! class member variables go here 5 | var a = 2 6 | var b = "textvar" 7 | 8 | func _ready(): 9 | # * Called when the node is added to the scene for the first time. 10 | # ? is this loop necessary? 11 | for i in range(20): 12 | print(i) 13 | 14 | func _process(delta): 15 | # ^ Add logic 16 | # Called every frame. Delta is time since last frame. 17 | # Update game logic here. 18 | pass 19 | 20 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | // Place your settings in this file to overwrite default and user settings. 2 | { 3 | "files.exclude": { 4 | "out": false, // set this to true to hide the "out" folder with the compiled JS files 5 | "npm-debug.log": true 6 | }, 7 | "search.exclude": { 8 | "out": true // set this to false to include "out" folder in search results 9 | }, 10 | // Turn off tsc task auto detection since we have the necessary tasks as npm scripts 11 | "typescript.tsc.autoDetect": "off" 12 | } -------------------------------------------------------------------------------- /src/test/samples/Not Tested/haskell.hs: -------------------------------------------------------------------------------- 1 | 2 | {-# LANGUAGE OverloadedStrings #-} 3 | {-# LANGUAGE TypeFamilies #-} 4 | {-# LANGUAGE QuasiQuotes #-} 5 | {-# LANGUAGE TemplateHaskell #-} 6 | {-# LANGUAGE MultiParamTypeClasses #-} 7 | 8 | import Yesod 9 | 10 | data WebApp = WebApp 11 | 12 | instance Yesod WebApp 13 | 14 | mkYesod "WebApp" [parseRoutes| 15 | / HomeR GET 16 | |] 17 | 18 | getHomeR = defaultLayout [whamlet| 19 |
    Hello, world! 20 | |] 21 | 22 | main = warpEnv WebApp 23 | 24 | -- ! hello world 25 | {- 26 | ! hello world 27 | -} -------------------------------------------------------------------------------- /src/Built-In Test/suite/extension.test.ts: -------------------------------------------------------------------------------- 1 | import * as assert from 'assert'; 2 | 3 | // You can import and use all API from the 'vscode' module 4 | // as well as import your extension to test it 5 | import * as vscode from 'vscode'; 6 | // import * as myExtension from '../../extension'; 7 | 8 | suite('Extension Test Suite', () => 9 | { 10 | vscode.window.showInformationMessage('Start all tests.'); 11 | 12 | test('Sample test', () => { 13 | assert.equal(-1, [1, 2, 3].indexOf(5)); 14 | assert.equal(-1, [1, 2, 3].indexOf(0)); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /src/test/samples/html.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |
    8 |

    TEST

    9 |
    10 | 11 | 19 |
    20 | Some content can go here 21 |
    22 | 23 | 24 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## [0.6.2] 4 | * Added Brightscript and XML Support but without samples experimented. 5 | 6 | ## [0.5.2] 7 | * Needed to re-publish my extension due to technical glitch so pls support so, it starts from 0.5.2 but has updated part of 0.5.0 8 | 9 | ## [0.4.0] 10 | * Added New Logo and Updated Package.json 11 | 12 | ## [0.3.0] 13 | * Added Images and also tested some new languages adding them to Readme.md 14 | 15 | ## [0.2.0] 16 | ### Features 17 | * Updated Readme.md to show all necessary information and changed some colors in Package.json -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "parser": "@typescript-eslint/parser", 4 | "parserOptions": { 5 | "ecmaVersion": 6, 6 | "sourceType": "module" 7 | }, 8 | "plugins": [ 9 | "@typescript-eslint" 10 | ], 11 | "rules": { 12 | "no-string-throw": true, 13 | "no-unused-expression": true, 14 | "no-duplicate-variable": true, 15 | "curly": [ 16 | true, 17 | "ignore-same-line" 18 | ], 19 | "class-name": true, 20 | "semicolon": [ 21 | true, 22 | "always" 23 | ], 24 | "triple-equals": true 25 | }, 26 | "defaultSeverity": "warning" 27 | } 28 | -------------------------------------------------------------------------------- /src/test/samples/Not Tested/genstat.gen: -------------------------------------------------------------------------------- 1 | 2 | print 0 3 | \ Line comment only at the start of a line 4 | \ Line comment only at the start of a line 5 | \ ! Line comment only at the start of a line 6 | \ * Line comment only at the start of a line 7 | print 2 " Block comment at the end of a line " 8 | print 3 " Block comment at the end of a line 9 | ! testing 10 | possibly continuing to the next line 11 | " 12 | print 4 13 | "============================================================================= 14 | Long block comment 15 | ==============================================================================" 16 | print 5 17 | " Another block comment" 18 | print 6 -------------------------------------------------------------------------------- /src/test/samples/Not Tested/stata.do: -------------------------------------------------------------------------------- 1 | 2 | * ! Stata do-file carsdata.do written January 2009 3 | * ? Create a text log file that stores the results 4 | log using carsdata.txt, text replace 5 | * Read in the Stata data set carsdata.dta 6 | use carsdata.dta 7 | * Describe the variables in the data set 8 | describe 9 | * List the dataset 10 | list 11 | * ^ Provide summary statistics of the variables in the data set 12 | summarize 13 | * Provide an X,Y scatterplot with a regression line 14 | twoway (scatter cars hhsize) (lfit cars hhsize) 15 | * Save the preceding graph in a file in PNG (portable networks graphic) format 16 | graph export carsdata.png 17 | * Regress cars on hhsize 18 | regress cars hhsize -------------------------------------------------------------------------------- /src/test/samples/Not Tested/pascal.pas: -------------------------------------------------------------------------------- 1 | 2 | {$mode objfpc}{$H+}{$J-} 3 | unit AnotherUnit; 4 | interface 5 | 6 | uses Classes; 7 | 8 | { The "TComponent" type (class) is defined in the Classes unit. 9 | That's why we had to use the Classes unit above. } 10 | procedure DoSomethingWithComponent(var C: TComponent); 11 | 12 | implementation 13 | 14 | // ! hello world 15 | uses SysUtils; 16 | 17 | procedure DoSomethingWithComponent(var C: TComponent); 18 | begin 19 | { The FreeAndNil procedure is defined in the SysUtils unit. 20 | Since we only refer to it's name in the implementation, 21 | it was OK to use the SysUtils unit in the "implementation" section. } 22 | FreeAndNil(C); 23 | end; 24 | 25 | end. -------------------------------------------------------------------------------- /src/test/samples/Not Tested/elm.elm: -------------------------------------------------------------------------------- 1 | 2 | --!(no space) 3 | -- ! (space) 4 | -- ! tab then tab 5 | -- ! tab then space 6 | import Html exposing (..) 7 | 8 | --! user status 9 | type UserStatus = Regular | Visitor 10 | 11 | {- 12 | ! type alias User 13 | * type alias User 14 | ? type alias User 15 | ^ typ alias Book 16 | -} 17 | type alias User = 18 | { 19 | firstName : String 20 | , lastName : String 21 | , age : Int 22 | , status : UserStatus 23 | } 24 | 25 | tom = {firstName = "tom", lastName = "john", age = 34, status = Visitor } 26 | 27 | main = 28 | text "Hello world!" 29 | 30 | {- 31 | ^ tab ^ 32 | !double tab 33 | ?triple tab 34 | *quadruple tab 35 | -} -------------------------------------------------------------------------------- /src/test/samples/Not Tested/tcl.tcl: -------------------------------------------------------------------------------- 1 | 2 | #!/usr/bin/tclsh 3 | 4 | # ! switch_cmd.tcl 5 | 6 | set domain x 7 | switch $domain { 8 | 9 | x { puts "x" } 10 | y { puts "y" } 11 | z { puts "z" } 12 | default { puts "unknown" } 13 | } 14 | 15 | proc power {base p} { 16 | set result 1 17 | while {$p > 0} { 18 | set result [expr $result * $base] 19 | set p [expr $p - 1] 20 | } 21 | return $result 22 | } 23 | 24 | set a 10 25 | set b 20 26 | 27 | if {$a == 10} { 28 | 29 | # ? if expression_1 is true then it will go to expression_2 30 | if {$b == 20} { 31 | # * if expression_2 is true then it will print the below string 32 | puts "value of a is 10 and b is 20" 33 | } 34 | } 35 | 36 | o/p: value of a is 10 and b is 20 -------------------------------------------------------------------------------- /src/Built-In Test/runTest.ts: -------------------------------------------------------------------------------- 1 | import * as path from 'path'; 2 | 3 | import { runTests } from 'vscode-test'; 4 | 5 | async function main() 6 | { 7 | try 8 | { 9 | // The folder containing the Extension Manifest package.json 10 | // Passed to `--extensionDevelopmentPath` 11 | const extensionDevelopmentPath = path.resolve(__dirname, '../../'); 12 | 13 | // The path to test runner 14 | // Passed to --extensionTestsPath 15 | const extensionTestsPath = path.resolve(__dirname, './suite/index'); 16 | 17 | // Download VS Code, unzip it and run the integration test 18 | await runTests({ extensionDevelopmentPath, extensionTestsPath }); 19 | } 20 | catch (err) 21 | { 22 | console.error('Failed to run tests'); 23 | process.exit(1); 24 | } 25 | } 26 | 27 | main(); 28 | -------------------------------------------------------------------------------- /src/test/samples/Not Tested/pig.pig: -------------------------------------------------------------------------------- 1 | 2 | input_lines = LOAD '/tmp/my-copy-of-all-pages-on-internet' AS (line:chararray); 3 | 4 | -- * Extract words from each line and put them into a pig bag 5 | -- ? datatype, then flatten the bag to get one word on each row 6 | words = FOREACH input_lines GENERATE FLATTEN(TOKENIZE(line)) AS word; 7 | 8 | -- ^ filter out any words that are just white spaces 9 | filtered_words = FILTER words BY word MATCHES '\\w+'; 10 | 11 | -- ! create a group for each word 12 | word_groups = GROUP filtered_words BY word; 13 | 14 | -- count the entries in each group 15 | word_count = FOREACH word_groups GENERATE COUNT(filtered_words) AS count, group AS word; 16 | 17 | -- order the records by count 18 | ordered_word_count = ORDER word_count BY count DESC; 19 | STORE ordered_word_count INTO '/tmp/number-of-words-on-internet'; -------------------------------------------------------------------------------- /src/test/samples/Not Tested/verilog.v: -------------------------------------------------------------------------------- 1 | 2 | /********************************************************************** 3 | * Date: Aug. 15, 2006 4 | * File: Mux_2_to_1b.v (440 Examples) 5 | * ! ALERT 6 | * ? question 7 | * ^ Some ^ 8 | * Behavioral Model of a 2 to 1 MUX (16-bit inputs) 9 | **********************************************************************/ 10 | 11 | // ******************************************************** 12 | module mux_2to1(Y, A, B, sel); 13 | // ******************************************************** 14 | // ! alert 15 | // ? question 16 | // ^ Some ^ 17 | //// Commented out code 18 | 19 | output [15:0] Y; 20 | input [15:0] A, B; 21 | input sel; 22 | reg [15:0] Y; 23 | always @(A or B or sel) 24 | if (sel == 1'b0) 25 | Y = A; 26 | else 27 | Y = B; 28 | endmodule -------------------------------------------------------------------------------- /src/test/samples/typescriptreact.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import * as ReactDOM from 'react-dom'; 3 | 4 | import Hello from './containers/Hello'; 5 | import { Provider } from 'react-redux'; 6 | import { createStore } from 'redux'; 7 | import { enthusiasm } from './reducers/index'; 8 | import { StoreState } from './types/index'; 9 | 10 | import './index.css'; 11 | 12 | /** 13 | * ^ Some comments here 14 | * ! to alert 15 | * * to highlight 16 | * ? to question 17 | */ 18 | 19 | /* 20 | ~ and the other format 21 | */ 22 | 23 | // & finally 24 | // ! Single line Comments 25 | 26 | const store = createStore(enthusiasm, 27 | { 28 | enthusiasmLevel: 1, 29 | languageName: 'TypeScript', 30 | }); 31 | 32 | ReactDOM.render( 33 | 34 | 35 | , 36 | document.getElementById('root') as HTMLElement 37 | ); -------------------------------------------------------------------------------- /src/Built-In Test/suite/index.ts: -------------------------------------------------------------------------------- 1 | import * as path from 'path'; 2 | import * as Mocha from 'mocha'; 3 | import * as glob from 'glob'; 4 | 5 | export function run(): Promise 6 | { 7 | // Create the mocha test 8 | 9 | const mocha = new Mocha({ 10 | ui: 'tdd', 11 | color: true 12 | }); 13 | 14 | const testsRoot = path.resolve(__dirname, '..'); 15 | 16 | return new Promise((c, e) => { 17 | glob('**/**.test.js', { cwd: testsRoot }, (err, files) => { 18 | if (err) { 19 | return e(err); 20 | } 21 | 22 | // Add files to the test suite 23 | files.forEach(f => mocha.addFile(path.resolve(testsRoot, f))); 24 | 25 | try { 26 | // Run the mocha test 27 | mocha.run(failures => { 28 | if (failures > 0) { 29 | e(new Error(`${failures} tests failed.`)); 30 | } else { 31 | c(); 32 | } 33 | }); 34 | } catch (err) { 35 | console.error(err); 36 | e(err); 37 | } 38 | }); 39 | }); 40 | } 41 | -------------------------------------------------------------------------------- /src/test/samples/Not Tested/dart.dart: -------------------------------------------------------------------------------- 1 | 2 | class Spacecraft { 3 | String name; 4 | DateTime launchDate; 5 | 6 | // ! Constructor, with syntactic sugar for assignment to members. 7 | Spacecraft(this.name, this.launchDate) { 8 | // Initialization code goes here. 9 | } 10 | 11 | // * Named constructor that forwards to the default one. 12 | Spacecraft.unlaunched(String name) : this(name, null); 13 | 14 | int get launchYear => 15 | launchDate?.year; // read-only non-final property 16 | 17 | /* 18 | Block comment 19 | ! alert 20 | * info 21 | ? question 22 | ^ do some stuff 23 | */ 24 | 25 | // ? Method. 26 | void describe() { 27 | print('Spacecraft: $name'); 28 | if (launchDate != null) { 29 | int years = new DateTime.now() 30 | .difference(launchDate) 31 | .inDays ~/ 32 | 365; 33 | print('Launched: $launchYear ($years years ago)'); 34 | } else { 35 | print('Unlaunched'); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | Copyright (c) 2020 Parth Rastogi 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 5 | 6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 9 | -------------------------------------------------------------------------------- /src/test/index.ts: -------------------------------------------------------------------------------- 1 | // 2 | // PLEASE DO NOT MODIFY / DELETE UNLESS YOU KNOW WHAT YOU ARE DOING 3 | // 4 | // This file is providing the test runner to use when running extension tests. 5 | // By default the test runner in use is Mocha based. 6 | // 7 | // You can provide your own test runner if you want to override it by exporting 8 | // a function run(testRoot: string, clb: (error:Error) => void) that the extension 9 | // host can call to run the tests. The test runner is expected to use console.log 10 | // to report the results back to the caller. When the tests are finished, return 11 | // a possible error to the callback or null if none. 12 | 13 | var testRunner = require('vscode/lib/testrunner'); 14 | 15 | // You can directly control Mocha options by uncommenting the following lines 16 | // See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info 17 | testRunner.configure({ 18 | ui: 'tdd', // the TDD UI is being used in extension.test.ts (suite, test, etc.) 19 | useColors: true // colorful output from test results 20 | }); 21 | 22 | module.exports = testRunner; -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | // A launch configuration that compiles the extension and then opens it inside a new window 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | { 6 | "version": "0.2.0", 7 | "configurations": [ 8 | { 9 | "name": "Run Extension", 10 | "type": "extensionHost", 11 | "request": "launch", 12 | "runtimeExecutable": "${execPath}", 13 | "args": [ "--extensionDevelopmentPath=${workspaceFolder}"], 14 | "outFiles": [ "${workspaceFolder}/out/**/*.js"], 15 | "stopOnEntry": false, 16 | "sourceMaps": true, 17 | "preLaunchTask": "${defaultBuildTask}" 18 | }, 19 | { 20 | "name": "Extension Tests", 21 | "type": "extensionHost", 22 | "request": "launch", 23 | "runtimeExecutable": "${execPath}", 24 | "args": [ "--extensionDevelopmentPath=${workspaceFolder}", "--extensionTestsPath=${workspaceFolder}/out/test/suite/index"], 25 | "outFiles": [ "${workspaceFolder}/out/test/**/*.js" ], 26 | "stopOnEntry": false, 27 | "sourceMaps": true, 28 | "preLaunchTask": "${defaultBuildTask}" 29 | } 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /src/test/samples/Not Tested/vuejs.vue: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /src/extension.ts: -------------------------------------------------------------------------------- 1 | import * as vscode from 'vscode'; 2 | import { Parser } from './parser'; 3 | 4 | export function activate(context: vscode.ExtensionContext) 5 | { 6 | let activeEditor: vscode.TextEditor | undefined; 7 | let parser: Parser = new Parser(); 8 | 9 | let updateDecorations = function (useHash = false) 10 | { 11 | if (!activeEditor) return; 12 | 13 | if (!parser.supportedLanguage) return; 14 | 15 | parser.FindSingleLineComments(activeEditor); 16 | parser.FindBlockComments(activeEditor); 17 | parser.FindJSDocComments(activeEditor); 18 | parser.ApplyDecorations(activeEditor); 19 | }; 20 | 21 | if (vscode.window.activeTextEditor) 22 | { 23 | activeEditor = vscode.window.activeTextEditor; 24 | 25 | parser.SetRegex(activeEditor.document.languageId); 26 | 27 | triggerUpdateDecorations(); 28 | } 29 | 30 | vscode.window.onDidChangeActiveTextEditor( (editor) => 31 | { 32 | activeEditor = editor; 33 | 34 | if (editor) 35 | { 36 | parser.SetRegex(editor.document.languageId); 37 | 38 | triggerUpdateDecorations(); 39 | } 40 | }, null, context.subscriptions); 41 | 42 | vscode.workspace.onDidChangeTextDocument( event => 43 | { 44 | if (activeEditor && event.document === activeEditor.document) { 45 | triggerUpdateDecorations(); 46 | } 47 | }, null, context.subscriptions); 48 | 49 | var timeout: NodeJS.Timer; 50 | 51 | function triggerUpdateDecorations() 52 | { 53 | if (timeout) { 54 | clearTimeout(timeout); 55 | } 56 | 57 | timeout = setTimeout(updateDecorations, 200); 58 | } 59 | } 60 | 61 | export function deactivate() { } -------------------------------------------------------------------------------- /src/test/samples/Unsupported/cobol.cbl: -------------------------------------------------------------------------------- 1 | $ SET SOURCEFORMAT"FREE" 2 | IDENTIFICATION DIVISION. 3 | PROGRAM-ID. PerformFormat3. 4 | AUTHOR. Michael Coughlan. 5 | * Demonstrates the use of the PERFORM..UNTIL. 6 | * The PERFORM..UNTIL is most often used to process a 7 | * stream of data where the length of the stream can not 8 | * be determined in advance. 9 | * Pay particular attention to the way the number stream is 10 | * processed in this program. 11 | * Note how the ON SIZE ERROR can be used to detect when the 12 | * result of a computation is tot big for the data-item intended 13 | * to hold it. 14 | * The INITIALIZE verb sets a data-item to its initial or 15 | * starting value. 16 | *> ^ Check if this format is correct 17 | DATA DIVISION. 18 | WORKING-STORAGE SECTION. 19 | 01 IterCount PIC 99 VALUE ZEROS. 20 | 88 MaxCountReached VALUE 99. 21 | 01 UserInput PIC 99 VALUE ZEROS. 22 | 88 EndOfUserInput VALUE ZEROS. 23 | 01 RunningTotal PIC 999 VALUE ZEROS. 24 | 01 AverageValue PIC 99 VALUES ZEROS. 25 | 26 | PROCEDURE DIVISION. 27 | Begin. 28 | PERFORM UNTIL IterCount = 5 29 | DISPLAY "IterCount = " IterCount 30 | ADD 1 TO IterCount 31 | END-PERFORM 32 | DISPLAY "Finished in line Perform." *> ! comment here 33 | 34 | INITIALIZE Itercount 35 | 36 | DISPLAY "Enter a stream of up to 99 numbers." 37 | DISPLAY "Each number must be in the range 1-99. Enter 0 to stop." 38 | DISPLAY "Enter number :- " WITH NO ADVANCING 39 | ACCEPT UserInput 40 | PERFORM GetUserInput UNTIL EndOfUserInput OR MaxCountReached 41 | 42 | DISPLAY "The final total is - " RunningTotal 43 | DISPLAY "The final count is - " IterCount 44 | COMPUTE AverageValue = RunningTotal / IterCount 45 | DISPLAY "The average value entered is - " AverageValue 46 | STOP RUN. 47 | 48 | 49 | GetUserInput. 50 | ADD UserInput TO RunningTotal 51 | ON SIZE ERROR DISPLAY "Error - new total too large for data-item." 52 | NOT ON SIZE ERROR ADD 1 TO IterCount END-ADD 53 | END-ADD 54 | DISPLAY "Total so far is - " RunningTotal 55 | DISPLAY "Count so far is - " IterCount 56 | DISPLAY "Enter number :- " WITH NO ADVANCING 57 | ACCEPT UserInput. 58 | 59 | -------------------------------------------------------------------------------- /src/test/samples/Not Tested/modernpascal.pp: -------------------------------------------------------------------------------- 1 | 2 | program class_Example; 3 | 4 | // ! hello 5 | Uses 6 | strings; 7 | 8 | Type 9 | HookRec=Record 10 | Name:String; 11 | Value:TStringArray; 12 | End; 13 | TSlim=Class 14 | Version:String; 15 | Container:String; 16 | Apps:TStringArray; 17 | Name:String; 18 | Middleware:String; 19 | Error:String; 20 | notFound:String; 21 | hooks:Array [0..5] of HookRec; 22 | Mem:Pointer; 23 | MemSize:Longint; 24 | End; 25 | TNotSoSlim=Class(TSlim) 26 | AnotherVar:String; 27 | End; 28 | TSomeOther=Class 29 | Happy:Boolean; 30 | Name:String; 31 | End; 32 | 33 | procedure TSlim.Free; 34 | begin 35 | with Self do begin 36 | FreeMem(Mem, MemSize); 37 | Writeln('Free: ',MemSize); 38 | End; 39 | end; 40 | 41 | procedure TSlim.Init; // constructor does not need to be published. 42 | begin 43 | with Self do begin 44 | MemSize:=2048; 45 | GetMem(Mem,MemSize); 46 | Container:='none'; 47 | Version:='2.6.1p'; 48 | hooks:=[ ['slim.before',[]], 49 | ['slim.before.router',[]], 50 | ['slim.before.dispatch',[]], 51 | ['slim.after.dispatch',[]], 52 | ['slim.after.router',[]], 53 | ['slim.after',[]] ]; 54 | TMethod(@Free):=[@TSlim.Free, @Self]; 55 | end; 56 | end; 57 | 58 | procedure TNotSoSlim.Free; override; 59 | Begin 60 | inherited; 61 | Writeln('AnotherVar layer: ',AnotherVar); 62 | end; 63 | 64 | procedure TNotSoSlim.Init; override; 65 | begin 66 | inherited; 67 | TMethod(@Free):=[@TNotSoSlim.Free, @Self]; 68 | end; 69 | 70 | procedure TSomeOther.Free; 71 | begin 72 | // nada 73 | end; 74 | 75 | procedure TSomeOther.Init; 76 | begin 77 | Self.Happy:=True; 78 | TMethod(@Free):=[@TSomeOther.Free, @Self]; 79 | end; 80 | 81 | var 82 | inst:TSlim; 83 | inst2:TSlim; 84 | inst3:TNotSoSlim; 85 | inst4:TSomeOther; 86 | 87 | begin 88 | Writeln('Testing...',1,2,3,' ',4); 89 | inst.Init; 90 | inst2.Init; 91 | inst3.Init; 92 | inst4.Init; 93 | inst3.AnotherVar:="Cool!"; 94 | inst2.Version:='3.0'; 95 | Writeln('v',inst.Version); 96 | Writeln('v',inst2.Version); 97 | Writeln('v',inst3.Version); 98 | Writeln('cont:',inst.Container); 99 | Writeln('a:',inst3.AnotherVar); 100 | Writeln('h:',inst4.Happy); 101 | inst.Free; 102 | inst2.Free; 103 | inst3.Free; 104 | inst4.Free; 105 | end. -------------------------------------------------------------------------------- /src/test/samples/Not Tested/AL.al: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------------------------------------------ 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the MIT License. See License.txt in the project root for license information. 4 | // ------------------------------------------------------------------------------------------------ 5 | 6 | // ! Codeunit for creating random greetings 7 | codeunit 50110 GreetingsManagement 8 | { 9 | // ? Get a translated 'Hello World' string. 10 | // * Thanks to https://www.bing.com/translator/ 11 | local procedure GetHelloWorldText(GreetingNo : Integer) : Text; 12 | begin 13 | case GreetingNo of 14 | 1: exit('Arabic: مرحبا بالعالم'); 15 | 2: exit('Bulgarian: Здравей, свят'); 16 | 3: exit('Cantonese: 世界你好'); 17 | 4: exit('Greek: Γεια σου κόσμε'); 18 | 5: exit('Korean: 전 세계 여러분 안녕하세요'); 19 | 6: exit('Thai: หวัดดีชาวโลก'); 20 | 7: exit('Hindi: हैलो वर्ल्ड'); 21 | 8: exit('Japanese: ハローワールド'); 22 | 9: exit('Danish: Hej verden'); 23 | 10: exit('Polish: Witaj świecie'); 24 | 11: exit('Pig Latin: Ellohay Orldway'); 25 | 12: exit('Hungarian: Szia, világ!'); 26 | 13: exit('Flemish: Hej wereld'); 27 | 14: exit('Dutch: Hallo wereld'); 28 | 15: exit('French: Bonjour le monde'); 29 | 16: exit('Finnish: Hei maailma'); 30 | 17: exit('Russian: Привет, мир!'); 31 | 18: exit('Czech: Ahoj světe'); 32 | 19: exit('German: Hallo Welt'); 33 | 20: exit('Lithuanian: Labas, pasauli!'); 34 | 21: exit('Afrikaans: Hallo wêreld'); 35 | 22: exit('Bakke Snavvendt: Wello Horld'); 36 | 23: exit('1337 : h3ll0 w0rld!'); 37 | 24: exit('|_337: |-|3|_|_0 \\/\\/0|2|_|)!'); 38 | 25: exit('Morse code: ...././.-../.-../---//.--/---/.-./.-../-../-.-.--////'); 39 | 26: exit('Ballon script: Ⓗⓔⓛⓛⓞ Ⓦⓞⓡⓛⓓ!'); 40 | 27: exit('Braille: ⠠⠓⠑⠇⠇⠕ ⠠⠺⠕⠗⠇⠙⠖'); 41 | 28: exit('Español: Hola Mundo!'); 42 | 29: exit('Albanian: Përshëndetje, Botë!'); 43 | 30: exit('Turkish: Merhaba Dünya!'); 44 | 31: exit('Tamil: வணக்கம்'); 45 | 32: exit('Sinhalese: ආයුබෝවන්'); 46 | 33: exit('Swahili: Salamu, Dunia'); 47 | 34: exit('Catalan: Hola món'); 48 | 35: exit('Icelandic: Halló heimur'); 49 | 36: exit('Gaeilge: Dia duit an domhan'); 50 | else 51 | exit('Hello, World'); // Default to the good old one. 52 | end; 53 | end; 54 | 55 | // Gets a random greeting. 56 | procedure GetRandomGreeting() : Text; 57 | begin 58 | Randomize; 59 | exit(GetHelloWorldText(Random(37))); 60 | end; 61 | 62 | /* 63 | ! hello world 64 | */ 65 | 66 | /** 67 | * ! hello world 68 | */ 69 | } -------------------------------------------------------------------------------- /src/test/samples/Not Tested/racket.rkt: -------------------------------------------------------------------------------- 1 | 2 | #lang racket 3 | 4 | ;; ! Functions for 2d drawing and transformation 5 | 6 | (require lang/posn) 7 | 8 | (struct pos (x y) #:transparent) 9 | 10 | (define (move-pos a-pos a-direction a-speed) 11 | (define r (degrees->radians a-direction)) 12 | (pos (+ (pos-x a-pos) (* a-speed (cos r))) 13 | (+ (pos-y a-pos) (* a-speed (sin r))))) 14 | 15 | (define (add-direction-speeds d1 s1 d2 s2) 16 | ;; Given two direction & speed pairs, calculate the 17 | ;; combined effect and return new direction and speed 18 | (if (and (zero? s1) (zero? s2)) 19 | (list d1 0) 20 | (let* ([vec1 (move-pos (pos 0 0) d1 s1)] 21 | [vec2 (move-pos (pos 0 0) d2 s2)] 22 | [c-vec (pos (+ (pos-x vec1) (pos-x vec2)) 23 | (+ (pos-y vec1) (pos-y vec2)))] 24 | [direction (radians->degrees 25 | (atan (pos-y c-vec) 26 | (pos-x c-vec)))] 27 | [speed (sqrt (+ (sqr (pos-x c-vec)) 28 | (sqr (pos-y c-vec))))]) 29 | (list direction speed)))) 30 | 31 | (define (pos->posn points) 32 | (map (λ (p) (make-posn (pos-x p) (pos-y p))) 33 | points)) 34 | 35 | ;; ^ ----------------------------------------------------------- 36 | 37 | (define (inside-circle? circle-pos radius a-pos) 38 | (define distance 39 | (sqrt (+ (expt (- (pos-x a-pos) (pos-x circle-pos)) 2) 40 | (expt (- (pos-y a-pos) (pos-y circle-pos)) 2)))) 41 | (<= distance radius)) 42 | 43 | (define (between? a x y) 44 | "Is a between x and y?" 45 | (or (<= x a y) 46 | (>= x a y))) 47 | 48 | (define (inside-rect? rpos1 rpos2 a-pos) 49 | "Is a-pos inside the rectangle defined by corners rpos1 and 2?" 50 | (and (between? (pos-x a-pos) (pos-x rpos1) (pos-x rpos2)) 51 | (between? (pos-y a-pos) (pos-y rpos1) (pos-y rpos2)))) 52 | 53 | (define (direction-from-a-to-b pos1 pos2) 54 | "What's the direction/bearing from pos1 to pos2?" 55 | (let ([vector (pos (- (pos-x pos2) (pos-x pos1)) 56 | (- (pos-y pos2) (pos-y pos1)))]) 57 | (radians->degrees 58 | (atan (pos-y vector) (pos-x vector))))) 59 | 60 | (define (inside-triangle? points a-pos) 61 | "Is a-pos inside this triangle defined by the 3 points?" 62 | (let* ([angle1-2 (direction-from-a-to-b (first points) (second points))] 63 | [angle1-3 (direction-from-a-to-b (first points) (third points))] 64 | [angle1-a (direction-from-a-to-b (first points) a-pos)] 65 | [angle2-1 (direction-from-a-to-b (second points) (first points))] 66 | [angle2-3 (direction-from-a-to-b (second points) (third points))] 67 | [angle2-a (direction-from-a-to-b (second points) a-pos)]) 68 | (and (between? angle1-a angle1-2 angle1-3) 69 | (between? angle2-a angle2-1 angle2-3)))) 70 | 71 | ;; ----------------------------------------------------------- 72 | 73 | (provide pos pos-x pos-y pos->posn 74 | move-pos add-direction-speeds 75 | between? inside-circle? inside-rect? inside-triangle? 76 | direction-from-a-to-b) -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # Colorful Comments 2 | 3 | The Colorful Comments Extension will help you create more human-friendly comments in your code. 4 | With this Extension, you will be able to categorise your cody by special colour into: 5 | * Red (!) 6 | * Blue (?) 7 | * Green (*) 8 | * Yellow (^) 9 | * Pink (&) 10 | * Purple (~) 11 | * Mustard (todo) 12 | * Grey (//) 13 | * Commented out Code can also be Styled to make it Clear the Code shouldn't be There. 14 | * Any Other Comment Styles you'd like can be Specified in the Settings. 15 | 16 | ![](Images/Colorful-Comments.png) 17 | 18 | ## Configurations 19 | 20 | This extension can be configured in User Settings or Workspace settings. 21 | 22 | 23 | `"colorful-comments.multilineComments": true` 24 | This setting will control whether multiline comments are styled using the annotation tags. 25 | When false, multiline comments will be presented without decoration. 26 | 27 | `"colorful-comments.highlightPlainText": false` 28 | This setting will control whether comments in a plain text file are styled using the annotation tags. 29 | When true, the tags (defaults: `! * ? // ~ & ^`) will be detected if they're the first character on a line. 30 | 31 | `colorful-comments.tags` 32 | The tags are the characters or sequences used to mark a comment for decoration. 33 | The default 7 can be modifed to change the colors, and more can be added. 34 | 35 | ```json 36 | "colorful-comments.tags": [ 37 | { 38 | "tag": "!", 39 | "color": "#FF2D00", 40 | "strikethrough": false, 41 | "backgroundColor": "transparent", 42 | "bold": false, 43 | "italic": false 44 | }, 45 | { 46 | "tag": "?", 47 | "color": "#0076FF", 48 | "strikethrough": false, 49 | "backgroundColor": "transparent", 50 | "bold": false, 51 | "italic": false 52 | }, 53 | { 54 | "tag": "//", 55 | "color": "#474747", 56 | "strikethrough": true, 57 | "backgroundColor": "transparent", 58 | "bold": false, 59 | "italic": false 60 | }, 61 | { 62 | "tag": "^", 63 | "color": "#EAF622", 64 | "strikethrough": false, 65 | "backgroundColor": "transparent", 66 | "bold": false, 67 | "italic": false 68 | }, 69 | { 70 | "tag": "*", 71 | "color": "#28FF00", 72 | "strikethrough": false, 73 | "backgroundColor": "transparent", 74 | "bold": false, 75 | "italic": false 76 | }, 77 | { 78 | "tag": "&", 79 | "color": "#FF06A0", 80 | "strikethrough": false, 81 | "backgroundColor": "transparent", 82 | "bold": false, 83 | "italic": false 84 | }, 85 | { 86 | "tag": "~", 87 | "color": "#BE00FF", 88 | "strikethrough": false, 89 | "backgroundColor": "transparent", 90 | "bold": false, 91 | "italic": false 92 | }, 93 | { 94 | "tag": "todo", 95 | "color": "#FF8C00", 96 | "strikethrough": false, 97 | "backgroundColor": "transparent", 98 | "bold": false, 99 | "italic": false 100 | } 101 | ] 102 | ``` 103 | 104 | ## Supported Languages 105 | 106 | * BrightScript 107 | * C 108 | * C# 109 | * C++ 110 | * Clojure 111 | * CSS 112 | * Dart 113 | * Dockerfile 114 | * Groovy 115 | * HTML 116 | * Java 117 | * Javascript 118 | * JavaScript React 119 | * JSON with comments 120 | * Less 121 | * Lua 122 | * Markdown 123 | * Objective-C 124 | * Objective-C++ 125 | * PHP 126 | * PowerShell 127 | * Python 128 | * Sass 129 | * SCSS 130 | * TypeScript 131 | * TypeScript React 132 | * XML 133 | * YAML 134 | 135 | 214 | -------------------------------------------------------------------------------- /src/test/samples/Not Tested/nim.nim: -------------------------------------------------------------------------------- 1 | 2 | # 3 | # 4 | # The Nim Compiler 5 | # (c) Copyright 2015 Andreas Rumpf 6 | # 7 | # See the file "copying.txt", included in this 8 | # distribution, for details about the copyright. 9 | # 10 | 11 | # * adding some sample comments for better-comments 12 | when defined(gcc) and defined(windows): 13 | when defined(x86): 14 | {.link: "icons/nim.res".} 15 | else: 16 | {.link: "icons/nim_icon.o".} 17 | 18 | #[ 19 | ? question 20 | block comment 21 | ]# 22 | 23 | when defined(amd64) and defined(windows) and defined(vcc): 24 | {.link: "icons/nim-amd64-windows-vcc.res".} 25 | when defined(i386) and defined(windows) and defined(vcc): 26 | {.link: "icons/nim-i386-windows-vcc.res".} 27 | 28 | import 29 | commands, lexer, condsyms, options, msgs, nversion, nimconf, ropes, 30 | extccomp, strutils, os, osproc, platform, main, parseopt, service, 31 | nodejs, scriptconfig, idents, modulegraphs 32 | 33 | # ? adding some sample comments for better-comments 34 | when hasTinyCBackend: 35 | import tccgen 36 | 37 | when defined(profiler) or defined(memProfiler): 38 | {.hint: "Profiling support is turned on!".} 39 | import nimprof 40 | 41 | proc prependCurDir(f: string): string = 42 | when defined(unix): 43 | if os.isAbsolute(f): result = f 44 | else: result = "./" & f 45 | else: 46 | result = f 47 | 48 | # ! adding some sample comments for better-comments 49 | proc handleCmdLine(cache: IdentCache; config: ConfigRef) = 50 | if paramCount() == 0: 51 | writeCommandLineUsage() 52 | else: 53 | # Process command line arguments: 54 | processCmdLine(passCmd1, "") 55 | if gProjectName == "-": 56 | gProjectName = "stdinfile" 57 | gProjectFull = "stdinfile" 58 | gProjectPath = canonicalizePath getCurrentDir() 59 | gProjectIsStdin = true 60 | elif gProjectName != "": 61 | try: 62 | gProjectFull = canonicalizePath(gProjectName) 63 | except OSError: 64 | gProjectFull = gProjectName 65 | let p = splitFile(gProjectFull) 66 | let dir = if p.dir.len > 0: p.dir else: getCurrentDir() 67 | gProjectPath = canonicalizePath dir 68 | gProjectName = p.name 69 | else: 70 | gProjectPath = canonicalizePath getCurrentDir() 71 | loadConfigs(DefaultConfig, config) # load all config files 72 | let scriptFile = gProjectFull.changeFileExt("nims") 73 | if fileExists(scriptFile): 74 | runNimScript(cache, scriptFile, freshDefines=false, config) 75 | # 'nim foo.nims' means to just run the NimScript file and do nothing more: 76 | if scriptFile == gProjectFull: return 77 | elif fileExists(gProjectPath / "config.nims"): 78 | # directory wide NimScript file 79 | runNimScript(cache, gProjectPath / "config.nims", freshDefines=false, config) 80 | # now process command line arguments again, because some options in the 81 | # command line can overwite the config file's settings 82 | extccomp.initVars() 83 | processCmdLine(passCmd2, "") 84 | if options.command == "": 85 | rawMessage(errNoCommand, command) 86 | mainCommand(newModuleGraph(config), cache) 87 | if optHints in gOptions and hintGCStats in gNotes: echo(GC_getStatistics()) 88 | #echo(GC_getStatistics()) 89 | if msgs.gErrorCounter == 0: 90 | when hasTinyCBackend: 91 | if gCmd == cmdRun: 92 | tccgen.run(commands.arguments) 93 | if optRun in gGlobalOptions: 94 | if gCmd == cmdCompileToJS: 95 | var ex: string 96 | if options.outFile.len > 0: 97 | ex = options.outFile.prependCurDir.quoteShell 98 | else: 99 | ex = quoteShell( 100 | completeCFilePath(changeFileExt(gProjectFull, "js").prependCurDir)) 101 | execExternalProgram(findNodeJs() & " " & ex & ' ' & commands.arguments) 102 | elif gCmd == cmdCompileToPHP: 103 | var ex: string 104 | if options.outFile.len > 0: 105 | ex = options.outFile.prependCurDir.quoteShell 106 | else: 107 | ex = quoteShell( 108 | completeCFilePath(changeFileExt(gProjectFull, "php").prependCurDir)) 109 | execExternalProgram("php " & ex & ' ' & commands.arguments) 110 | else: 111 | var binPath: string 112 | if options.outFile.len > 0: 113 | # If the user specified an outFile path, use that directly. 114 | binPath = options.outFile.prependCurDir 115 | else: 116 | # Figure out ourselves a valid binary name. 117 | binPath = changeFileExt(gProjectFull, ExeExt).prependCurDir 118 | var ex = quoteShell(binPath) 119 | execExternalProgram(ex & ' ' & commands.arguments) 120 | 121 | # ^ adding some sample comments for better-comments 122 | when declared(GC_setMaxPause): 123 | GC_setMaxPause 2_000 124 | 125 | when compileOption("gc", "v2") or compileOption("gc", "refc"): 126 | # the new correct mark&sweet collector is too slow :-/ 127 | GC_disableMarkAndSweep() 128 | condsyms.initDefines() 129 | 130 | # // adding some sample comments for better-comments 131 | when not defined(selftest): 132 | handleCmdLine(newIdentCache(), newConfigRef()) 133 | when declared(GC_setMaxPause): 134 | echo GC_getStatistics() 135 | msgQuit(int8(msgs.gErrorCounter > 0)) 136 | -------------------------------------------------------------------------------- /src/test/samples/nested.cs: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | This is my class 4 | 5 | ! This class is not for public use 6 | ^ Create some copyright notices 7 | * Highlight to draw attention 8 | ? Maybe I should indent less 9 | & More logic should be added 10 | ~ Impressive time management 11 | */ 12 | 13 | public class MyClass 14 | { 15 | // ! backing member for the public property 16 | private short myProperty = 0; 17 | 18 | // * Available for public use 19 | public short MyProperty 20 | { 21 | // ^ add some better comments 22 | get { return this.myProperty; } 23 | 24 | // ? should this value be transformed first? 25 | set { this.myProperty = value; } 26 | 27 | } 28 | 29 | public constructor() 30 | { 31 | this.MyProperty = 1; 32 | } 33 | 34 | public void DoSomeStuff(string myParameter) 35 | { 36 | 37 | } 38 | 39 | private boolean doSomePrivateStuff() 40 | { 41 | 42 | } 43 | } 44 | 45 | /* 46 | This is my class 47 | ! This class is not for public use 48 | ^ Create some copyright notices 49 | * Highlight to draw attention 50 | ? Maybe I should indent less 51 | */ 52 | public class MyClass 53 | { 54 | // ! backing member for the public property 55 | private short myProperty = 0; 56 | 57 | // * Available for public use 58 | public short MyProperty 59 | { 60 | // ^ add some better comments 61 | get { return this.myProperty; } 62 | 63 | // ? should this value be transformed first? 64 | set { this.myProperty = value; } 65 | 66 | } 67 | 68 | public constructor() 69 | { 70 | this.MyProperty = 1; 71 | } 72 | 73 | public void DoSomeStuff(string myParameter) 74 | { 75 | 76 | } 77 | 78 | private boolean doSomePrivateStuff() 79 | { 80 | 81 | } 82 | } 83 | 84 | /* 85 | This is my class 86 | ! This class is not for public use 87 | ^ Create some copyright notices 88 | * Highlight to draw attention 89 | ? Maybe I should indent less 90 | */ 91 | public class MyClass 92 | { 93 | // ! backing member for the public property 94 | private short myProperty = 0; 95 | 96 | // * Available for public use 97 | public short MyProperty 98 | { 99 | // ^ add some better comments 100 | get { return this.myProperty; } 101 | 102 | // ? should this value be transformed first? 103 | set { this.myProperty = value; } 104 | 105 | } 106 | 107 | public constructor() 108 | { 109 | this.MyProperty = 1; 110 | } 111 | 112 | public void DoSomeStuff(string myParameter) 113 | { 114 | 115 | } 116 | 117 | private boolean doSomePrivateStuff() 118 | { 119 | 120 | } 121 | } 122 | 123 | /* 124 | This is my class 125 | ! This class is not for public use 126 | ^ Create some copyright notices 127 | * Highlight to draw attention 128 | ? Maybe I should indent less 129 | */ 130 | public class MyClass 131 | { 132 | // ! backing member for the public property 133 | private short myProperty = 0; 134 | 135 | // * Available for public use 136 | public short MyProperty 137 | { 138 | // ^ add some better comments 139 | get { return this.myProperty; } 140 | 141 | // ? should this value be transformed first? 142 | set { this.myProperty = value; } 143 | 144 | } 145 | 146 | public constructor() 147 | { 148 | this.MyProperty = 1; 149 | } 150 | 151 | public void DoSomeStuff(string myParameter) 152 | { 153 | 154 | } 155 | 156 | private boolean doSomePrivateStuff() 157 | { 158 | 159 | } 160 | } 161 | 162 | /* 163 | This is my class 164 | ! This class is not for public use 165 | ^ Create some copyright notices 166 | * Highlight to draw attention 167 | ? Maybe I should indent less 168 | */ 169 | public class MyClass 170 | { 171 | // ! backing member for the public property 172 | private short myProperty = 0; 173 | 174 | // * Available for public use 175 | public short MyProperty 176 | { 177 | // ^ add some better comments 178 | get { return this.myProperty; } 179 | 180 | // ? should this value be transformed first? 181 | set { this.myProperty = value; } 182 | 183 | } 184 | 185 | public constructor() 186 | { 187 | this.MyProperty = 1; 188 | } 189 | 190 | public void DoSomeStuff(string myParameter) 191 | { 192 | 193 | } 194 | 195 | private boolean doSomePrivateStuff() 196 | { 197 | 198 | } 199 | } 200 | 201 | /* 202 | This is my class 203 | ! This class is not for public use 204 | ^ Create some copyright notices 205 | * Highlight to draw attention 206 | ? Maybe I should indent less 207 | */ 208 | public class MyClass 209 | { 210 | // ! backing member for the public property 211 | private short myProperty = 0; 212 | 213 | // * Available for public use 214 | public short MyProperty 215 | { 216 | // ^ add some better comments 217 | get { return this.myProperty; } 218 | 219 | // ? should this value be transformed first? 220 | set { this.myProperty = value; } 221 | 222 | } 223 | 224 | public constructor() 225 | { 226 | this.MyProperty = 1; 227 | } 228 | 229 | public void DoSomeStuff(string myParameter) 230 | { 231 | 232 | } 233 | 234 | private boolean doSomePrivateStuff() 235 | { 236 | 237 | } 238 | } -------------------------------------------------------------------------------- /src/test/samples/test.py: -------------------------------------------------------------------------------- 1 | 2 | #!/usr/bin/env python3 3 | 4 | """ 5 | TODO my_method does a thing. There are many like it, but this one is mine. 6 | ? Do we really need this? 7 | ! Deprecated 8 | ^ Comments 9 | * Important 10 | & Another Comment 11 | ~ my_param Do some stuff with this 12 | """ 13 | 14 | # ! Import the modules 15 | import sys 16 | import random 17 | 18 | # * var to set up loop 19 | myVar = True 20 | 21 | # ? Will this loop ever terminate? 22 | while myVar: 23 | 24 | # ^ localise the output 25 | question = raw_input("Ask the magic 8 ball a question: (press enter to quit) ") 26 | 27 | answers = random.randint(1,8) 28 | 29 | if question == "": 30 | sys.exit() 31 | 32 | elif answers == 1: 33 | print "It is certain" 34 | 35 | elif answers == 2: 36 | print "Outlook good" 37 | 38 | elif answers == 3: 39 | print "You may rely on it" 40 | 41 | elif answers == 4: 42 | print "Ask again later" 43 | 44 | elif answers == 5: 45 | print "Concentrate and ask again" 46 | 47 | elif answers == 6: 48 | print "Reply hazy, try again" 49 | 50 | elif answers == 7: 51 | print "My reply is no" 52 | 53 | elif answers == 8: 54 | print "My sources say no" 55 | 56 | 57 | # ! Import the modules 58 | import sys 59 | import random 60 | 61 | # * var to set up loop 62 | myVar = True 63 | 64 | # ? will this loop ever terminate? 65 | while myVar: 66 | 67 | # ^ localise the output 68 | question = raw_input("Ask the magic 8 ball a question: (press enter to quit) ") 69 | 70 | answers = random.randint(1,8) 71 | 72 | if question == "": 73 | sys.exit() 74 | 75 | elif answers == 1: 76 | print "It is certain" 77 | 78 | elif answers == 2: 79 | print "Outlook good" 80 | 81 | elif answers == 3: 82 | print "You may rely on it" 83 | 84 | elif answers == 4: 85 | print "Ask again later" 86 | 87 | elif answers == 5: 88 | print "Concentrate and ask again" 89 | 90 | elif answers == 6: 91 | print "Reply hazy, try again" 92 | 93 | elif answers == 7: 94 | print "My reply is no" 95 | 96 | elif answers == 8: 97 | print "My sources say no" 98 | 99 | # ! Import the modules 100 | import sys 101 | import random 102 | 103 | # * var to set up loop 104 | myVar = True 105 | 106 | # ? will this loop ever terminate? 107 | while myVar: 108 | 109 | # ^ localise the output 110 | question = raw_input("Ask the magic 8 ball a question: (press enter to quit) ") 111 | 112 | answers = random.randint(1,8) 113 | 114 | if question == "": 115 | sys.exit() 116 | 117 | elif answers == 1: 118 | print "It is certain" 119 | 120 | elif answers == 2: 121 | print "Outlook good" 122 | 123 | elif answers == 3: 124 | print "You may rely on it" 125 | 126 | elif answers == 4: 127 | print "Ask again later" 128 | 129 | elif answers == 5: 130 | print "Concentrate and ask again" 131 | 132 | elif answers == 6: 133 | print "Reply hazy, try again" 134 | 135 | elif answers == 7: 136 | print "My reply is no" 137 | 138 | elif answers == 8: 139 | print "My sources say no" 140 | 141 | # ! Import the modules 142 | import sys 143 | import random 144 | 145 | # * var to set up loop 146 | myVar = True 147 | 148 | # ? will this loop ever terminate? 149 | while myVar: 150 | 151 | # ^ localise the output 152 | question = raw_input("Ask the magic 8 ball a question: (press enter to quit) ") 153 | 154 | answers = random.randint(1,8) 155 | 156 | if question == "": 157 | sys.exit() 158 | 159 | elif answers == 1: 160 | print "It is certain" 161 | 162 | elif answers == 2: 163 | print "Outlook good" 164 | 165 | elif answers == 3: 166 | print "You may rely on it" 167 | 168 | elif answers == 4: 169 | print "Ask again later" 170 | 171 | elif answers == 5: 172 | print "Concentrate and ask again" 173 | 174 | elif answers == 6: 175 | print "Reply hazy, try again" 176 | 177 | elif answers == 7: 178 | print "My reply is no" 179 | 180 | elif answers == 8: 181 | print "My sources say no" 182 | 183 | # ! Import the modules 184 | import sys 185 | import random 186 | 187 | # * var to set up loop 188 | myVar = True 189 | 190 | # ? will this loop ever terminate? 191 | while myVar: 192 | 193 | # ^ localise the output 194 | question = raw_input("Ask the magic 8 ball a question: (press enter to quit) ") 195 | 196 | answers = random.randint(1,8) 197 | 198 | if question == "": 199 | sys.exit() 200 | 201 | elif answers == 1: 202 | print "It is certain" 203 | 204 | elif answers == 2: 205 | print "Outlook good" 206 | 207 | elif answers == 3: 208 | print "You may rely on it" 209 | 210 | elif answers == 4: 211 | print "Ask again later" 212 | 213 | elif answers == 5: 214 | print "Concentrate and ask again" 215 | 216 | elif answers == 6: 217 | print "Reply hazy, try again" 218 | 219 | elif answers == 7: 220 | print "My reply is no" 221 | 222 | elif answers == 8: 223 | print "My sources say no" -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "colorful-comments", 3 | "displayName": "Colorful Comments", 4 | "icon": "icon.png", 5 | "description": "Improve and Enhance your code and make it attractive by adding Colorful Comments", 6 | "version": "0.6.4", 7 | "publisher": "ParthR2031", 8 | "author": { 9 | "name": "Parth Rastogi" 10 | }, 11 | "homepage": "https://github.com/Parth2031/Colorful-Comments/master/README.md", 12 | "license": "SEE LICENSE IN LICENSE.md", 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/Parth2031/Colorful-Comments" 16 | }, 17 | "bugs": "https://github.com/Parth2031/Colorful-Comments/issues", 18 | "engines": { 19 | "vscode": "^1.68.0" 20 | }, 21 | "categories": [ 22 | "Formatters" 23 | ], 24 | "extensionKind": [ 25 | "ui", 26 | "workspace" 27 | ], 28 | "activationEvents": [ 29 | "onLanguage:ada", 30 | "onLanguage:al", 31 | "onLanguage:apex", 32 | "onLanguage:asciidoc", 33 | "onLanguage:bibtex", 34 | "onLanguage: brightscript", 35 | "onLanguage:c", 36 | "onLanguage:clojure", 37 | "onLanguage:cfml", 38 | "onLanguage:COBOL", 39 | "onLanguage:coffeescript", 40 | "onLanguage:cpp", 41 | "onLanguage:csharp", 42 | "onLanguage:css", 43 | "onLanguage:d", 44 | "onLanguage:dart", 45 | "onLanguage:diagram", 46 | "onLanguage:dockerfile", 47 | "onLanguage:elixir", 48 | "onLanguage:elm", 49 | "onLanguage:erlang", 50 | "onLanguage:flax", 51 | "onLanguage:fsharp", 52 | "onLanguage:fortran-modern", 53 | "onLanguage:gdscript", 54 | "onLanguage:genstat", 55 | "onLanguage:go", 56 | "onLanguage:graphql", 57 | "onLanguage:groovy", 58 | "onLanguage:haskell", 59 | "onLanguage:html", 60 | "onLanguage:haxe", 61 | "onLanguage:hive-sql", 62 | "onLanguage:kotlin", 63 | "onLanguage:java", 64 | "onLanguage:javascript", 65 | "onLanguage:javascriptreact", 66 | "onLanguage:jsonc", 67 | "onLanguage:julia", 68 | "onLanguage:latex", 69 | "onLanguage:less", 70 | "onLanguage:lisp", 71 | "onLanguage:lua", 72 | "onLanguage:makefile", 73 | "onLanguage:markdown", 74 | "onLanguage:matlab", 75 | "onLanguage:nim", 76 | "onLanguage:objective-c", 77 | "onLanguage:objective-cpp", 78 | "onLanguage:objectpascal", 79 | "onLanguage:pascal", 80 | "onLanguage:perl", 81 | "onLanguage:perl6", 82 | "onLanguage:pig", 83 | "onLanguage:plaintext", 84 | "onLanguage:plsql", 85 | "onLanguage:php", 86 | "onLanguage:powershell", 87 | "onLanguage:puppet", 88 | "onLanguage:python", 89 | "onLanguage:r", 90 | "onLanguage:racket", 91 | "onLanguage:ruby", 92 | "onLanguage:rust", 93 | "onLanguage:scala", 94 | "onLanguage:sas", 95 | "onLanguage:sass", 96 | "onLanguage:scss", 97 | "onLanguage:shaderlab", 98 | "onLanguage:shellscript", 99 | "onLanguage:sql", 100 | "onLanguage:stata", 101 | "onLanguage:stylus", 102 | "onLanguage:swift", 103 | "onLanguage:tcl", 104 | "onLanguage:terraform", 105 | "onLanguage:twig", 106 | "onLanguage:typescript", 107 | "onLanguage:typescriptreact", 108 | "onLanguage:vb", 109 | "onLanguage:verilog", 110 | "onLanguage:vue", 111 | "onLanguage:xml", 112 | "onLanguage:yaml" 113 | ], 114 | "galleryBanner": { 115 | "color": "#e3f4ff", 116 | "theme": "light" 117 | }, 118 | "main": "./out/extension.js", 119 | "contributes": { 120 | "configuration": { 121 | "title": "Colorful Comments Configuration", 122 | "properties": { 123 | "colorful-comments.multilineComments": { 124 | "type": "boolean", 125 | "description": "Whether the multiline comment highlighter should be active", 126 | "default": true 127 | }, 128 | "colorful-comments.highlightPlainText": { 129 | "type": "boolean", 130 | "description": "Whether the plaintext comment highlighter should be active", 131 | "default": false 132 | }, 133 | "colorful-comments.tags": { 134 | "type": "array", 135 | "description": "Tags which are used to color the comments. Changes require a restart of VS Code to take effect", 136 | "default": [ 137 | { 138 | "tag": "!", 139 | "color": "#FF2D00", 140 | "strikethrough": false, 141 | "backgroundColor": "transparent" 142 | }, 143 | { 144 | "tag": "?", 145 | "color": "#0076FF", 146 | "strikethrough": false, 147 | "backgroundColor": "transparent" 148 | }, 149 | { 150 | "tag": "//", 151 | "color": "#474747", 152 | "strikethrough": true, 153 | "backgroundColor": "transparent" 154 | }, 155 | { 156 | "tag": "^", 157 | "color": "#EAF622", 158 | "strikethrough": false, 159 | "backgroundColor": "transparent" 160 | }, 161 | { 162 | "tag": "*", 163 | "color": "#28FF00", 164 | "strikethrough": false, 165 | "backgroundColor": "transparent" 166 | }, 167 | { 168 | "tag": "&", 169 | "color": "#FF06A0", 170 | "strikethrough": false, 171 | "backgroundColor": "transparent" 172 | }, 173 | { 174 | "tag": "~", 175 | "color": "#BE00FF", 176 | "strikethrough": false, 177 | "backgroundColor": "transparent" 178 | }, 179 | { 180 | "tag": "todo", 181 | "color": "#FF8C00", 182 | "strikethrough": false, 183 | "backgroundColor": "transparent" 184 | } 185 | ] 186 | } 187 | } 188 | } 189 | }, 190 | "scripts": { 191 | "vscode:prepublish": "npm run compile", 192 | "compile": "tsc -p ./", 193 | "lint": "eslint src --ext ts", 194 | "watch": "tsc -watch -p ./", 195 | "pretest": "npm run compile && npm run lint", 196 | "test": "node ./out/test/runTest.js" 197 | }, 198 | "devDependencies": { 199 | "@types/glob": "^7.1.3", 200 | "@types/mocha": "^8.0.3", 201 | "@types/node": "^14.14.0", 202 | "@types/vscode": "^1.48.0", 203 | "@typescript-eslint/eslint-plugin": "^3.10.1", 204 | "@typescript-eslint/parser": "^3.10.1", 205 | "eslint": "^7.11.0", 206 | "glob": "^7.1.6", 207 | "mocha": "^8.2.0", 208 | "typescript": "^3.8.3", 209 | "vsce": "^1.81.1", 210 | "vscode-test": "^1.4.0" 211 | } 212 | } 213 | -------------------------------------------------------------------------------- /src/test/samples/typescript.ts: -------------------------------------------------------------------------------- 1 | 2 | export class TestClass 3 | { 4 | /** 5 | * Test Method 6 | * ! Colorful 7 | * * Important information is highlighted 8 | * & Deprecated method, do not use 9 | * ? Should this method be exposed through API? 10 | * ^ refactor this method to conform to API 11 | * @param param The parameter for this method 12 | */ 13 | 14 | public TestMethod(param: any): void 15 | { 16 | let testVar: number = 123; 17 | 18 | // ~ This is a pointing out 19 | 20 | if (testVar > 0) { 21 | throw new TypeError(); // ! This is an alert 22 | } 23 | 24 | // ? This is a query 25 | let x = 1; 26 | 27 | //// this.lineOfCode() == commentedOut; 28 | 29 | // ^ write some test cases 30 | } 31 | 32 | //! no spaces 33 | // ~ Space then Tab 34 | // & Tab then Tab 35 | // ^ Tab then space 36 | 37 | // ? 汉字 38 | // * 123 39 | 40 | /* 41 | Test Method 42 | * Important information is highlighted 43 | ! Deprecated method, do not use 44 | ? Should this method be exposed through API? 45 | ^ refactor this method to conform to API 46 | @param param The parameter for this method 47 | */ 48 | } 49 | 50 | export class TestClass { 51 | 52 | /** 53 | * Test Method 54 | * * Important information is highlighted 55 | * ! Deprecated method, do not use 56 | * ? Should this method be exposed through API? 57 | * ^ refactor this method to conform to API 58 | * @param param The parameter for this method 59 | */ 60 | public TestMethod(param: any): void { 61 | let testVar: number = 123; 62 | 63 | // * This is a highlight 64 | if (testVar > 0) { 65 | throw new TypeError(); // ! this is an alert 66 | } 67 | 68 | // ? This is a query 69 | let x = 1; 70 | 71 | //// this.lineOfCode() == commentedOut; 72 | 73 | // ^ write some test cases 74 | } 75 | 76 | //!no spaces 77 | // ! Space then Tab 78 | // ! Tab then Tab 79 | // ! Tab then space 80 | 81 | // ? 汉字 82 | // * 123 83 | 84 | /* 85 | Test Method 86 | * Important information is highlighted 87 | ! Deprecated method, do not use 88 | ? Should this method be exposed through API? 89 | ^ refactor this method to conform to API 90 | @param param The parameter for this method 91 | */ 92 | } 93 | 94 | export class TestClass { 95 | 96 | /** 97 | * Test Method 98 | * * Important information is highlighted 99 | * ! Deprecated method, do not use 100 | * ? Should this method be exposed through API? 101 | * ^ refactor this method to conform to API 102 | * @param param The parameter for this method 103 | */ 104 | public TestMethod(param: any): void { 105 | let testVar: number = 123; 106 | 107 | // * This is a highlight 108 | if (testVar > 0) { 109 | throw new TypeError(); // ! this is an alert 110 | } 111 | 112 | // ? This is a query 113 | let x = 1; 114 | 115 | //// this.lineOfCode() == commentedOut; 116 | 117 | // ^ write some test cases 118 | } 119 | 120 | //!no spaces 121 | // ! Space then Tab 122 | // ! Tab then Tab 123 | // ! Tab then space 124 | 125 | // ? 汉字 126 | // * 123 127 | 128 | /* 129 | Test Method 130 | * Important information is highlighted 131 | ! Deprecated method, do not use 132 | ? Should this method be exposed through API? 133 | ^ refactor this method to conform to API 134 | @param param The parameter for this method 135 | */ 136 | } 137 | 138 | export class TestClass { 139 | 140 | /** 141 | * Test Method 142 | * * Important information is highlighted 143 | * ! Deprecated method, do not use 144 | * ? Should this method be exposed through API? 145 | * ^ refactor this method to conform to API 146 | * @param param The parameter for this method 147 | */ 148 | public TestMethod(param: any): void { 149 | let testVar: number = 123; 150 | 151 | // * This is a highlight 152 | if (testVar > 0) { 153 | throw new TypeError(); // ! this is an alert 154 | } 155 | 156 | // ? This is a query 157 | let x = 1; 158 | 159 | //// this.lineOfCode() == commentedOut; 160 | 161 | // ^ write some test cases 162 | } 163 | 164 | //!no spaces 165 | // ! Space then Tab 166 | // ! Tab then Tab 167 | // ! Tab then space 168 | 169 | // ? 汉字 170 | // * 123 171 | 172 | /* 173 | Test Method 174 | * Important information is highlighted 175 | ! Deprecated method, do not use 176 | ? Should this method be exposed through API? 177 | ^ refactor this method to conform to API 178 | @param param The parameter for this method 179 | */ 180 | } 181 | 182 | export class TestClass { 183 | 184 | /** 185 | * Test Method 186 | * * Important information is highlighted 187 | * ! Deprecated method, do not use 188 | * ? Should this method be exposed through API? 189 | * ^ refactor this method to conform to API 190 | * @param param The parameter for this method 191 | */ 192 | public TestMethod(param: any): void { 193 | let testVar: number = 123; 194 | 195 | // * This is a highlight 196 | if (testVar > 0) { 197 | throw new TypeError(); // ! this is an alert 198 | } 199 | 200 | // ? This is a query 201 | let x = 1; 202 | 203 | //// this.lineOfCode() == commentedOut; 204 | 205 | // ^ write some test cases 206 | } 207 | 208 | //!no spaces 209 | // ! Space then Tab 210 | // ! Tab then Tab 211 | // ! Tab then space 212 | 213 | // ? 汉字 214 | // * 123 215 | 216 | /* 217 | Test Method 218 | * Important information is highlighted 219 | ! Deprecated method, do not use 220 | ? Should this method be exposed through API? 221 | ^ refactor this method to conform to API 222 | @param param The parameter for this method 223 | */ 224 | } 225 | 226 | export class TestClass { 227 | 228 | /** 229 | * Test Method 230 | * * Important information is highlighted 231 | * ! Deprecated method, do not use 232 | * ? Should this method be exposed through API? 233 | * ^ refactor this method to conform to API 234 | * @param param The parameter for this method 235 | */ 236 | public TestMethod(param: any): void { 237 | let testVar: number = 123; 238 | 239 | // * This is a highlight 240 | if (testVar > 0) { 241 | throw new TypeError(); // ! this is an alert 242 | } 243 | 244 | // ? This is a query 245 | let x = 1; 246 | 247 | //// this.lineOfCode() == commentedOut; 248 | 249 | // ^ write some test cases 250 | } 251 | 252 | //!no spaces 253 | // ! Space then Tab 254 | // ! Tab then Tab 255 | // ! Tab then space 256 | 257 | // ? 汉字 258 | // * 123 259 | 260 | /* 261 | Test Method 262 | * Important information is highlighted 263 | ! Deprecated method, do not use 264 | ? Should this method be exposed through API? 265 | ^ refactor this method to conform to API 266 | @param param The parameter for this method 267 | */ 268 | } -------------------------------------------------------------------------------- /src/test/samples/Not Tested/lisp.lisp: -------------------------------------------------------------------------------- 1 | 2 | ;;;; Math Utilities 3 | 4 | ;;; FIB computes the the Fibonacci function in the traditional 5 | ;;; ! recursive way. 6 | 7 | (defun fib (n) 8 | (check-type n integer) 9 | ;; At this point we're sure we have an integer argument. 10 | ;; ! Now we can get down to some serious computation. 11 | (cond ((< n 0) 12 | ;; Hey, this is just supposed to be a simple example. 13 | ;; Did you really expect me to handle the general case? 14 | (error "FIB got ~D as an argument." n)) 15 | ((< n 2) n) ;fib[0]=0 and fib[1]=1 16 | ;; The cheap cases didn't work. 17 | ;; Nothing more to do but recurse. 18 | (t (+ (fib (- n 1)) ;The traditional formula 19 | (fib (- n 2)))))) ; is fib[n-1]+fib[n-2]. 20 | 21 | (defun fib (n) 22 | (check-type n integer) 23 | ;; At this point we're sure we have an integer argument. 24 | ;; ! Now we can get down to some serious computation. 25 | (cond ((< n 0) 26 | ;; Hey, this is just supposed to be a simple example. 27 | ;; Did you really expect me to handle the general case? 28 | (error "FIB got ~D as an argument." n)) 29 | ((< n 2) n) ;fib[0]=0 and fib[1]=1 30 | ;; The cheap cases didn't work. 31 | ;; Nothing more to do but recurse. 32 | (t (+ (fib (- n 1)) ;The traditional formula 33 | (fib (- n 2)))))) ; is fib[n-1]+fib[n-2]. 34 | 35 | (defun fib (n) 36 | (check-type n integer) 37 | ;; At this point we're sure we have an integer argument. 38 | ;; ! Now we can get down to some serious computation. 39 | (cond ((< n 0) 40 | ;; Hey, this is just supposed to be a simple example. 41 | ;; Did you really expect me to handle the general case? 42 | (error "FIB got ~D as an argument." n)) 43 | ((< n 2) n) ;fib[0]=0 and fib[1]=1 44 | ;; The cheap cases didn't work. 45 | ;; Nothing more to do but recurse. 46 | (t (+ (fib (- n 1)) ;The traditional formula 47 | (fib (- n 2)))))) ; is fib[n-1]+fib[n-2]. 48 | 49 | (defun fib (n) 50 | (check-type n integer) 51 | ;; At this point we're sure we have an integer argument. 52 | ;; ! Now we can get down to some serious computation. 53 | (cond ((< n 0) 54 | ;; Hey, this is just supposed to be a simple example. 55 | ;; Did you really expect me to handle the general case? 56 | (error "FIB got ~D as an argument." n)) 57 | ((< n 2) n) ;fib[0]=0 and fib[1]=1 58 | ;; The cheap cases didn't work. 59 | ;; Nothing more to do but recurse. 60 | (t (+ (fib (- n 1)) ;The traditional formula 61 | (fib (- n 2)))))) ; is fib[n-1]+fib[n-2]. 62 | 63 | (defun fib (n) 64 | (check-type n integer) 65 | ;; At this point we're sure we have an integer argument. 66 | ;; ! Now we can get down to some serious computation. 67 | (cond ((< n 0) 68 | ;; Hey, this is just supposed to be a simple example. 69 | ;; Did you really expect me to handle the general case? 70 | (error "FIB got ~D as an argument." n)) 71 | ((< n 2) n) ;fib[0]=0 and fib[1]=1 72 | ;; The cheap cases didn't work. 73 | ;; Nothing more to do but recurse. 74 | (t (+ (fib (- n 1)) ;The traditional formula 75 | (fib (- n 2)))))) ; is fib[n-1]+fib[n-2]. 76 | 77 | (defun fib (n) 78 | (check-type n integer) 79 | ;; At this point we're sure we have an integer argument. 80 | ;; ! Now we can get down to some serious computation. 81 | (cond ((< n 0) 82 | ;; Hey, this is just supposed to be a simple example. 83 | ;; Did you really expect me to handle the general case? 84 | (error "FIB got ~D as an argument." n)) 85 | ((< n 2) n) ;fib[0]=0 and fib[1]=1 86 | ;; The cheap cases didn't work. 87 | ;; Nothing more to do but recurse. 88 | (t (+ (fib (- n 1)) ;The traditional formula 89 | (fib (- n 2)))))) ; is fib[n-1]+fib[n-2]. 90 | (defun fib (n) 91 | (check-type n integer) 92 | ;; At this point we're sure we have an integer argument. 93 | ;; ! Now we can get down to some serious computation. 94 | (cond ((< n 0) 95 | ;; Hey, this is just supposed to be a simple example. 96 | ;; Did you really expect me to handle the general case? 97 | (error "FIB got ~D as an argument." n)) 98 | ((< n 2) n) ;fib[0]=0 and fib[1]=1 99 | ;; The cheap cases didn't work. 100 | ;; Nothing more to do but recurse. 101 | (t (+ (fib (- n 1)) ;The traditional formula 102 | (fib (- n 2)))))) ; is fib[n-1]+fib[n-2]. 103 | (defun fib (n) 104 | (check-type n integer) 105 | ;; At this point we're sure we have an integer argument. 106 | ;; ! Now we can get down to some serious computation. 107 | (cond ((< n 0) 108 | ;; Hey, this is just supposed to be a simple example. 109 | ;; Did you really expect me to handle the general case? 110 | (error "FIB got ~D as an argument." n)) 111 | ((< n 2) n) ;fib[0]=0 and fib[1]=1 112 | ;; The cheap cases didn't work. 113 | ;; Nothing more to do but recurse. 114 | (t (+ (fib (- n 1)) ;The traditional formula 115 | (fib (- n 2)))))) ; is fib[n-1]+fib[n-2]. 116 | (defun fib (n) 117 | (check-type n integer) 118 | ;; At this point we're sure we have an integer argument. 119 | ;; ! Now we can get down to some serious computation. 120 | (cond ((< n 0) 121 | ;; Hey, this is just supposed to be a simple example. 122 | ;; Did you really expect me to handle the general case? 123 | (error "FIB got ~D as an argument." n)) 124 | ((< n 2) n) ;fib[0]=0 and fib[1]=1 125 | ;; The cheap cases didn't work. 126 | ;; Nothing more to do but recurse. 127 | (t (+ (fib (- n 1)) ;The traditional formula 128 | (fib (- n 2)))))) ; is fib[n-1]+fib[n-2].(defun fib (n) 129 | (check-type n integer) 130 | ;; At this point we're sure we have an integer argument. 131 | ;; ! Now we can get down to some serious computation. 132 | (cond ((< n 0) 133 | ;; Hey, this is just supposed to be a simple example. 134 | ;; ? Did you really expect me to handle the general case? 135 | (error "FIB got ~D as an argument." n)) 136 | ((< n 2) n) ;fib[0]=0 and fib[1]=1 137 | ;; The cheap cases didn't work. 138 | ;; Nothing more to do but recurse. 139 | (t (+ (fib (- n 1)) ;The traditional formula 140 | (fib (- n 2)))))) ; is fib[n-1]+fib[n-2]. 141 | (defun fib (n) 142 | (check-type n integer) 143 | ;; At this point we're sure we have an integer argument. 144 | ;; ! Now we can get down to some serious computation. 145 | (cond ((< n 0) 146 | ;; Hey, this is just supposed to be a simple example. 147 | ;; Did you really expect me to handle the general case? 148 | (error "FIB got ~D as an argument." n)) 149 | ((< n 2) n) ;fib[0]=0 and fib[1]=1 150 | ;; The cheap cases didn't work. 151 | ;; Nothing more to do but recurse. 152 | (t (+ (fib (- n 1)) ;The traditional formula 153 | (fib (- n 2)))))) ; is fib[n-1]+fib[n-2].(defun fib (n) 154 | (check-type n integer) 155 | ;; At this point we're sure we have an integer argument. 156 | ;; ! Now we can get down to some serious computation. 157 | (cond ((< n 0) 158 | ;; Hey, this is just supposed to be a simple example. 159 | ;; Did you really expect me to handle the general case? 160 | (error "FIB got ~D as an argument." n)) 161 | ((< n 2) n) ;fib[0]=0 and fib[1]=1 162 | ;; The cheap cases didn't work. 163 | ;; Nothing more to do but recurse. 164 | (t (+ (fib (- n 1)) ;The traditional formula 165 | (fib (- n 2)))))) ; is fib[n-1]+fib[n-2]. 166 | 167 | 168 | (defun fib (n) 169 | (check-type n integer) 170 | ;; At this point we're sure we have an integer argument. 171 | ;; ! Now we can get down to some serious computation. 172 | (cond ((< n 0) 173 | ;; Hey, this is just supposed to be a simple example. 174 | ;; Did you really expect me to handle the general case? 175 | (error "FIB got ~D as an argument." n)) 176 | ((< n 2) n) ;fib[0]=0 and fib[1]=1 177 | ;; The cheap cases didn't work. 178 | ;; Nothing more to do but recurse. 179 | (t (+ (fib (- n 1)) ;The traditional formula 180 | (fib (- n 2)))))) ; is fib[n-1]+fib[n-2].(defun fib (n) 181 | (check-type n integer) 182 | ;; At this point we're sure we have an integer argument. 183 | ;; ! Now we can get down to some serious computation. 184 | (cond ((< n 0) 185 | ;; Hey, this is just supposed to be a simple example. 186 | ;; Did you really expect me to handle the general case? 187 | (error "FIB got ~D as an argument." n)) 188 | ((< n 2) n) ;fib[0]=0 and fib[1]=1 189 | ;; The cheap cases didn't work. 190 | ;; Nothing more to do but recurse. 191 | (t (+ (fib (- n 1)) ;The traditional formula 192 | (fib (- n 2)))))) ; is fib[n-1]+fib[n-2]. -------------------------------------------------------------------------------- /src/parser.ts: -------------------------------------------------------------------------------- 1 | import * as vscode from 'vscode'; 2 | 3 | interface CommentTag 4 | { 5 | tag: string; 6 | escapedTag: string; 7 | decoration: vscode.TextEditorDecorationType; 8 | ranges: Array; 9 | } 10 | 11 | interface Contributions 12 | { 13 | multilineComments: boolean; 14 | useJSDocStyle: boolean; 15 | highlightPlainText: boolean; 16 | tags: [{ 17 | tag: string; 18 | color: string; 19 | strikethrough: boolean; 20 | backgroundColor: string; 21 | }]; 22 | } 23 | 24 | export class Parser 25 | { 26 | private tags: CommentTag[] = []; 27 | private expression: string = ""; 28 | 29 | private delimiter: string = ""; 30 | private blockCommentStart: string = ""; 31 | private blockCommentEnd: string = ""; 32 | 33 | private highlightSingleLineComments = true; 34 | private highlightMultilineComments = false; 35 | private highlightJSDoc = false; 36 | 37 | private isPlainText = false; 38 | private ignoreFirstLine = false; 39 | public supportedLanguage = true; 40 | 41 | private contributions: Contributions = vscode.workspace.getConfiguration('colorful-comments') as any; 42 | 43 | public constructor() { 44 | this.setTags(); 45 | } 46 | 47 | /** 48 | * Sets the regex to be used by the matcher based on the config specified in the package.json 49 | * @param languageCode The short code of the current language 50 | * https://code.visualstudio.com/docs/languages/identifiers 51 | */ 52 | 53 | public SetRegex(languageCode: string) 54 | { 55 | this.setDelimiter(languageCode); 56 | 57 | if (!this.supportedLanguage) { 58 | return; 59 | } 60 | 61 | let characters: Array = []; 62 | for (let commentTag of this.tags) { 63 | characters.push(commentTag.escapedTag); 64 | } 65 | 66 | if (this.isPlainText && this.contributions.highlightPlainText) { 67 | this.expression = "(^)+([ \\t]*[ \\t]*)"; 68 | } 69 | else { 70 | this.expression = "(" + this.delimiter.replace(/\//ig, "\\/") + ")+( |\t)*"; 71 | } 72 | 73 | this.expression += "("; 74 | this.expression += characters.join("|"); 75 | this.expression += ")+(.*)"; 76 | } 77 | 78 | /** 79 | * Finds all single line comments delimited by a given delimiter and matching tags specified in package.json 80 | * @param activeEditor The active text editor containing the code document 81 | */ 82 | 83 | public FindSingleLineComments(activeEditor: vscode.TextEditor): void 84 | { 85 | if (!this.highlightSingleLineComments) 86 | return; 87 | 88 | let text = activeEditor.document.getText(); 89 | 90 | let regexFlags = (this.isPlainText) ? "igm" : "ig"; 91 | let regEx = new RegExp(this.expression, regexFlags); 92 | 93 | let match: any; 94 | while (match = regEx.exec(text)) 95 | { 96 | let startPos = activeEditor.document.positionAt(match.index); 97 | let endPos = activeEditor.document.positionAt(match.index + match[0].length); 98 | let range = { range: new vscode.Range(startPos, endPos) }; 99 | 100 | if (this.ignoreFirstLine && startPos.line === 0 && startPos.character === 0) { 101 | continue; 102 | } 103 | 104 | let matchTag = this.tags.find(item => item.tag.toLowerCase() === match[3].toLowerCase()); 105 | if (matchTag) { 106 | matchTag.ranges.push(range); 107 | } 108 | } 109 | } 110 | 111 | /** 112 | * Finds block comments as indicated by start and end delimiter 113 | * @param activeEditor The active text editor containing the code document 114 | */ 115 | 116 | public FindBlockComments(activeEditor: vscode.TextEditor): void 117 | { 118 | 119 | if (!this.highlightMultilineComments) 120 | return; 121 | 122 | let text = activeEditor.document.getText(); 123 | 124 | let characters: Array = []; 125 | for (let commentTag of this.tags) { 126 | characters.push(commentTag.escapedTag); 127 | } 128 | 129 | let commentMatchString = "(^)+([ \\t]*[ \\t]*)("; 130 | commentMatchString += characters.join("|"); 131 | commentMatchString += ")([ ]*|[:])+([^*/][^\\r\\n]*)"; 132 | 133 | let regexString = "(^|[ \\t])("; 134 | regexString += this.blockCommentStart; 135 | regexString += "[\\s])+([\\s\\S]*?)("; 136 | regexString += this.blockCommentEnd; 137 | regexString += ")"; 138 | 139 | let regEx = new RegExp(regexString, "gm"); 140 | let commentRegEx = new RegExp(commentMatchString, "igm"); 141 | 142 | let match: any; 143 | 144 | while (match = regEx.exec(text)) 145 | { 146 | let commentBlock = match[0]; 147 | 148 | let line; 149 | while (line = commentRegEx.exec(commentBlock)) 150 | { 151 | let startPos = activeEditor.document.positionAt(match.index + line.index + line[2].length); 152 | let endPos = activeEditor.document.positionAt(match.index + line.index + line[0].length); 153 | let range: vscode.DecorationOptions = { range: new vscode.Range(startPos, endPos) }; 154 | 155 | let matchString = line[3] as string; 156 | let matchTag = this.tags.find(item => item.tag.toLowerCase() === matchString.toLowerCase()); 157 | 158 | if (matchTag) { 159 | matchTag.ranges.push(range); 160 | } 161 | } 162 | } 163 | } 164 | 165 | /** 166 | * Finds all multiline comments starting with "*" 167 | * @param activeEditor The active text editor containing the code document 168 | */ 169 | 170 | public FindJSDocComments(activeEditor: vscode.TextEditor): void 171 | { 172 | if (!this.highlightMultilineComments && !this.highlightJSDoc) 173 | return; 174 | 175 | let text = activeEditor.document.getText(); 176 | 177 | let characters: Array = []; 178 | for (let commentTag of this.tags) { 179 | characters.push(commentTag.escapedTag); 180 | } 181 | 182 | let commentMatchString = "(^)+([ \\t]*\\*[ \\t]*)("; 183 | let regEx = /(^|[ \t])(\/\*\*)+([\s\S]*?)(\*\/)/gm; 184 | 185 | commentMatchString += characters.join("|"); 186 | commentMatchString += ")([ ]*|[:])+([^*/][^\\r\\n]*)"; 187 | 188 | let commentRegEx = new RegExp(commentMatchString, "igm"); 189 | 190 | let match: any; 191 | while (match = regEx.exec(text)) 192 | { 193 | let commentBlock = match[0]; 194 | 195 | let line; 196 | while (line = commentRegEx.exec(commentBlock)) 197 | { 198 | let startPos = activeEditor.document.positionAt(match.index + line.index + line[2].length); 199 | let endPos = activeEditor.document.positionAt(match.index + line.index + line[0].length); 200 | let range: vscode.DecorationOptions = { range: new vscode.Range(startPos, endPos) }; 201 | 202 | let matchString = line[3] as string; 203 | let matchTag = this.tags.find(item => item.tag.toLowerCase() === matchString.toLowerCase()); 204 | 205 | if (matchTag) { 206 | matchTag.ranges.push(range); 207 | } 208 | } 209 | } 210 | } 211 | 212 | /** 213 | * Apply decorations after finding all relevant comments 214 | * @param activeEditor The active text editor containing the code document 215 | */ 216 | 217 | public ApplyDecorations(activeEditor: vscode.TextEditor): void 218 | { 219 | for (let tag of this.tags) 220 | { 221 | activeEditor.setDecorations(tag.decoration, tag.ranges); 222 | 223 | tag.ranges.length = 0; 224 | } 225 | } 226 | 227 | /** 228 | * Sets the comment delimiter [//, #, --, '] of a given language 229 | * @param languageCode The short code of the current language 230 | * https://code.visualstudio.com/docs/languages/identifiers 231 | */ 232 | 233 | private setDelimiter(languageCode: string): void 234 | { 235 | this.supportedLanguage = true; 236 | this.ignoreFirstLine = false; 237 | this.isPlainText = false; 238 | 239 | switch (languageCode) 240 | { 241 | 242 | case "asciidoc": this.setCommentFormat("//", "////", "////"); 243 | break; 244 | 245 | case "apex": 246 | case "javascript": 247 | case "javascriptreact": 248 | case "typescript": 249 | case "typescriptreact": 250 | this.setCommentFormat("//", "/*", "*/"); 251 | this.highlightJSDoc = true; 252 | break; 253 | 254 | case "al": 255 | case "c": 256 | case "cpp": 257 | case "csharp": 258 | case "dart": 259 | case "flax": 260 | case "fsharp": 261 | case "go": 262 | case "groovy": 263 | case "haxe": 264 | case "java": 265 | case "jsonc": 266 | case "kotlin": 267 | case "less": 268 | case "pascal": 269 | case "objectpascal": 270 | case "php": 271 | case "rust": 272 | case "scala": 273 | case "scss": 274 | case "stylus": 275 | case "swift": 276 | case "verilog": 277 | case "vue": 278 | this.setCommentFormat("//", "/*", "*/"); 279 | break; 280 | 281 | case "css": this.setCommentFormat("/*", "/*", "*/"); 282 | break; 283 | 284 | case "coffeescript": 285 | case "dockerfile": 286 | case "gdscript": 287 | case "graphql": 288 | case "julia": 289 | case "makefile": 290 | case "perl": 291 | case "perl6": 292 | case "puppet": 293 | case "r": 294 | case "ruby": 295 | case "shellscript": 296 | case "tcl": 297 | case "yaml": 298 | this.delimiter = "#"; 299 | break; 300 | 301 | case "tcl": this.delimiter = "#"; 302 | this.ignoreFirstLine = true; 303 | break; 304 | 305 | case "elixir": 306 | case "python": 307 | this.setCommentFormat("#", '"""', '"""'); 308 | this.ignoreFirstLine = true; 309 | break; 310 | 311 | case "nim": this.setCommentFormat("#", "#[", "]#"); 312 | break; 313 | 314 | case "powershell": this.setCommentFormat("#", "<#", "#>"); 315 | break; 316 | 317 | case "ada": 318 | case "hive-sql": 319 | case "pig": 320 | case "plsql": 321 | case "sql": 322 | this.delimiter = "--"; 323 | break; 324 | 325 | case "lua": this.setCommentFormat("--", "--[[", "]]"); 326 | break; 327 | 328 | case "elm": 329 | case "haskell": 330 | this.setCommentFormat("--", "{-", "-}"); 331 | break; 332 | 333 | 334 | case "brightscript": 335 | case "diagram": // ? PlantUML is recognized as Diagram (diagram) 336 | case "vb": 337 | this.delimiter = "'"; 338 | break; 339 | 340 | case "bibtex": 341 | case "erlang": 342 | case "latex": 343 | case "matlab": 344 | this.delimiter = "%"; 345 | break; 346 | 347 | case "clojure": 348 | case "racket": 349 | case "lisp": 350 | this.delimiter = ";"; 351 | break; 352 | 353 | case "terraform": this.setCommentFormat("#", "/*", "*/"); 354 | break; 355 | 356 | case "COBOL": this.delimiter = this.escapeRegExp("*>"); 357 | break; 358 | 359 | case "fortran-modern": this.delimiter = "c"; 360 | break; 361 | 362 | case "SAS": 363 | case "stata": 364 | this.setCommentFormat("*", "/*", "*/"); 365 | break; 366 | 367 | case "html": 368 | case "markdown": 369 | case "xml": 370 | this.setCommentFormat(""); 371 | break; 372 | 373 | case "twig": this.setCommentFormat("{#", "{#", "#}"); 374 | break; 375 | 376 | case "genstat": this.setCommentFormat("\\", '"', '"'); 377 | break; 378 | 379 | case "cfml": this.setCommentFormat(""); 380 | break; 381 | 382 | case "plaintext": this.isPlainText = true; 383 | this.supportedLanguage = this.contributions.highlightPlainText; 384 | break; 385 | 386 | default: this.supportedLanguage = false; 387 | break; 388 | } 389 | } 390 | 391 | /** 392 | * Sets the highlighting tags up for use by the parser 393 | */ 394 | 395 | private setTags(): void 396 | { 397 | let items = this.contributions.tags; 398 | for (let item of items) 399 | { 400 | let options: vscode.DecorationRenderOptions = { color: item.color, backgroundColor: item.backgroundColor }; 401 | if (item.strikethrough) { 402 | options.textDecoration = "line-through"; 403 | } 404 | 405 | let escapedSequence = item.tag.replace(/([()[{*+.$^\\|?])/g, '\\$1'); 406 | this.tags.push( 407 | { 408 | tag: item.tag, 409 | escapedTag: escapedSequence.replace(/\//gi, "\\/"), 410 | ranges: [], 411 | decoration: vscode.window.createTextEditorDecorationType(options) 412 | }); 413 | } 414 | } 415 | 416 | /** 417 | * Escapes a given string for use in a regular expression 418 | * @param input The input string to be escaped 419 | * @returns {string} The escaped string 420 | */ 421 | 422 | private escapeRegExp(input: string): string { 423 | return input.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string 424 | } 425 | 426 | /** 427 | * Set up the comment format for single and multiline highlighting 428 | * @param singleLine The single line comment delimiter. If NULL, single line is not supported 429 | * @param start The start delimiter for block comments 430 | * @param end The end delimiter for block comments 431 | */ 432 | 433 | private setCommentFormat(singleLine: string | null, start: string, end: string): void 434 | { 435 | if (singleLine) { 436 | this.delimiter = this.escapeRegExp(singleLine); 437 | } 438 | else { 439 | this.highlightSingleLineComments = false; 440 | } 441 | 442 | this.blockCommentStart = this.escapeRegExp(start); 443 | this.blockCommentEnd = this.escapeRegExp(end); 444 | this.highlightMultilineComments = this.contributions.multilineComments; 445 | } 446 | } 447 | -------------------------------------------------------------------------------- /src/test/samples/clojure.clj: -------------------------------------------------------------------------------- 1 | 2 | ; ? Inspired by the snakes the have gone before: 3 | ; ^ Abhishek Reddy's snake: http://www.plt1.com/1070/even-smaller-snake/ 4 | ; ! Mark Volkmann's snake: http://www.ociweb.com/mark/programming/ClojureSnake.html 5 | 6 | (ns examples.atom-snake 7 | (:import (java.awt Color Dimension) 8 | (javax.swing JPanel JFrame Timer JOptionPane) 9 | (java.awt.event ActionListener KeyListener)) 10 | (:use examples.import-static)) 11 | (import-static java.awt.event.KeyEvent VK_LEFT VK_RIGHT VK_UP VK_DOWN) 12 | 13 | ; ---------------------------------------------------------- 14 | ; & Functional model 15 | ; ---------------------------------------------------------- 16 | (def width 75) 17 | (def height 50) 18 | (def point-size 10) 19 | (def turn-millis 75) 20 | (def win-length 5) 21 | (def dirs { VK_LEFT [-1 0] 22 | VK_RIGHT [ 1 0] 23 | VK_UP [ 0 -1] 24 | VK_DOWN [ 0 1]}) 25 | 26 | (defn add-points [& pts] 27 | (vec (apply map + pts))) 28 | 29 | (defn point-to-screen-rect [pt] 30 | (map #(* point-size %) 31 | [(pt 0) (pt 1) 1 1])) 32 | 33 | (defn create-apple [] 34 | {:location [(rand-int width) (rand-int height)] 35 | :color (Color. 210 50 90) 36 | :type :apple}) 37 | 38 | (defn create-snake [] 39 | {:body (list [1 1]) 40 | :dir [1 0] 41 | :type :snake 42 | :color (Color. 15 160 70)}) 43 | 44 | (defn move [{:keys [body dir] :as snake} & grow] 45 | (assoc snake :body (cons (add-points (first body) dir) 46 | (if grow body (butlast body))))) 47 | 48 | (defn turn [snake newdir] 49 | (if newdir (assoc snake :dir newdir) snake)) 50 | 51 | (defn win? [{body :body}] 52 | (>= (count body) win-length)) 53 | 54 | (defn head-overlaps-body? [{[head & body] :body}] 55 | (contains? (set body) head)) 56 | 57 | (def lose? head-overlaps-body?) 58 | 59 | (defn eats? [{[snake-head] :body} {apple :location}] 60 | (= snake-head apple)) 61 | 62 | ; START: update-positions 63 | (defn update-positions [{snake :snake, apple :apple, :as game}] 64 | (if (eats? snake apple) 65 | (merge game {:apple (create-apple) :snake (move snake :grow)}) 66 | (merge game {:snake (move snake)}))) 67 | ; END: update-positions 68 | 69 | (defn update-direction [{snake :snake :as game} newdir] 70 | (merge game {:snake (turn snake newdir)})) 71 | 72 | (defn reset-game [game] 73 | (merge game {:apple (create-apple) :snake (create-snake)})) 74 | 75 | ; ---------------------------------------------------------- 76 | ; * * gui * * 77 | ; ---------------------------------------------------------- 78 | (defn fill-point [g pt color] 79 | (let [[x y width height] (point-to-screen-rect pt)] 80 | (.setColor g color) 81 | (.fillRect g x y width height))) 82 | 83 | (defmulti paint (fn [g object & _] (:type object))) 84 | 85 | (defmethod paint :apple [g {:keys [location color]}] 86 | (fill-point g location color)) 87 | 88 | (defmethod paint :snake [g {:keys [body color]}] 89 | (doseq [point body] 90 | (fill-point g point color))) 91 | 92 | (defn game-panel [frame game] 93 | (proxy [JPanel ActionListener KeyListener] [] 94 | (paintComponent [g] 95 | (proxy-super paintComponent g) 96 | (paint g (@game :snake)) 97 | (paint g (@game :apple))) 98 | ; START: swap! 99 | (actionPerformed [e] 100 | (swap! game update-positions) 101 | (when (lose? (@game :snake)) 102 | (swap! game reset-game) 103 | (JOptionPane/showMessageDialog frame "You lose!")) 104 | ; END: swap! 105 | (when (win? (@game :snake)) 106 | (swap! game reset-game) 107 | (JOptionPane/showMessageDialog frame "You win!")) 108 | (.repaint this)) 109 | (keyPressed [e] 110 | (swap! game update-direction (dirs (.getKeyCode e)))) 111 | (getPreferredSize [] 112 | (Dimension. (* (inc width) point-size) 113 | (* (inc height) point-size))) 114 | (keyReleased [e]) 115 | (keyTyped [e]))) 116 | ;;;;; ! hello world 117 | (defn game [] 118 | (let [game (atom (reset-game {})) 119 | frame (JFrame. "Snake") 120 | panel (game-panel frame game) 121 | timer (Timer. turn-millis panel)] 122 | (doto panel 123 | (.setFocusable true) 124 | (.addKeyListener panel)) 125 | (doto frame 126 | (.add panel) 127 | (.pack) 128 | (.setVisible true)) 129 | (.start timer) 130 | [game, timer])) 131 | 132 | ; Inspired by the snakes the have gone before: 133 | ; Abhishek Reddy's snake: http://www.plt1.com/1070/even-smaller-snake/ 134 | ; ! Mark Volkmann's snake: http://www.ociweb.com/mark/programming/ClojureSnake.html 135 | 136 | (ns examples.atom-snake 137 | (:import (java.awt Color Dimension) 138 | (javax.swing JPanel JFrame Timer JOptionPane) 139 | (java.awt.event ActionListener KeyListener)) 140 | (:use examples.import-static)) 141 | (import-static java.awt.event.KeyEvent VK_LEFT VK_RIGHT VK_UP VK_DOWN) 142 | 143 | ; ---------------------------------------------------------- 144 | ; functional model 145 | ; ---------------------------------------------------------- 146 | (def width 75) 147 | (def height 50) 148 | (def point-size 10) 149 | (def turn-millis 75) 150 | (def win-length 5) 151 | (def dirs { VK_LEFT [-1 0] 152 | VK_RIGHT [ 1 0] 153 | VK_UP [ 0 -1] 154 | VK_DOWN [ 0 1]}) 155 | 156 | (defn add-points [& pts] 157 | (vec (apply map + pts))) 158 | 159 | (defn point-to-screen-rect [pt] 160 | (map #(* point-size %) 161 | [(pt 0) (pt 1) 1 1])) 162 | 163 | (defn create-apple [] 164 | {:location [(rand-int width) (rand-int height)] 165 | :color (Color. 210 50 90) 166 | :type :apple}) 167 | 168 | (defn create-snake [] 169 | {:body (list [1 1]) 170 | :dir [1 0] 171 | :type :snake 172 | :color (Color. 15 160 70)}) 173 | 174 | (defn move [{:keys [body dir] :as snake} & grow] 175 | (assoc snake :body (cons (add-points (first body) dir) 176 | (if grow body (butlast body))))) 177 | 178 | (defn turn [snake newdir] 179 | (if newdir (assoc snake :dir newdir) snake)) 180 | 181 | (defn win? [{body :body}] 182 | (>= (count body) win-length)) 183 | 184 | (defn head-overlaps-body? [{[head & body] :body}] 185 | (contains? (set body) head)) 186 | 187 | (def lose? head-overlaps-body?) 188 | 189 | (defn eats? [{[snake-head] :body} {apple :location}] 190 | (= snake-head apple)) 191 | 192 | ; START: update-positions 193 | (defn update-positions [{snake :snake, apple :apple, :as game}] 194 | (if (eats? snake apple) 195 | (merge game {:apple (create-apple) :snake (move snake :grow)}) 196 | (merge game {:snake (move snake)}))) 197 | ; END: update-positions 198 | 199 | (defn update-direction [{snake :snake :as game} newdir] 200 | (merge game {:snake (turn snake newdir)})) 201 | 202 | (defn reset-game [game] 203 | (merge game {:apple (create-apple) :snake (create-snake)})) 204 | 205 | ; ---------------------------------------------------------- 206 | ; * * gui * * 207 | ; ---------------------------------------------------------- 208 | (defn fill-point [g pt color] 209 | (let [[x y width height] (point-to-screen-rect pt)] 210 | (.setColor g color) 211 | (.fillRect g x y width height))) 212 | 213 | (defmulti paint (fn [g object & _] (:type object))) 214 | 215 | (defmethod paint :apple [g {:keys [location color]}] 216 | (fill-point g location color)) 217 | 218 | (defmethod paint :snake [g {:keys [body color]}] 219 | (doseq [point body] 220 | (fill-point g point color))) 221 | 222 | (defn game-panel [frame game] 223 | (proxy [JPanel ActionListener KeyListener] [] 224 | (paintComponent [g] 225 | (proxy-super paintComponent g) 226 | (paint g (@game :snake)) 227 | (paint g (@game :apple))) 228 | ; START: swap! 229 | (actionPerformed [e] 230 | (swap! game update-positions) 231 | (when (lose? (@game :snake)) 232 | (swap! game reset-game) 233 | (JOptionPane/showMessageDialog frame "You lose!")) 234 | ; END: swap! 235 | (when (win? (@game :snake)) 236 | (swap! game reset-game) 237 | (JOptionPane/showMessageDialog frame "You win!")) 238 | (.repaint this)) 239 | (keyPressed [e] 240 | (swap! game update-direction (dirs (.getKeyCode e)))) 241 | (getPreferredSize [] 242 | (Dimension. (* (inc width) point-size) 243 | (* (inc height) point-size))) 244 | (keyReleased [e]) 245 | (keyTyped [e]))) 246 | ;;;;; ! hello world 247 | (defn game [] 248 | (let [game (atom (reset-game {})) 249 | frame (JFrame. "Snake") 250 | panel (game-panel frame game) 251 | timer (Timer. turn-millis panel)] 252 | (doto panel 253 | (.setFocusable true) 254 | (.addKeyListener panel)) 255 | (doto frame 256 | (.add panel) 257 | (.pack) 258 | (.setVisible true)) 259 | (.start timer) 260 | [game, timer])) 261 | 262 | 263 | 264 | ; Inspired by the snakes the have gone before: 265 | ; Abhishek Reddy's snake: http://www.plt1.com/1070/even-smaller-snake/ 266 | ; ! Mark Volkmann's snake: http://www.ociweb.com/mark/programming/ClojureSnake.html 267 | 268 | (ns examples.atom-snake 269 | (:import (java.awt Color Dimension) 270 | (javax.swing JPanel JFrame Timer JOptionPane) 271 | (java.awt.event ActionListener KeyListener)) 272 | (:use examples.import-static)) 273 | (import-static java.awt.event.KeyEvent VK_LEFT VK_RIGHT VK_UP VK_DOWN) 274 | 275 | ; ---------------------------------------------------------- 276 | ; functional model 277 | ; ---------------------------------------------------------- 278 | (def width 75) 279 | (def height 50) 280 | (def point-size 10) 281 | (def turn-millis 75) 282 | (def win-length 5) 283 | (def dirs { VK_LEFT [-1 0] 284 | VK_RIGHT [ 1 0] 285 | VK_UP [ 0 -1] 286 | VK_DOWN [ 0 1]}) 287 | 288 | (defn add-points [& pts] 289 | (vec (apply map + pts))) 290 | 291 | (defn point-to-screen-rect [pt] 292 | (map #(* point-size %) 293 | [(pt 0) (pt 1) 1 1])) 294 | 295 | (defn create-apple [] 296 | {:location [(rand-int width) (rand-int height)] 297 | :color (Color. 210 50 90) 298 | :type :apple}) 299 | 300 | (defn create-snake [] 301 | {:body (list [1 1]) 302 | :dir [1 0] 303 | :type :snake 304 | :color (Color. 15 160 70)}) 305 | 306 | (defn move [{:keys [body dir] :as snake} & grow] 307 | (assoc snake :body (cons (add-points (first body) dir) 308 | (if grow body (butlast body))))) 309 | 310 | (defn turn [snake newdir] 311 | (if newdir (assoc snake :dir newdir) snake)) 312 | 313 | (defn win? [{body :body}] 314 | (>= (count body) win-length)) 315 | 316 | (defn head-overlaps-body? [{[head & body] :body}] 317 | (contains? (set body) head)) 318 | 319 | (def lose? head-overlaps-body?) 320 | 321 | (defn eats? [{[snake-head] :body} {apple :location}] 322 | (= snake-head apple)) 323 | 324 | ; START: update-positions 325 | (defn update-positions [{snake :snake, apple :apple, :as game}] 326 | (if (eats? snake apple) 327 | (merge game {:apple (create-apple) :snake (move snake :grow)}) 328 | (merge game {:snake (move snake)}))) 329 | ; END: update-positions 330 | 331 | (defn update-direction [{snake :snake :as game} newdir] 332 | (merge game {:snake (turn snake newdir)})) 333 | 334 | (defn reset-game [game] 335 | (merge game {:apple (create-apple) :snake (create-snake)})) 336 | 337 | ; ---------------------------------------------------------- 338 | ; * * gui * * 339 | ; ---------------------------------------------------------- 340 | (defn fill-point [g pt color] 341 | (let [[x y width height] (point-to-screen-rect pt)] 342 | (.setColor g color) 343 | (.fillRect g x y width height))) 344 | 345 | (defmulti paint (fn [g object & _] (:type object))) 346 | 347 | (defmethod paint :apple [g {:keys [location color]}] 348 | (fill-point g location color)) 349 | 350 | (defmethod paint :snake [g {:keys [body color]}] 351 | (doseq [point body] 352 | (fill-point g point color))) 353 | 354 | (defn game-panel [frame game] 355 | (proxy [JPanel ActionListener KeyListener] [] 356 | (paintComponent [g] 357 | (proxy-super paintComponent g) 358 | (paint g (@game :snake)) 359 | (paint g (@game :apple))) 360 | ; START: swap! 361 | (actionPerformed [e] 362 | (swap! game update-positions) 363 | (when (lose? (@game :snake)) 364 | (swap! game reset-game) 365 | (JOptionPane/showMessageDialog frame "You lose!")) 366 | ; END: swap! 367 | (when (win? (@game :snake)) 368 | (swap! game reset-game) 369 | (JOptionPane/showMessageDialog frame "You win!")) 370 | (.repaint this)) 371 | (keyPressed [e] 372 | (swap! game update-direction (dirs (.getKeyCode e)))) 373 | (getPreferredSize [] 374 | (Dimension. (* (inc width) point-size) 375 | (* (inc height) point-size))) 376 | (keyReleased [e]) 377 | (keyTyped [e]))) 378 | ;;;;; ! hello world 379 | (defn game [] 380 | (let [game (atom (reset-game {})) 381 | frame (JFrame. "Snake") 382 | panel (game-panel frame game) 383 | timer (Timer. turn-millis panel)] 384 | (doto panel 385 | (.setFocusable true) 386 | (.addKeyListener panel)) 387 | (doto frame 388 | (.add panel) 389 | (.pack) 390 | (.setVisible true)) 391 | (.start timer) 392 | [game, timer])) 393 | 394 | ; Inspired by the snakes the have gone before: 395 | ; Abhishek Reddy's snake: http://www.plt1.com/1070/even-smaller-snake/ 396 | ; ! Mark Volkmann's snake: http://www.ociweb.com/mark/programming/ClojureSnake.html 397 | 398 | (ns examples.atom-snake 399 | (:import (java.awt Color Dimension) 400 | (javax.swing JPanel JFrame Timer JOptionPane) 401 | (java.awt.event ActionListener KeyListener)) 402 | (:use examples.import-static)) 403 | (import-static java.awt.event.KeyEvent VK_LEFT VK_RIGHT VK_UP VK_DOWN) 404 | 405 | ; ---------------------------------------------------------- 406 | ; functional model 407 | ; ---------------------------------------------------------- 408 | (def width 75) 409 | (def height 50) 410 | (def point-size 10) 411 | (def turn-millis 75) 412 | (def win-length 5) 413 | (def dirs { VK_LEFT [-1 0] 414 | VK_RIGHT [ 1 0] 415 | VK_UP [ 0 -1] 416 | VK_DOWN [ 0 1]}) 417 | 418 | (defn add-points [& pts] 419 | (vec (apply map + pts))) 420 | 421 | (defn point-to-screen-rect [pt] 422 | (map #(* point-size %) 423 | [(pt 0) (pt 1) 1 1])) 424 | 425 | (defn create-apple [] 426 | {:location [(rand-int width) (rand-int height)] 427 | :color (Color. 210 50 90) 428 | :type :apple}) 429 | 430 | (defn create-snake [] 431 | {:body (list [1 1]) 432 | :dir [1 0] 433 | :type :snake 434 | :color (Color. 15 160 70)}) 435 | 436 | (defn move [{:keys [body dir] :as snake} & grow] 437 | (assoc snake :body (cons (add-points (first body) dir) 438 | (if grow body (butlast body))))) 439 | 440 | (defn turn [snake newdir] 441 | (if newdir (assoc snake :dir newdir) snake)) 442 | 443 | (defn win? [{body :body}] 444 | (>= (count body) win-length)) 445 | 446 | (defn head-overlaps-body? [{[head & body] :body}] 447 | (contains? (set body) head)) 448 | 449 | (def lose? head-overlaps-body?) 450 | 451 | (defn eats? [{[snake-head] :body} {apple :location}] 452 | (= snake-head apple)) 453 | 454 | ; START: update-positions 455 | (defn update-positions [{snake :snake, apple :apple, :as game}] 456 | (if (eats? snake apple) 457 | (merge game {:apple (create-apple) :snake (move snake :grow)}) 458 | (merge game {:snake (move snake)}))) 459 | ; END: update-positions 460 | 461 | (defn update-direction [{snake :snake :as game} newdir] 462 | (merge game {:snake (turn snake newdir)})) 463 | 464 | (defn reset-game [game] 465 | (merge game {:apple (create-apple) :snake (create-snake)})) 466 | 467 | ; ---------------------------------------------------------- 468 | ; * * gui * * 469 | ; ---------------------------------------------------------- 470 | (defn fill-point [g pt color] 471 | (let [[x y width height] (point-to-screen-rect pt)] 472 | (.setColor g color) 473 | (.fillRect g x y width height))) 474 | 475 | (defmulti paint (fn [g object & _] (:type object))) 476 | 477 | (defmethod paint :apple [g {:keys [location color]}] 478 | (fill-point g location color)) 479 | 480 | (defmethod paint :snake [g {:keys [body color]}] 481 | (doseq [point body] 482 | (fill-point g point color))) 483 | 484 | (defn game-panel [frame game] 485 | (proxy [JPanel ActionListener KeyListener] [] 486 | (paintComponent [g] 487 | (proxy-super paintComponent g) 488 | (paint g (@game :snake)) 489 | (paint g (@game :apple))) 490 | ; START: swap! 491 | (actionPerformed [e] 492 | (swap! game update-positions) 493 | (when (lose? (@game :snake)) 494 | (swap! game reset-game) 495 | (JOptionPane/showMessageDialog frame "You lose!")) 496 | ; END: swap! 497 | (when (win? (@game :snake)) 498 | (swap! game reset-game) 499 | (JOptionPane/showMessageDialog frame "You win!")) 500 | (.repaint this)) 501 | (keyPressed [e] 502 | (swap! game update-direction (dirs (.getKeyCode e)))) 503 | (getPreferredSize [] 504 | (Dimension. (* (inc width) point-size) 505 | (* (inc height) point-size))) 506 | (keyReleased [e]) 507 | (keyTyped [e]))) 508 | ;;;;; ! hello world 509 | (defn game [] 510 | (let [game (atom (reset-game {})) 511 | frame (JFrame. "Snake") 512 | panel (game-panel frame game) 513 | timer (Timer. turn-millis panel)] 514 | (doto panel 515 | (.setFocusable true) 516 | (.addKeyListener panel)) 517 | (doto frame 518 | (.add panel) 519 | (.pack) 520 | (.setVisible true)) 521 | (.start timer) 522 | [game, timer])) 523 | 524 | 525 | 526 | ; Inspired by the snakes the have gone before: 527 | ; Abhishek Reddy's snake: http://www.plt1.com/1070/even-smaller-snake/ 528 | ; ! Mark Volkmann's snake: http://www.ociweb.com/mark/programming/ClojureSnake.html 529 | 530 | (ns examples.atom-snake 531 | (:import (java.awt Color Dimension) 532 | (javax.swing JPanel JFrame Timer JOptionPane) 533 | (java.awt.event ActionListener KeyListener)) 534 | (:use examples.import-static)) 535 | (import-static java.awt.event.KeyEvent VK_LEFT VK_RIGHT VK_UP VK_DOWN) 536 | 537 | ; ---------------------------------------------------------- 538 | ; functional model 539 | ; ---------------------------------------------------------- 540 | (def width 75) 541 | (def height 50) 542 | (def point-size 10) 543 | (def turn-millis 75) 544 | (def win-length 5) 545 | (def dirs { VK_LEFT [-1 0] 546 | VK_RIGHT [ 1 0] 547 | VK_UP [ 0 -1] 548 | VK_DOWN [ 0 1]}) 549 | 550 | (defn add-points [& pts] 551 | (vec (apply map + pts))) 552 | 553 | (defn point-to-screen-rect [pt] 554 | (map #(* point-size %) 555 | [(pt 0) (pt 1) 1 1])) 556 | 557 | (defn create-apple [] 558 | {:location [(rand-int width) (rand-int height)] 559 | :color (Color. 210 50 90) 560 | :type :apple}) 561 | 562 | (defn create-snake [] 563 | {:body (list [1 1]) 564 | :dir [1 0] 565 | :type :snake 566 | :color (Color. 15 160 70)}) 567 | 568 | (defn move [{:keys [body dir] :as snake} & grow] 569 | (assoc snake :body (cons (add-points (first body) dir) 570 | (if grow body (butlast body))))) 571 | 572 | (defn turn [snake newdir] 573 | (if newdir (assoc snake :dir newdir) snake)) 574 | 575 | (defn win? [{body :body}] 576 | (>= (count body) win-length)) 577 | 578 | (defn head-overlaps-body? [{[head & body] :body}] 579 | (contains? (set body) head)) 580 | 581 | (def lose? head-overlaps-body?) 582 | 583 | (defn eats? [{[snake-head] :body} {apple :location}] 584 | (= snake-head apple)) 585 | 586 | ; START: update-positions 587 | (defn update-positions [{snake :snake, apple :apple, :as game}] 588 | (if (eats? snake apple) 589 | (merge game {:apple (create-apple) :snake (move snake :grow)}) 590 | (merge game {:snake (move snake)}))) 591 | ; END: update-positions 592 | 593 | (defn update-direction [{snake :snake :as game} newdir] 594 | (merge game {:snake (turn snake newdir)})) 595 | 596 | (defn reset-game [game] 597 | (merge game {:apple (create-apple) :snake (create-snake)})) 598 | 599 | ; ---------------------------------------------------------- 600 | ; * * gui * * 601 | ; ---------------------------------------------------------- 602 | (defn fill-point [g pt color] 603 | (let [[x y width height] (point-to-screen-rect pt)] 604 | (.setColor g color) 605 | (.fillRect g x y width height))) 606 | 607 | (defmulti paint (fn [g object & _] (:type object))) 608 | 609 | (defmethod paint :apple [g {:keys [location color]}] 610 | (fill-point g location color)) 611 | 612 | (defmethod paint :snake [g {:keys [body color]}] 613 | (doseq [point body] 614 | (fill-point g point color))) 615 | 616 | (defn game-panel [frame game] 617 | (proxy [JPanel ActionListener KeyListener] [] 618 | (paintComponent [g] 619 | (proxy-super paintComponent g) 620 | (paint g (@game :snake)) 621 | (paint g (@game :apple))) 622 | ; START: swap! 623 | (actionPerformed [e] 624 | (swap! game update-positions) 625 | (when (lose? (@game :snake)) 626 | (swap! game reset-game) 627 | (JOptionPane/showMessageDialog frame "You lose!")) 628 | ; END: swap! 629 | (when (win? (@game :snake)) 630 | (swap! game reset-game) 631 | (JOptionPane/showMessageDialog frame "You win!")) 632 | (.repaint this)) 633 | (keyPressed [e] 634 | (swap! game update-direction (dirs (.getKeyCode e)))) 635 | (getPreferredSize [] 636 | (Dimension. (* (inc width) point-size) 637 | (* (inc height) point-size))) 638 | (keyReleased [e]) 639 | (keyTyped [e]))) 640 | ;;;;; ! hello world 641 | (defn game [] 642 | (let [game (atom (reset-game {})) 643 | frame (JFrame. "Snake") 644 | panel (game-panel frame game) 645 | timer (Timer. turn-millis panel)] 646 | (doto panel 647 | (.setFocusable true) 648 | (.addKeyListener panel)) 649 | (doto frame 650 | (.add panel) 651 | (.pack) 652 | (.setVisible true)) 653 | (.start timer) 654 | [game, timer])) 655 | 656 | ; Inspired by the snakes the have gone before: 657 | ; Abhishek Reddy's snake: http://www.plt1.com/1070/even-smaller-snake/ 658 | ; ! Mark Volkmann's snake: http://www.ociweb.com/mark/programming/ClojureSnake.html 659 | 660 | (ns examples.atom-snake 661 | (:import (java.awt Color Dimension) 662 | (javax.swing JPanel JFrame Timer JOptionPane) 663 | (java.awt.event ActionListener KeyListener)) 664 | (:use examples.import-static)) 665 | (import-static java.awt.event.KeyEvent VK_LEFT VK_RIGHT VK_UP VK_DOWN) 666 | 667 | ; ---------------------------------------------------------- 668 | ; functional model 669 | ; ---------------------------------------------------------- 670 | (def width 75) 671 | (def height 50) 672 | (def point-size 10) 673 | (def turn-millis 75) 674 | (def win-length 5) 675 | (def dirs { VK_LEFT [-1 0] 676 | VK_RIGHT [ 1 0] 677 | VK_UP [ 0 -1] 678 | VK_DOWN [ 0 1]}) 679 | 680 | (defn add-points [& pts] 681 | (vec (apply map + pts))) 682 | 683 | (defn point-to-screen-rect [pt] 684 | (map #(* point-size %) 685 | [(pt 0) (pt 1) 1 1])) 686 | 687 | (defn create-apple [] 688 | {:location [(rand-int width) (rand-int height)] 689 | :color (Color. 210 50 90) 690 | :type :apple}) 691 | 692 | (defn create-snake [] 693 | {:body (list [1 1]) 694 | :dir [1 0] 695 | :type :snake 696 | :color (Color. 15 160 70)}) 697 | 698 | (defn move [{:keys [body dir] :as snake} & grow] 699 | (assoc snake :body (cons (add-points (first body) dir) 700 | (if grow body (butlast body))))) 701 | 702 | (defn turn [snake newdir] 703 | (if newdir (assoc snake :dir newdir) snake)) 704 | 705 | (defn win? [{body :body}] 706 | (>= (count body) win-length)) 707 | 708 | (defn head-overlaps-body? [{[head & body] :body}] 709 | (contains? (set body) head)) 710 | 711 | (def lose? head-overlaps-body?) 712 | 713 | (defn eats? [{[snake-head] :body} {apple :location}] 714 | (= snake-head apple)) 715 | 716 | ; START: update-positions 717 | (defn update-positions [{snake :snake, apple :apple, :as game}] 718 | (if (eats? snake apple) 719 | (merge game {:apple (create-apple) :snake (move snake :grow)}) 720 | (merge game {:snake (move snake)}))) 721 | ; END: update-positions 722 | 723 | (defn update-direction [{snake :snake :as game} newdir] 724 | (merge game {:snake (turn snake newdir)})) 725 | 726 | (defn reset-game [game] 727 | (merge game {:apple (create-apple) :snake (create-snake)})) 728 | 729 | ; ---------------------------------------------------------- 730 | ; * * gui * * 731 | ; ---------------------------------------------------------- 732 | (defn fill-point [g pt color] 733 | (let [[x y width height] (point-to-screen-rect pt)] 734 | (.setColor g color) 735 | (.fillRect g x y width height))) 736 | 737 | (defmulti paint (fn [g object & _] (:type object))) 738 | 739 | (defmethod paint :apple [g {:keys [location color]}] 740 | (fill-point g location color)) 741 | 742 | (defmethod paint :snake [g {:keys [body color]}] 743 | (doseq [point body] 744 | (fill-point g point color))) 745 | 746 | (defn game-panel [frame game] 747 | (proxy [JPanel ActionListener KeyListener] [] 748 | (paintComponent [g] 749 | (proxy-super paintComponent g) 750 | (paint g (@game :snake)) 751 | (paint g (@game :apple))) 752 | ; START: swap! 753 | (actionPerformed [e] 754 | (swap! game update-positions) 755 | (when (lose? (@game :snake)) 756 | (swap! game reset-game) 757 | (JOptionPane/showMessageDialog frame "You lose!")) 758 | ; END: swap! 759 | (when (win? (@game :snake)) 760 | (swap! game reset-game) 761 | (JOptionPane/showMessageDialog frame "You win!")) 762 | (.repaint this)) 763 | (keyPressed [e] 764 | (swap! game update-direction (dirs (.getKeyCode e)))) 765 | (getPreferredSize [] 766 | (Dimension. (* (inc width) point-size) 767 | (* (inc height) point-size))) 768 | (keyReleased [e]) 769 | (keyTyped [e]))) 770 | ;;;;; ! hello world 771 | (defn game [] 772 | (let [game (atom (reset-game {})) 773 | frame (JFrame. "Snake") 774 | panel (game-panel frame game) 775 | timer (Timer. turn-millis panel)] 776 | (doto panel 777 | (.setFocusable true) 778 | (.addKeyListener panel)) 779 | (doto frame 780 | (.add panel) 781 | (.pack) 782 | (.setVisible true)) 783 | (.start timer) 784 | [game, timer])) 785 | 786 | --------------------------------------------------------------------------------