[Sciviews-commits] r186 - in komodo/SciViews-K: . content/js templates/R udl

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Sep 12 23:48:03 CEST 2009


Author: phgrosjean
Date: 2009-09-12 23:48:02 +0200 (Sat, 12 Sep 2009)
New Revision: 186

Added:
   komodo/SciViews-K/templates/R/R syntax test.R
Modified:
   komodo/SciViews-K/content/js/misc.js
   komodo/SciViews-K/content/js/prefs.js
   komodo/SciViews-K/sciviewsk-0.8.1-ko.xpi
   komodo/SciViews-K/udl/Rlex.udl
Log:
Bugs fixes and enhancement of R syntax highlighting

Modified: komodo/SciViews-K/content/js/misc.js
===================================================================
--- komodo/SciViews-K/content/js/misc.js	2009-09-10 09:43:09 UTC (rev 185)
+++ komodo/SciViews-K/content/js/misc.js	2009-09-12 21:48:02 UTC (rev 186)
@@ -10,10 +10,9 @@
 // sv.misc.searchBySel();       // Search next using current selection
 // sv.misc.showConfig();        // Show Komodo configuration page
 // sv.misc.swapQuotes();        // Swap single and double quotes in selection
-// sv.misc.pathToClipboard(); // Copy file path to clipboard
+// sv.misc.pathToClipboard();   // Copy file path to clipboard
 // sv.misc.unixPathToClipboard(); // Copy file path in UNIX format to clipboard
-// sv.misc.timeStamp(); // Stamp text with current date/time
-// sv.misc.delLine(); // Delete current line in buffer
+// sv.misc.timeStamp();         // Stamp text with current date/time
 ////////////////////////////////////////////////////////////////////////////////
 
 // Define the 'sv.misc' namespace
@@ -265,9 +264,3 @@
         sv.log.exception(e, "sv.misc.timeStamp() error");
     }
 }
-
-// Delete current line
-// not really necessary. to be removed??
-sv.misc.delLine = function () {
-    ko.commands.doCommand('cmd_lineDelete');
-}

Modified: komodo/SciViews-K/content/js/prefs.js
===================================================================
--- komodo/SciViews-K/content/js/prefs.js	2009-09-10 09:43:09 UTC (rev 185)
+++ komodo/SciViews-K/content/js/prefs.js	2009-09-12 21:48:02 UTC (rev 186)
@@ -92,20 +92,30 @@
 sv.prefs.mru("breaks", true, '"Sturges"|"Scott"|"Freedman-Diaconis"|10', "|");
 sv.prefs.mru("corMethod", true, '"pearson"|"kendall"|"spearman"', "|");
 
+// Var.equal (for t-test)
+sv.prefs.mru("var.equal", true, 'TRUE|FALSE', "|");
+
 //// Various graph parameters //////////////////////////////////////////////////
 // Colors
 sv.prefs.mru("col", true,
+    '1|2|3|4|5|6|7|8|"#838383"|' +
     '"black"|"red"|"blue"|"green"|"gray"|"darkred"|"darkblue"|"darkgreen"|' +
-	'"darkgray"|"lightblue"|"lightgreen"|"lightgray"|"gray10"|"gray20"|' +
-    '"gray30"|"gray40"|"gray50"|"gray60"|"gray70"|"gray80"|"gray90"|"white|"' +
-    '"transparent"|"wheat"|"cornsilk"|"yellow"|"orange"|"tan"|"tomato"|' +
-    '"firebrick"|"magenta"|"pink"|"salmon"|"violet"|"purple"|"plum"|"cyan"|' +
-    '"lavender"|"navy"|"azure"|"aquamarine"|"turquoise"|"khaki"|"gold"|' +
-    '"bisque"|"beige"|"brown"|"chocolate"', "|");
+	'"darkgray"|"mistyrose"|"lightblue"|"lightgreen"|"lightgray"|"gray10"|' +
+    '"gray20"|"gray30"|"gray40"|"gray50"|"gray60"|"gray70"|"gray80"|"gray90"|' +
+    '"white"|"transparent"|"wheat"|"cornsilk"|"yellow"|"orange"|"tan"|' +
+    '"tomato"|"firebrick"|"magenta"|"pink"|"salmon"|"violet"|"purple"|' +
+    '"plum"|"cyan"|"lightcyan"|"lavender"|"navy"|"azure"|"aquamarine"|' +
+    '"turquoise"|"khaki"|"gold"|"bisque"|"beige"|"brown"|"chocolate"', "|");
 
 // Type
 sv.prefs.mru("type", true, '"p"|"l"|"b"|"c"|"o"|"h"|"s"|"S"|"n"', "|");
 
