R: a better lexer to CudaText

All questions regarding lexer highlighting schemes are discussed here...
main Alexey
Posts: 2990
Joined: 25.08.2021 18:15

Re: R: a better lexer to CudaText

Post by main Alexey »

yes, underline-style doesn't work. with lexer themes and w/o them. seems I will remove/disable the checkbox.
jcfaria.uesc
Posts: 27
Joined: 07.05.2024 18:58

Re: R: a better lexer to CudaText

Post by jcfaria.uesc »

Alexey,
Well, the first step has been taken: we have a good lexer for R that can still be improved. I will work on it calmly and send you to be socialized with other users.

Be amazed at how easily this was done! This facility reflects a lot of your previous accumulated experience when you set out to create CudaText. Congratulations!

I am now more familiar with CudaText's interface and features. I will continue studying...

Next question: is it possible to create Lexer containers in Cuda?
For example: R + Markdown, R + Latex, etc. The idea is to develop efficient Lexers for Rnoweb to CudaText.

If so, can you send me a small example...
main Alexey
Posts: 2990
Joined: 25.08.2021 18:15

Re: R: a better lexer to CudaText

Post by main Alexey »

Thank you.
>is it possible to create Lexer containers in Cuda?
Sublexers. A lexer needs the configuration in the 'sub lexers' ui-tab of SynWrite dialog.
Lot of lexers do it:
HTML (includes CSS, JSON, JS, HTML Style)
JS (includes JSDoc)
Markdown (includes JS, CSS, YAML, JSON, HTML)
etc
alusiani
Posts: 3
Joined: 07.02.2026 10:45

Re: R: a better lexer to CudaText

Post by alusiani »

Hi,

thanks for the current R lexer! If the String recognition in the present R lexer R.lcf is replaced with the following fragment, new R 4.0 raw strings are also recognized. I got that with a longish session with ChatGPT. The last item is the same as the original.

Code: Select all

    item
      DisplayName = 'Raw string r"..."'
      StyleName = 'String'
      TokenType = 4
      Expression = 'r"[^"]*"'
      ColumnFrom = 0
      ColumnTo = 0
    end
    item
      DisplayName = 'Raw string R"..."'
      StyleName = 'String'
      TokenType = 4
      Expression = 'R"[^"]*"'
      ColumnFrom = 0
      ColumnTo = 0
    end
    item
      DisplayName = 'Raw string r''...'''
      StyleName = 'String'
      TokenType = 4
      Expression = 'r''[^'']*'''
      ColumnFrom = 0
      ColumnTo = 0
    end
    item
      DisplayName = 'Raw string R''...'''
      StyleName = 'String'
      TokenType = 4
      Expression = 'R''[^'']*'''
      ColumnFrom = 0
      ColumnTo = 0
    end
    item
      DisplayName = 'Raw string delimited "'
      StyleName = 'String'
      TokenType = 4
      Expression = 'r"([^()]{0,12})\((?:.(?!\1\))*?)\1"'
      ColumnFrom = 0
      ColumnTo = 0
    end
    item
      DisplayName = 'String (quoted)'
      StyleName = 'String'
      TokenType = 4
      Expression = '(?s)(?<!\w)("|'#39')(\\.|.)*?(\1|\Z)'
      ColumnFrom = 0
      ColumnTo = 0
    end
main Alexey
Posts: 2990
Joined: 25.08.2021 18:15

Re: R: a better lexer to CudaText

Post by main Alexey »

Results of AI thinking is not ok for me.
I need example of R code.

I asked Qwen AI about examples of all possible raw-strings in R 4.0.
I got this file, is it correct? If yes, I will adapte the lexer for this file.

Code: Select all

# ==============================================================================
# R 4.0+ Raw String Literals - Comprehensive Examples
# ==============================================================================

# 1. Check R version (requires R 4.0 or higher)
print(R.version.string)

# ------------------------------------------------------------------------------
# 2. Basic Syntax Variations (lowercase 'r' and uppercase 'R')
# ------------------------------------------------------------------------------

# Lowercase 'r' with double quotes as delimiter starters
basic_lower <- r"(Hello World)"

# Uppercase 'R' with double quotes as delimiter starters
basic_upper <- R"(Hello World)"

# Using single quotes as delimiter starters
basic_single <- r'[Hello World]'

# ------------------------------------------------------------------------------
# 3. Handling Special Characters (No Escaping Needed)
# ------------------------------------------------------------------------------

# Windows file paths (backslashes do not need escaping)
windows_path <- r"(C:\Users\Name\Documents\file.txt)"

# Literal backslash-n (not interpreted as newline)
literal_escape <- r"(This is \n not a newline)"

# Regular expressions (no double escaping required)
regex_pattern <- r"(\d+\.\d+)"

# ------------------------------------------------------------------------------
# 4. Handling Quotes Inside Strings
# ------------------------------------------------------------------------------

# Including double quotes inside (using square brackets as delimiters)
contains_double_quotes <- r"[He said "Hello" to me]"

# Including single quotes inside (using parentheses as delimiters)
contains_single_quotes <- r"(It's a nice day)"

# Including both quotes (using curly braces as delimiters)
contains_both_quotes <- r"{She said 'Hi' and "Bye"}"

# ------------------------------------------------------------------------------
# 5. Multiline Raw Strings
# ------------------------------------------------------------------------------

multiline_string <- r"(
Line 1 of text
Line 2 of text
Line 3 of text
)"

# ------------------------------------------------------------------------------
# 6. Custom Delimiters (for nested content)
# ------------------------------------------------------------------------------

# Using hyphens to allow closing brackets inside the string
custom_delim_1 <- r"--[Text with ] inside]--"

# Using equals signs to allow curly braces inside
custom_delim_2 <- r"={Text with } inside}="

# ------------------------------------------------------------------------------
# 7. Comparison: Normal Strings vs. Raw Strings
# ------------------------------------------------------------------------------

# Normal string (requires escaping backslashes and quotes)
normal_string <- "C:\\Users\\Name\\file.txt"
normal_regex  <- "\\d+\\.\\d+"

# Raw string (cleaner syntax)
raw_string    <- r"(C:\Users\Name\file.txt)"
raw_regex     <- r"(\d+\.\d+)"

# ------------------------------------------------------------------------------
# 8. Print Results to Console
# ------------------------------------------------------------------------------

cat("Basic Lower:", basic_lower, "\n")
cat("Windows Path:", windows_path, "\n")
cat("Literal Escape:", literal_escape, "\n")
cat("Regex Pattern:", regex_pattern, "\n")
cat("Multiline:\n", multiline_string, "\n")
main Alexey
Posts: 2990
Joined: 25.08.2021 18:15

Re: R: a better lexer to CudaText

Post by main Alexey »

I placed the adapted lexer to Git:
https://github.com/CudaText-addons/CudaText-lexers

test how it works with raw-strings. if OK, I will update it in addon-manager.
Post Reply