SynFacilSyn icon indicating copy to clipboard operation
SynFacilSyn copied to clipboard

Folding based on indentation

Open ursuscamp opened this issue 4 years ago • 3 comments

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?

ursuscamp avatar Apr 03 '20 17:04 ursuscamp

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.

t-edson avatar Apr 07 '20 18:04 t-edson

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?

ursuscamp avatar Apr 08 '20 20:04 ursuscamp

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

t-edson avatar Apr 09 '20 01:04 t-edson