Skip to content

indentation-based blocks #716

Answered by simonbuchan
w1kee asked this question in Q&A
Oct 4, 2022 · 3 comments · 4 replies
Discussion options

You must be logged in to vote

This seems to work for me:

start = _ { SOI ~ block* ~ EOI }

block = { id ~ nl ~ body? }
body = _ { indent_start ~ block ~ (indent ~ block)* ~ indent_end }

indent = _ { PEEK[..] }
indent_start = _ { PEEK[..] ~ PUSH(" "+) }
indent_end = _ { DROP }

nl = _ { (" "* ~ NEWLINE)+ | EOI }
id = { ASCII_ALPHA+ }

With input:

a
  b
   c
  d
  
  e
     f

the editor gives:

- block
  - id: "a"
  - block
    - id: "b"
    - block > id: "c"
  - block > id: "d"
  - block
    - id: "e"
    - block
      - id: "f"
      - EOI: ""
- EOI: ""

(don't know why the share button doesn't work for me?)

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@KSXGitHub
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@KSXGitHub
Comment options

@LeoDog896
Comment options

@KSXGitHub
Comment options

Answer selected by tomtau
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
6 participants