+// Log
+sv.prefs.mru("log", true, '""|"x"|"y"|"xy"', "|");
+
+// Add
+sv.prefs.mru("add", true, 'TRUE|FALSE', "|");
+
 // Pch
 sv.prefs.mru("pch", true,
     '0|1|2|3|3|4|5|6|7|8|9|10|11|12|13|14|15|15|17|18|19|20|21|22|23|24|25|' +
@@ -118,6 +128,10 @@
 // Lwd
 sv.prefs.mru("lwd", true, '1|2|3', "|");
 
+// Notch (for boxplot)
+sv.prefs.mru("notch", true, 'TRUE|FALSE', "|");
+
+
 //// various mrus for 'car' graphs /////////////////////////////////////////////
 sv.prefs.mru("reg.line", true, 'FALSE|lm', "|");
 sv.prefs.mru("smooth", true, 'TRUE|FALSE', "|");

Modified: komodo/SciViews-K/sciviewsk-0.8.1-ko.xpi
===================================================================
(Binary files differ)

Added: komodo/SciViews-K/templates/R/R syntax test.R
===================================================================
--- komodo/SciViews-K/templates/R/R syntax test.R	                        (rev 0)
+++ komodo/SciViews-K/templates/R/R syntax test.R	2009-09-12 21:48:02 UTC (rev 186)
@@ -0,0 +1,241 @@
+# SciViews-K/Komodo R syntax lexer test
+# Version 1.0, Ph. Grosjean (phgrosjean at sciviews.org)
+
+## Quick overview ##############################################################
+# Most features of the R syntax lexer are expressed here:
+#! Shebang line, or R Wiki output style (same as string style)
+`cube` <- function (x, na.rm = FALSE) {
+    if (!is.numeric(x))
+        stop("'x' must be a numeric vector")
+    if (isTRUE(na.rm)) x <- x[!is.na(x)]
+    return(x^3L)
+}
+cube(iris$Petal.Length, na.rm = TRUE)
+base::ls()
+base:::search()
+# 1) Keywords, names, operators, strings and comments are colored differently
+#    (depending on the color scheme you choose in Preferences... -> Editor ->
+#    Fonts and Colors -> Lang-Specific -> R). Please, note that the 'Default'
+#    mode of Komodo 5.x uses the same color for 'identifiers' and 'variables'.
+#    Either switch to another mode, or customize it by changing the color of one
+#    of these two styles to see all features discussed in this document!
+# 2) Currently keywords is a fixed list of objects in recommended + SciViews
+#    R packages (more dynamic choice planned for the future).
+# 3) All R numbers are recognized, including complex, hex, etc.
+# 4) List/data frames variables (like 'var' in l$var), S4 object slots (like
+#    'slot' in obj at slot), function arguments (like 'x' or 'na.rm' here above)
+#    and namespaces (like 'base::' or 'base:::' here above) are colored
+#    differently. Also, using '=' for assignment instead of '<-' causes the
+#    variable to be colored as a function argument. This is not a bug, but a
+#    feature: it is there to show you the danger of using '=' for assignation.
+#    But if you consistently use it, then syntax highlighting will be consistent
+#    too in coloring assigned variables that way...
+# 5) There are small vertical indentation marks (see after 'if (!is.numeric').
+# 6) Move the cursor on top of parentheses or brackets and you will see the
+#    bracket-matching feature coloring the pair of corresponding brackets.
+# 7) There is automatic calculation of folding marks on pairs of '()' and '{}'.
+#    Click on the little square with a minus sign in the margin in fromt of
+#    `cube` <- .... and you fold the function body. Click again to unfold it.
+#    There is also a manual folding tag: #{{ .... #}}, like hereunder.
+# "Manual" folding indicator (so-called, "comment folding") section here:
+#{{
+# You can fold this content between the #{{ and #}} marks!   
+#}}
+# 8) Wrong characters in R strings are highlighted differently. For instance,
+#    you are not supposed to use '\0' inside R strings, and R will end the
+#    string there and will complain with a warning. The syntax lexer detects
+#    such wrong characters and colorize them differently, like here:
+stringWithNull <- 'A string with a null\0 character'
+#    The same style is also used to colorize the end of invalid numbers:
+10.5e-3iWrongNumberEnd + 1
+
+
+## More extensive tests ########################################################
+
+# Keywords & builtins should be highlighted in a specific color ("keywords")
+c(TRUE, FALSE, NA)
+ls.str
+as.data.frame
+as.data.frame.data.frame
+# but not
+nokeyword
+NA_nokey_
+mean.newobj
+as.data.frame.myobj
+
+# List components and S4 object slots are colored differently ("variables")
+iris$Species
+obj at slot
+# ... even if the component has the same name as a keyword
+mean
+# but, different context, different style:
+dat$mean
+
+is.data.frame
+# but
+obj at is.data.frame
+
+# Spaces are allowed and carriage return and/or comments too
+# (note: ugly and not advised, but syntactically correct!)
+iris      $     Species
+iris$
+                Petal.Length
+iris      $ # Comment in between
+    Sepal.Length
+obj       @     slot <- NULL
+obj@
+    slot <- 1
+obj   @ # Do not format code this way, although it is correct for the parser!
+    slot
+
+# When '$' or '@' are followed by something else than an identifier, it goes
+# back to default mode and does not try to figure out if the syntax is correct
+mydf$`item`; mydf$"item"; mydf$'item'  # These are correct constructions
+mydf$["item"]; mydf$(1); mydf$1 # Incorrect but the lexer just goes on!
+
+# Formula items are treated as usual identifiers/keywords/numbers/operators
+# One could have used a special color to highlight a whole formula, but then,
+# one looses the information about good/wrong numbers, or good/wrong use of
+# keywords (here, we see that 'I()' is a known function, but 'cos' also,...
+# and it would have been better to use a different variable name than 'cos').
+lm(y ~ I(x^2) + cos * z^2 | w - 1, data = mydf)
+
+# Named arguments are colorized in the right color, even if they match keywords:
+mean
+# or
+file
+# but
+myfun(mean = 5, file = "temp")
+
+# There is a special mode for function definition that does a pretty good job
+# on finding and coloring the name of the defined arguments, even when the code
+# spans on multiple lines and has various comments added, like here:
+myfun2 <- function (  # A function doing something
+    # The complete description of ''myfun2()'' that does something really very,
+    # very useful!
+    x,               # A matrix of numerical values
+    y,               # Another matrix of numbers
+    na.rm = FALSE,   # Do we eliminate missing data
+    text = "string", # A string to use somewhere
+    ...)             # Further arguments passed to the plot function
+
+# More particularly, notice how 'x' is colored differently according to the
+# context:
+x <- 1 # Assignation with '<-'
+foo <- function (x) # Here is an argument definition
+    return(x) # Here it is the local variable inside my function
+foo(x)  # Here, it is the variable 'x' provided for argument 'x = ', same as:
+foo(x = x)
+foo(x = 3) # Here the argument 'x' receives the value 3
+
+# One bug that can hardly be corrected (but it occurs with a strange layout
+# of the code, when the '=' sign is placed on another line). In the function
+# definition, it works fine:
+aa <- function (arg1
+                  = 1,
+                arg2 # Ugly, but valid R syntax!!!
+                  = 2) return("hello!")
+# But outside of function definition, named arguments are not colored correctly
+# any more if the '=' sign is on another line:
+aa(arg1 = 10, arg2
+   = 11) #'arg1' color is correct, but not 'arg2'!
+
+# Warning! The same 'arguments' color is used when one assign values to a
+# variable using '=' instead of '<-' (this could be considered as a feature to
+# warn user about ambiguity, providing that the "usual" assignation operator in
+# R is '<-')
+mydf <- data.frame(x = 1:10)
+# fine, but
+mydf = data.frame(x = 1:10)
+
+
+# Namespaces and package names are also colored that way:
+base::getwd()
+stats:::t.test.default()
+# Note that 't.test.default' is *not* colored as a keyword since it is not in
+# the list of visible (exported) items!
+# Spaces are allowed (but ugly, don't use!). Carriage return not allowed!
+base      ::     search()
+stats     :::    t.test.default()
+
+
+# Numbers are colored differently
+# All these numbers are correct
+1; 10; 0.1; .1; 1e-7; 3E6; 2e; 3e+
+# Numbers can be represented in hexadecimal notation
+0x000ADFE; 0xa5b; 0x00aA3
+# Numbers ending with 'L' are considered integers (possibly converted to
+# integers with a warning by R)
+10L; 1.1L; 1.L; 1e2L; 1.1e+3L; 1e-3L; 0xaDE012FL
+# Numbers ending with 'i' are complex
+2i; 4.1i; 13 + 12i; 1e-2i; 0x003i
+# These numbers are incorrect (note that the end is colored as error)
+4iL; 3Li; 0x001iL; 0x001Li; 0x00G3; 1e-0.9; 14e+3iVar 
+
+
+# String (three types, surrounded by "", '' or ``, are recognized)
+"This is a correct string"
+'Idem'
+`My unusual variable name!`
+# Escaped quotes are correctly recognized
+"This is \"quoted\" and correctly highlighted"
+'This is \'quoted\' and correctly highlighted'
+# Strings can span on multiple lines
+"This is a
+multiline
+string"
+# The R syntax lexer recognizes correct escapes
+" Test of escapes \"\'\n\r\t\f\\\v\a\b\1\12\238\x1
+\xA\xF5\x2a3\u0\uAF20\u{0AF1}\U13AFD\U{14530EFA}"
+# But it colorizes differently wrong ones
+"Wrong escapes \d\9\xS\uP\u{}\u{h}\uG\U{}\UY\U{h}\0
+gffg\00dff\000fg\u{0AF1ddd2BF}fddf\U{14530EFA2}"
+
+
+# Operators, all operators are detected:
+1:5; 1 + 1; 1 != 2; 3 %% 2; 3 %/% 2; dat %o% 1:3
+# including custom ones...
+1 %myop% 2
+
+
+# Automatic indentation with vertical indentation marks and code folding
+for (i in 1:10) {
+    mean(
+        if (i == 2) {
+            i
+        } else {
+            i + 1
+        }
+    )
+}
+# There is also a "comment folding" item: start by '#{{' and end by '#}}'
+# Start folding here
+#{{
+# This comment is included in a custom folding
+# Of course, commands can be embedded too
+1+1
+# and folding nicely nest with usual command folding on () or {}
+for (i in 1:10) {
+    cat("Hello world!\n")
+}
+#}}
+# Not included in the comment folding part
+ls()
+cube <- function (x, na.rm = TRUE) {
+    x^3
+}
+
+
+## To do...
+# A more dynamic recognition of keywords, taking into account packages loaded
+# with library() or require()... problem with namespace => recognize them too!
+
+# Since we are analyzing NAMESPACE: propose also a different coloration for
+# exported items (reuse SSL_REGEX?)
+
+# Is it possible to give more meaningful names to the various styles that
+# appear in the preferences box? And why are there other tags (cdata, tag, ...)?
+
+# Colorize Rd files, DESCRIPTION, NAMESPACE and Sweave    
+
+# Colorize wiki elements differently

Modified: komodo/SciViews-K/udl/Rlex.udl
===================================================================
--- komodo/SciViews-K/udl/Rlex.udl	2009-09-10 09:43:09 UTC (rev 185)
+++ komodo/SciViews-K/udl/Rlex.udl	2009-09-12 21:48:02 UTC (rev 186)
@@ -42,6 +42,7 @@
 # We have to specify the min and max styles we'll be referring to
 # Here are the available styles (see include/Scintilla.iface):
 #SCE_UDL_SSL_DEFAULT=31
+#Scintilla reserves styles 32->39 for its own use!
 #SCE_UDL_SSL_COMMENT=40
 #SCE_UDL_SSL_COMMENTBLOCK=41
 #SCE_UDL_SSL_NUMBER=42
@@ -57,7 +58,7 @@
 # If the language has keywords, specify which style needs to be transformed
 keyword_style SSL_IDENTIFIER => SSL_WORD
 
-# Define keywords (TODO: update this list)
+# Define keywords (TODO: update this list to latest R version)
 keywords [
 #{{
 # Reserved keywords
@@ -2623,44 +2624,52 @@
 
 # Some info on the styles we're using here
 pattern NMSTART = 'a-zA-Z\.\x80-\xff'   # inside cset
-pattern NMCHAR = '_$NMSTART\d'          # inside cset
-pattern CS = '\w\d_\.\x80-\xff'         # inside cset
+pattern CS = '_$NMSTART\d'              # inside cset
 pattern WS = '\s\t\r\n'                 # inside cset
 pattern OP = '!%&\(\)\*\+,-\/:;<=>\?@\[\]\^\{\}~|\$'
 
 # Initial IN_SSL_DEFAULT
 state IN_SSL_DEFAULT:
 
+# A special mode for function definition
+'function' : paint(upto, SSL_DEFAULT), paint(include, SSL_IDENTIFIER), => IN_SSL_FUNDEF
+
+# This is shebang line or the R wiki construct used for R output
+/^#!/ : paint(upto, SSL_DEFAULT), paint(include, SSL_COMMENT), => IN_SSL_OUTPUT
+
 # One-line comments end at end-of-line
-'#' : paint(upto, SSL_DEFAULT),  => IN_SSL_COMMENT_1
-# This is the R wiki construct used for R output, not used (yet) here
-#'#!' : paint(upto, SSL_DEFAULT), => IN_SSL_COMMENTBLOCK_1
+'#' : paint(upto, SSL_DEFAULT),  => IN_SSL_COMMENT
 
 # Variables are always after $ or @ in list$var or obj at slot
-/[\$@](?=[$NMSTART])/ : paint(upto, SSL_DEFAULT), \
+/[\$@]/ : paint(upto, SSL_DEFAULT), \
     paint(include, SSL_OPERATOR), => IN_SSL_VARIABLE_1
 
-# We use also SSL_VARIABLE style to colorize function arguments (but also assignations with '=')
-# That is: arg/var = (but not var ==)
-/[$NMSTART](?=[$CS]*[$WS]*\=[^\=])/ :  paint(upto, SSL_DEFAULT), => IN_SSL_ARGUMENT_1
+# We use also SSL_VARIABLE style to colorize function arguments (but also
+# assignations with '='). That is: arg/var = (but not var ==)
+/[$NMSTART](?=[$CS]*[$WS]*\=[^\=])/ : paint(upto, SSL_DEFAULT), => IN_SSL_ARGUMENT
 
+# SSL_VARIABLE also colorizes namespaces ns in ns::fun() or ns:::fun()
+/[$NMSTART](?=[$CS]*[$WS]*::)/ : paint(upto, SSL_DEFAULT), => IN_SSL_NAMESPACE
+
+# Stay in SSL_DEFAULT mode, spaces have no meaning in R!
 /[$WS]+/  : #stay
 
+# Enter string mode
 '"' : paint(upto, SSL_DEFAULT), => IN_SSL_DSTRING
 '\'' : paint(upto, SSL_DEFAULT), => IN_SSL_SSTRING
 '`' : paint(upto, SSL_DEFAULT), => IN_SSL_BSTRING
 
 # Go process a number, try to do it in regexes
 # Hexadecimal numbers: 0x0A or 0x10L or 0xFF23i
-/0[Xx][0-9a-fA-F]+[Li]?/ : paint(upto, SSL_DEFAULT), paint(include, SSL_NUMBER)
+/0[Xx][0-9a-fA-F]+[Li]?/ : paint(upto, SSL_DEFAULT), paint(include, SSL_NUMBER), => IN_SSL_NUMBER_DONE
+# Beginning of any other number
 /(?<![$CS])[-+]?\d/ : paint(upto, SSL_DEFAULT), => IN_SSL_NUMBER_INT
-
-# A "." can start a number only if it doesn't follow a
-# name, many keywords, string, regex, number, or a few
-# closing operators.
+# A "." can start a number only if it doesn't follow a name, many keywords,
+# string, regex, number, or a few closing operators.
 /[-+]?\.\d/ : paint(upto, SSL_DEFAULT), => IN_SSL_NUMBER_FLOAT
 
-/[$NMSTART][$CS]*/ : paint(upto, SSL_DEFAULT), paint(include, SSL_IDENTIFIER)
+# Paint an identifier
+/[$NMSTART][$CS]*/ : paint(upto, SSL_DEFAULT), paint(include, SSL_IDENTIFIER), => IN_SSL_DEFAULT
 
 # Now a bunch of operators
 # Multi-char operators first
@@ -2669,33 +2678,43 @@
 /[$OP]/ : paint(upto, SSL_DEFAULT), redo, => IN_SSL_OP1
 
 
-#### Non-keyword identifiers (slot names and list elements) ####################
+#### "Non-identifiers" names (slot names and list elements) ####################
 state IN_SSL_VARIABLE_1:
-/(?=.)/ : no_keyword, paint(include, SSL_VARIABLE), => IN_SSL_VARIABLE_2
+/[$WS]/ : # stay
+'#' : paint(upto, SSL_DEFAULT),  => IN_SSL_VARIABLE_COMMENT # Comments allowed!
+/[$NMSTART]/ : paint(upto, SSL_DEFAULT), => IN_SSL_VARIABLE_2
+/[^$WS$NMSTART#]/ : paint(upto, SSL_DEFAULT), redo, => IN_SSL_DEFAULT
 
 state IN_SSL_VARIABLE_2:
 /[$CS]/ : #stay
-/[^$CS]/ : paint(upto, SSL_VARIABLE), no_keyword, => IN_SSL_DEFAULT
+/[^$CS]/ : paint(upto, SSL_VARIABLE), redo, no_keyword, => IN_SSL_DEFAULT
 
+state IN_SSL_VARIABLE_COMMENT:
+/[\r\n]/ : paint(upto, SSL_COMMENT), => IN_SSL_VARIABLE_1
 
+
 #### Arguments in functions fun(arg= ), or assignation using =, like a = 1 #####
-state IN_SSL_ARGUMENT_1:
-/(?=.)./ : no_keyword, paint(include, SSL_VARIABLE), => IN_SSL_ARGUMENT_2
+state IN_SSL_ARGUMENT:
+/[$CS]/ : #stay
+/[^$CS]/ : paint(upto, SSL_VARIABLE), redo, no_keyword, => IN_SSL_DEFAULT
 
-state IN_SSL_ARGUMENT_2:
+
+#### Namespace of package name is ns::fun or ns:::fun ##########################
+state IN_SSL_NAMESPACE:
 /[$CS]/ : #stay
 /[^$CS]/ : paint(upto, SSL_VARIABLE), redo, no_keyword, => IN_SSL_DEFAULT
 
 
 ##### Comments #################################################################
-state IN_SSL_COMMENT_1 : 
+# This is used in R Wiki to denote R output
+state IN_SSL_OUTPUT: # SSL_COMMENTBLOCK not different from SSL_COMMENT
+#/[\r\n]/ : paint(upto, SSL_COMMENTBLOCK), => IN_SSL_DEFAULT
+/[\r\n]/ : paint(upto, SSL_STRING), => IN_SSL_DEFAULT # Use SSL_STRING instead
+
+state IN_SSL_COMMENT:
 /[\r\n]/ : paint(upto, SSL_COMMENT), => IN_SSL_DEFAULT
 
-#state IN_SSL_COMMENTBLOCK_1 : 
-##/[\r\n]/ : paint(include, SSL_COMMENTBLOCK), => IN_SSL_DEFAULT
-#/[\r\n]/ : paint(upto, SSL_COMMENTBLOCK), => IN_SSL_DEFAULT
 
-
 ##### Strings ##################################################################
 # Note: we use SSL_REGEX (not used in R) to denote wrong escaped characters
 state IN_SSL_DSTRING:
@@ -2757,42 +2776,55 @@
 state IN_SSL_NUMBER_INT :
 /\d/ : #stay
 '.' : => IN_SSL_NUMBER_FLOAT
-'L' : paint(include, SSL_NUMBER) => IN_SSL_DEFAULT # Integer
-'i' : paint(include, SSL_NUMBER) => IN_SSL_DEFAULT # Complex number
+'L' : paint(include, SSL_NUMBER) => IN_SSL_NUMBER_DONE # Integer
+'i' : paint(include, SSL_NUMBER) => IN_SSL_NUMBER_DONE # Complex number
 /[Ee][-+]?/ : => IN_SSL_NUMBER_EXP
-/_a-zA-Z/ : paint(upto, SSL_REGEX), redo, => IN_SSL_DEFAULT # Wrong number!
-/./ : paint(upto, SSL_NUMBER), redo, => IN_SSL_DEFAULT
+/_a-zA-Z/ : paint(upto, SSL_REGEX), redo, => IN_SSL_NUMBER_WRONG # Wrong number!
+/$/ : paint(upto, SSL_NUMBER) => IN_SSL_DEFAULT # End of line
+/./ : paint(upto, SSL_NUMBER), redo, => IN_SSL_NUMBER_DONE
 
 # Note 'L' suffix allowed in float (R converts to integer with a warning)
 state IN_SSL_NUMBER_FLOAT:
 /[\d]/ : #stay
-'L' : paint(include, SSL_NUMBER) => IN_SSL_DEFAULT # Integer
-'i' : paint(include, SSL_NUMBER) => IN_SSL_DEFAULT # Complex number
+'L' : paint(include, SSL_NUMBER) => IN_SSL_NUMBER_DONE # Integer
+'i' : paint(include, SSL_NUMBER) => IN_SSL_NUMBER_DONE # Complex number
 /[Ee][-+]?/ : => IN_SSL_NUMBER_EXP
-/_a-zA-Z/ : paint(upto, SSL_REGEX), redo, => IN_SSL_DEFAULT # Wrong number!
-/./ : paint(upto, SSL_NUMBER), redo, => IN_SSL_DEFAULT
+/_a-zA-Z/ : paint(upto, SSL_REGEX), redo, => IN_SSL_NUMBER_WRONG # Wrong number!
+/$/ : paint(upto, SSL_NUMBER) => IN_SSL_DEFAULT # End of line
+/./ : paint(upto, SSL_NUMBER), redo, => IN_SSL_NUMBER_DONE
 
 state IN_SSL_NUMBER_EXP:
 /\d/ : #stay
-'L' : paint(include, SSL_NUMBER) => IN_SSL_DEFAULT
-'i' : paint(include, SSL_NUMBER) => IN_SSL_DEFAULT # Complex number
-/[^\d]/ : paint(upto, SSL_NUMBER), redo, => IN_SSL_DEFAULT
+'L' : paint(include, SSL_NUMBER) => IN_SSL_NUMBER_DONE
+'i' : paint(include, SSL_NUMBER) => IN_SSL_NUMBER_DONE # Complex number
+/$/ : paint(upto, SSL_NUMBER) => IN_SSL_DEFAULT # End of line
+/[^\d]/ : paint(upto, SSL_NUMBER), redo, => IN_SSL_NUMBER_DONE
 
+state IN_SSL_NUMBER_DONE:
+/$/ : => IN_SSL_DEFAULT # End of line
+/[$CS]/ : => IN_SSL_NUMBER_WRONG #This is wrong!
+/[^$CS]/ : redo, => IN_SSL_DEFAULT
 
+state IN_SSL_NUMBER_WRONG:
+/$/ : paint(upto, SSL_REGEX), no_keyword, => IN_SSL_DEFAULT # End of line
+/[$CS]/ : #stay
+/[^$CS]/ : paint(upto, SSL_REGEX), redo, no_keyword, => IN_SSL_DEFAULT
+
+
 ##### Operators ################################################################
 # If we're here, we've painted the previous part, and 
 # just need to figure out which operator we have, doing
-# greedy left-to-right matching ('+++' parses as /++/, /+/)
+# greedy left-to-right matching (':::' parses as /::/, /:/)
 state IN_SSL_OP1:
+# Special case for opening parentheses: we need to know if we define function
+# arguments 'myfun <- function (', then, we popup this mode each time we got
+# ',' or ')'
+'(' : paint(include, SSL_OPERATOR), spush_check(IN_SSL_NO_ARGSDEF), => IN_SSL_NO_ARGSDEF
+',' : paint(upto, SSL_DEFAULT), paint(include, SSL_OPERATOR), spop_check, => IN_SSL_DEFAULT
+')' : paint(upto, SSL_DEFAULT), paint(include, SSL_OPERATOR), spop_check, => IN_SSL_DEFAULT
 # Single-char operator -- all ops work as standalone chars
 /[$OP](?:(?![$OP])|$)/ : paint(include, SSL_OPERATOR), => IN_SSL_DEFAULT
 # Otherwise look from longest to smallest
-#/%.+%/  : paint(include, SSL_OPERATOR), => IN_SSL_DEFAULT
-#'%in%'  : paint(include, SSL_OPERATOR), => IN_SSL_DEFAULT
-#'%*%'   : paint(include, SSL_OPERATOR), => IN_SSL_DEFAULT
-#'%/%'   : paint(include, SSL_OPERATOR), => IN_SSL_DEFAULT
-#'%o%'   : paint(include, SSL_OPERATOR), => IN_SSL_DEFAULT
-#'%x%'   : paint(include, SSL_OPERATOR), => IN_SSL_DEFAULT
 ':::'    : paint(include, SSL_OPERATOR), => IN_SSL_DEFAULT
 '<<-'    : paint(include, SSL_OPERATOR), => IN_SSL_DEFAULT
 '->>'    : paint(include, SSL_OPERATOR), => IN_SSL_DEFAULT
@@ -2809,9 +2841,46 @@
 # The fallback
 /[$OP]/ : paint(include, SSL_OPERATOR), => IN_SSL_DEFAULT
 
-#### End States ################################################################
 
+##### Special treatment for function arguments #################################
+# We are defining a function like 'myfun <- function'
+# Allowed items: $WS or a comment, or '(' that switches to IN_SSL_ARGSDEF mode
+state IN_SSL_FUNDEF:
+/[$WS]/ : # stay
+'#' : paint(upto, SSL_DEFAULT),  => IN_SSL_FUNDEF_COMMENT
+'(' : paint(upto, SSL_DEFAULT), paint(include, SSL_OPERATOR), spush_check(IN_SSL_ARGSDEF), => IN_SSL_ARGSDEF
+/[^$WS#\(]/ : paint(upto, SSL_DEFAULT), redo, => IN_SSL_DEFAULT # Exit
 
+state IN_SSL_FUNDEF_COMMENT:
+/[\r\n]/ : paint(upto, SSL_COMMENT), => IN_SSL_FUNDEF
+
+# Mode started after 'function ('
+state IN_SSL_ARGSDEF:
+/(?<=,)[$WS]/ : spush_check(IN_SSL_ARGSDEF) # Push again
+/(?<=,)#/ : spush_check(IN_SSL_ARGSDEF), paint(upto, SSL_DEFAULT), => IN_SSL_ARGSDEF_COMMENT 
+/(?<=,)[$NMSTART]/ : spush_check(IN_SSL_ARGSDEF), paint(upto, SSL_DEFAULT), paint(include, SSL_VARIABLE), => IN_SSL_ARGUMENT
+/(?<=,)[^$WS$NMSTART#]/ : spush_check(IN_SSL_ARGSDEF), paint(upto, SSL_DEFAULT), redo, => IN_SSL_DEFAULT
+/(?<=\))./ : paint(upto, SSL_DEFAULT), redo, => IN_SSL_DEFAULT    # End of ARGSDEF mode
+/(?<=\))$/ : paint(upto, SSL_DEFAULT), => IN_SSL_DEFAULT    # Idem, closing parenthesis at end of line
+/[$WS]/ : # stay
+'#' : paint(upto, SSL_DEFAULT), => IN_SSL_ARGSDEF_COMMENT
+# Here, we have an argument
+/[$NMSTART]/ : paint(upto, SSL_DEFAULT), paint(include, SSL_VARIABLE), => IN_SSL_ARGUMENT
+/[^$WS$NMSTART#]/ : paint(upto, SSL_DEFAULT), redo,  => IN_SSL_DEFAULT
+
+state IN_SSL_ARGSDEF_COMMENT:
+/[\r\n]/ : paint(upto, SSL_COMMENT), => IN_SSL_ARGSDEF
+
+# Mode started after any '(' without 'function' in front of it
+state IN_SSL_NO_ARGSDEF:
+/(?<=,)./ : spush_check(IN_SSL_NO_ARGSDEF), paint(upto, SSL_DEFAULT), redo, => IN_SSL_DEFAULT # Push again
+/./ : redo, => IN_SSL_DEFAULT
+/$/ : => IN_SSL_DEFAULT # Idem at end of line
+
+
+##### End States ###############################################################
+
+
 # We might want to generalize this... by allowing named tokens.
 # Currently we just wrap things with a token-check
 # How to avoid specifying too much:



More information about the Sciviews-commits mailing list