t-edson / SynFacilSyn

Scriptable Highlighter for the SynEdit Component of Lazarus
GNU General Public License v2.0
34 stars 16 forks source link

Folding based on indentation #29

Open ursuscamp opened 4 years ago

ursuscamp commented 4 years ago

I'm trying to create a syntax definition for the Nim language, which is like a cross between Python and Pascal, syntactically. All of the blocks in Nim are defined by indentation and do not have closing tokens.

Here is an example of Nim code:

import strformat

type
  Person = object
    name: string
    age: Natural # Ensures the age is positive

let people = [
  Person(name: "John", age: 45),
  Person(name: "Kate", age: 30)
]

for person in people:
  # Type-safe string interpolation,
  # evaluated at compile time.
  echo(fmt"{person.name} is {person.age} years old")

There doesn't seem to be an obvious way to do folding for this unless I am missing something in the manual. Do you have any suggestions or is this beyond the capabilities of the lexing engine?

t-edson commented 4 years ago

Hi. Folding are usually defined using delimiters in SynFaciLSyn. However, there is sections too. Check the section 4.12 in documentation.

I don't know if this can be applied to your case.

ursuscamp commented 4 years ago

I saw that. I may be able to make that work. Secondary question: For the TokenPos parameters, is there some way to indicate if something is the LAST token on the line, or can you only use numbers?

t-edson commented 4 years ago

Only numbers defined by now. Last token of a line is always the token "next line".