From a3e2979f5fb981b9da291f1a237f97ec2a2683fa Mon Sep 17 00:00:00 2001 From: "Bastiaan M. van de Weerd" Date: Thu, 24 May 2012 21:59:17 +0200 Subject: [PATCH 1/4] Revisions, and updated to Coda 2 styling (using the `scope` attribute). --- Contents/Info.plist | 28 +- Contents/Resources/AutocompleteAdditions.txt | 6 - Contents/Resources/RegexSymbols.xml | 10 +- Contents/Resources/SyntaxDefinition.xml | 326 +++++++++---------- Contents/Resources/template.coffee | 110 +++---- 5 files changed, 218 insertions(+), 262 deletions(-) diff --git a/Contents/Info.plist b/Contents/Info.plist index 46a5c4e..e9505b7 100644 --- a/Contents/Info.plist +++ b/Contents/Info.plist @@ -1,20 +1,20 @@ - - CFBundleIdentifier - SEEMode.CoffeeScript - CFBundleName - CoffeeScript + + CFBundleIdentifier + SEEMode.CoffeeScript + CFBundleName + CoffeeScript CFBundleShortVersionString - 0.1 - CFBundleVersion - 0.1 + 0.1 + CFBundleVersion + 0.1 CFBundleGetInfoString - 0.1, Copyright Sean Durham 2010 - CFBundlePackageType - BNDL - CFBundleInfoDictionaryVersion - 6.0 - + 0.1, Copyright Sean Durham 2010 (revised for Coda 2 by Bastiaan van de Weerd) + CFBundlePackageType + BNDL + CFBundleInfoDictionaryVersion + 6.0 + diff --git a/Contents/Resources/AutocompleteAdditions.txt b/Contents/Resources/AutocompleteAdditions.txt index b6acee0..e69de29 100644 --- a/Contents/Resources/AutocompleteAdditions.txt +++ b/Contents/Resources/AutocompleteAdditions.txt @@ -1,6 +0,0 @@ -these -strings -are added -to the -autocomplete -dictionary \ No newline at end of file diff --git a/Contents/Resources/RegexSymbols.xml b/Contents/Resources/RegexSymbols.xml index b62fe37..911a732 100644 --- a/Contents/Resources/RegexSymbols.xml +++ b/Contents/Resources/RegexSymbols.xml @@ -1,22 +1,20 @@ - { } - + (?<=[\n\r]|^)[ \t]*class[ \t]+(?:[\w\d_\$]+\.)*([\w\d_\$]+)[ \t]*(?:\([^\)]*\))?[ \t]* - + - (?<=[\n\r]|^)[ \t]*(@*[\w\d_\$]+)[ \t]*[: =][ \t]*\(?[\w\d\s,]*\)?[ \t]+[-=]> + (?<=[\n\r]|^)[ \t]*(@*[\w\d_\$]+)[ \t]*[: =]\s*(?:\([^\n]*?\))?\s*[\-=]> - + # !([^\n\r]+) - \ No newline at end of file diff --git a/Contents/Resources/SyntaxDefinition.xml b/Contents/Resources/SyntaxDefinition.xml index 206f2e7..0bf5396 100644 --- a/Contents/Resources/SyntaxDefinition.xml +++ b/Contents/Resources/SyntaxDefinition.xml @@ -1,178 +1,154 @@ - - - CoffeeScript - - - - - - - - - - - - - - - - - if - unless - else - switch - when - then - - - for - while - until - do - - - new - this - - - break - continue - return - - - try - catch - throw - - - is - isnt - not - and - or - true - yes - on - false - no - of - off - in - - - - - - (?:[\(][\w\s\.\,\$]*[\)][\s])?[-=]> - [\s] - - - - - (?<=[^\w\d]|^)(((([0-9]+\.[0-9]*)|(\.[0-9]+))([eE][+\-]?[0-9]+)?[fFlL]?)|((([1-9][0-9]*)|0[0-7]*|(0[xX][0-9a-fA-F]+))(([uU][lL]?)|([lL][uU]?))?))(?=[^\w\d]|$) - - - - - (@\w*) - - - - (\w+(\s+)?:) - - - - (\b[A-Z]\w*) - - - - ### - ### - - - - - # - [\n\r] - - - - - " - (((?<!\\)(\\\\)*)|^)" - - - #{ - } - - - - - ' - (((?<!\\)(\\\\)*)|^)' - - - - - (?i)(?<=[=(,:\+~]|^|return|;)\s*/(?![/*+{}?]) - /[cgimosx]* - - - - - - + + CoffeeScript + + + + + + + this + + + + true + yes + on + false + no + off + + + arguments + process + console + window + document + $ + + + + if + unless + else + switch + when + then + + for + while + until + do + + break + continue + return + + try + catch + throw + + new + + + + is + isnt + not + and + of + or + in + ([\+\-\*\/\=\!\?\<\>\%]) + + + + {(?={) + (?<=})} + + + { + } + + + + + ([\-=]>) + + + \((?=[^\n\)]*?\)\s*[\-=]>) + \)\s*[\-=]> + + + [\(,]\s*(\w+)\s*(?=[=,\)]) + + + + + = + (?=[,\)]) + + + + + + NaN + (?<=[^\w\d]|^)(((([0-9]+\.[0-9]*)|(\.[0-9]+))([eE][+\-]?[0-9]+)?[fFlL]?)|((([1-9][0-9]*)|0[0-7]*|(0[xX][0-9a-fA-F]+))(([uU][lL]?)|([lL][uU]?))?))(?=[^\w\d]|$) + + + + (@\w*) + (\w+(\s+)?:) + (?:\D|[a-zA-Z@\$]\d)\.(\w+) + + + + (\$\w*) + + + + (\b[A-Z]\w*) + + + + ### + ### + + + + # + [\n\r] + + + + " + (((?<!\\)(\\\\)*)|^)" + + + + #{ + } + + + + + + ' + (((?<!\\)(\\\\)*)|^)' + + + + (?i)(?<=[=(,:\+~]|^|return|;)\s*/(?![/*+{}?]) + /[cgimosx]* + + + + `` + ` + + + + diff --git a/Contents/Resources/template.coffee b/Contents/Resources/template.coffee index 17b24c3..977d2e2 100644 --- a/Contents/Resources/template.coffee +++ b/Contents/Resources/template.coffee @@ -1,57 +1,67 @@ +### Comments ### - - - - -###------------------ - PASSING -------------------### - - -### COMMENTS ### - # A singe line comment should be colorized as a comment ### A multi-line comment should be colorized as a comment ### -answer = 4 + 5 # A comment trailing code should be colorized as a comment - - - +variable # A comment trailing code should be colorized as a comment + + +### OPERATORS ### + +a = 30 + 70 +s = 62 - 10 +m = 5 * 5 +d = 10 / NaN + + ### STRINGS ### -double_quote_string = "This string is in double quotes" -single_quote_string = 'This string is in single quotes' -string_segment = 'interpolated in-line' -interpolated_string = "This string is #{ string_segment }" - - - +theFirstString = 'is in single quotes' +thenThisString = "is in double quotes + and can span multiple lines" +interpolatedStrings = "contain code-colored #{Inter.pol() + "at#{"ti"}ons"}!" +heredocStrings = """ + are + rather #{"awesome"}. + """ + + ### FUNCTIONS ### -# A function with no arguments should be colorized as a function -$(document).ready -> - alert 'ready!' +withoutArguments = -> "in-line" +withoutArguments = => + "indented" +withArguments = (a, b) -> + (f > "indented") -# A function with arguments should be colorized as a function -square = (x) -> x * x +#-- Meh... +defaultArg = (u, ments, are='nice' in ['colors'] or not true?) -> + "...but the function definition's RPAREN (before the arrow) isn't, and + it fails with more complex things, which is a #{not are} shame" -# A function binding with no arguments should be colorized as a function -$('.element').bind 'click', (event) => - @customer.purchase @cart +#-- Fail +the = (second) -> (inline > "function is mean") and ((captures)=>"the first LPAREN too greedily")() -# A function binding with arguments should be colorized as a function -bound_function = => - # bound function code - - -### Embedded javascript ### + + +### VARIABLES ### + +Class.attribute = + property: yes + property: yes + +### REGULAR EXPRESSION ### +r = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/g + + +### EMBEDDED JAVASCRIPT ### apple = `function(){ - Apple = function (){ + apple = function(){ this.family = "Granny Smith"; this.peel = function(){ // Peel this apple. @@ -62,30 +72,8 @@ apple = `function(){ return Apple.new(); }` - -# Regular Expression -r = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/g -# Operators -a = 30 + 70 -s = 62 - 10 -m = 5 * 5 -d = 10/2 #division symbol should be interepereted as a regular expression - - - -###------------------ - FAILING -------------------### - - - - - - -###------------------ - PENDING -------------------### +#-- This was left from Sean Durham's work # Assignment: number = 42 @@ -111,5 +99,5 @@ race = (winner, runners...) -> alert "I knew it!" if elvis? # Array comprehensions: -cubes = (math.cube num for num in list) +cubes = (Math.cube num for num in list) From 57d20234c9ca894990bc3d9526100084fd5dff65 Mon Sep 17 00:00:00 2001 From: "Bastiaan M. van de Weerd" Date: Thu, 24 May 2012 22:13:42 +0200 Subject: [PATCH 2/4] Added function and class code folding (via `cabel`, via the Python mode). --- Contents/Resources/SyntaxDefinition.xml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Contents/Resources/SyntaxDefinition.xml b/Contents/Resources/SyntaxDefinition.xml index 0bf5396..ea317d5 100644 --- a/Contents/Resources/SyntaxDefinition.xml +++ b/Contents/Resources/SyntaxDefinition.xml @@ -149,6 +149,18 @@ ` + + + ^class[^\n]+\n + (?:\r?\n|\r)(?=(?:\r?\n|\r)(?:\r?\n|\r)\S|(?:\r?\n|\r)\S|\S) + + + + + ^(?'functionstartingwhitespace'[ \t]*).*?(?:[\(][\w\s\.\,\$]*[\)][\s])?[-=]> + (?:\r?\n|\r)(?=(?:\r?\n|\r)(?:\r?\n|\r)(?#see-insert-start-group:functionstartingwhitespace)\S|(?:\r?\n|\r)(?#see-insert-start-group:functionstartingwhitespace)\S|(?#see-insert-start-group:functionstartingwhitespace)\S|(?:\r?\n|\r)(?:\r?\n|\r)\S|(?:\r?\n|\r)\S|\S) + + From a5df49928ccfb9c07e61dbbda561be828ca4f8f2 Mon Sep 17 00:00:00 2001 From: "Bastiaan M. van de Weerd" Date: Thu, 24 May 2012 22:30:30 +0200 Subject: [PATCH 3/4] Updated the readme for the Coda 2 fork. Thanks, Sean. --- README.md | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 6d55cff..bef118c 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,16 @@ Read me ======= - -This is a Coda/SubEthaEdit syntax coloring mode for the CoffeeScript language. - -Special thanks to brajeshwar's Sass.Mode and jashkenas' TextMate bundle-- -I used them for reference while developing this mode. - - + +This is fork of Sean Durham's Coda/SubEthaEdit syntax coloring mode for the +CoffeeScript language, revisited for use with Coda 2. + +Special thanks to brajeshwar's Sass.Mode and jashkenas' TextMate bundle--Sean +apparently used them for reference while developing this mode. + Installation ============ - Download and unpack either the ZIP or TAR version of the CoffeeScript mode. - Rename the unzipped directory to 'CoffeeScript.mode'. - Coda: - Manually copy the CoffeeScript.mode directory into ~/Library/Application\ Support/Coda/Modes/. -- SubEthaEdit: - Open the CoffeeScript.mode file from within SubEthaEdit using the File > Open command - or by dragging the CoffeeScript.mode file onto the SubEthaEdit application icon in the dock. - -Extras ------------- -Chendrix made an alternate [light-on-dark color scheme](https://github.com/chendrix/Specials-Board) for those who prefer the dark side. - + Manually copy the CoffeeScript.mode directory into ~/Library/Application\ Support/Coda 2/Modes/. \ No newline at end of file From 038149de00421a78944f322eb902f2b1fdbea014 Mon Sep 17 00:00:00 2001 From: "Bastiaan M. van de Weerd" Date: Fri, 25 May 2012 01:52:29 +0200 Subject: [PATCH 4/4] Hacky implementation of properly-recognised interpolated strings and default arguments (using whitespace padding). Also disabled function block folding, as it was giving issue (to be investigated). --- Contents/Resources/RegexSymbols.xml | 1 - Contents/Resources/SyntaxDefinition.xml | 51 +++++++++++++++++-------- Contents/Resources/template.coffee | 12 +++--- 3 files changed, 43 insertions(+), 21 deletions(-) diff --git a/Contents/Resources/RegexSymbols.xml b/Contents/Resources/RegexSymbols.xml index 911a732..80e935b 100644 --- a/Contents/Resources/RegexSymbols.xml +++ b/Contents/Resources/RegexSymbols.xml @@ -13,7 +13,6 @@ (?<=[\n\r]|^)[ \t]*(@*[\w\d_\$]+)[ \t]*[: =]\s*(?:\([^\n]*?\))?\s*[\-=]> - # !([^\n\r]+) diff --git a/Contents/Resources/SyntaxDefinition.xml b/Contents/Resources/SyntaxDefinition.xml index ea317d5..c8df9f8 100644 --- a/Contents/Resources/SyntaxDefinition.xml +++ b/Contents/Resources/SyntaxDefinition.xml @@ -3,6 +3,13 @@ CoffeeScript + @@ -19,6 +26,9 @@ no off + null + undefined + arguments process @@ -36,6 +46,9 @@ when then + class + extends + for while until @@ -47,6 +60,7 @@ try catch + finally throw new @@ -60,7 +74,7 @@ of or in - ([\+\-\*\/\=\!\?\<\>\%]) + ([\+\-\*\/\=\!\?\<\>\%]) @@ -74,26 +88,27 @@ - ([\-=]>) + ([\-=]>) - - \((?=[^\n\)]*?\)\s*[\-=]>) - \)\s*[\-=]> + + \((?=[^\n\)]*?\)\s*[\-=]>) + \)\s*[\-=]> [\(,]\s*(\w+)\s*(?=[=,\)]) - + = - (?=[,\)]) - + \s(?=[,\)]) + NaN + infinity (?<=[^\w\d]|^)(((([0-9]+\.[0-9]*)|(\.[0-9]+))([eE][+\-]?[0-9]+)?[fFlL]?)|((([1-9][0-9]*)|0[0-7]*|(0[xX][0-9a-fA-F]+))(([uU][lL]?)|([lL][uU]?))?))(?=[^\w\d]|$) @@ -125,12 +140,16 @@ " (((?<!\\)(\\\\)*)|^)" - - - #{ + + #(?={) } - + + + + (?<={)\s + \s(?=}) + + @@ -150,17 +169,19 @@ - + diff --git a/Contents/Resources/template.coffee b/Contents/Resources/template.coffee index 977d2e2..efe38a7 100644 --- a/Contents/Resources/template.coffee +++ b/Contents/Resources/template.coffee @@ -16,18 +16,18 @@ s = 62 - 10 m = 5 * 5 d = 10 / NaN - ### STRINGS ### theFirstString = 'is in single quotes' thenThisString = "is in double quotes and can span multiple lines" -interpolatedStrings = "contain code-colored #{Inter.pol() + "at#{"ti"}ons"}!" heredocStrings = """ are rather #{"awesome"}. """ +#-- Meh... +interpolatedStrings = "contain code-colored #{ Inter.pol() + "ation, #{"but currently only when whitespace-padded"}" }..." ### FUNCTIONS ### @@ -37,15 +37,17 @@ withoutArguments = => withArguments = (a, b) -> (f > "indented") -#-- Meh... -defaultArg = (u, ments, are='nice' in ['colors'] or not true?) -> +#-- Meh... (again with the whitespace-padding (end only))----v +defaultArg = (u, ments, are='nice' in ['colors'] or not true? , man) -> "...but the function definition's RPAREN (before the arrow) isn't, and it fails with more complex things, which is a #{not are} shame" #-- Fail the = (second) -> (inline > "function is mean") and ((captures)=>"the first LPAREN too greedily")() - +#-- Fail with foldable block +foo 'bar', -> + "baz" ### VARIABLES ###