Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indent/Dedent #107

Open
hudson-ai opened this issue Jan 17, 2025 · 2 comments
Open

Indent/Dedent #107

hudson-ai opened this issue Jan 17, 2025 · 2 comments
Assignees

Comments

@hudson-ai
Copy link
Collaborator

  • For JSON and Python: track indentation depth
  • For Python: also track nesting level of parentheses
@mmoskal mmoskal self-assigned this Jan 17, 2025
@mmoskal
Copy link
Collaborator

mmoskal commented Jan 17, 2025

  • extend lexer state (RegexVec) with these two numbers.
  • add some configuration syntax in lark (%config { ... } or similar) - this would let one configure what is the 1-level indent string (eg. " ") and whether to track nesting

@mmoskal
Copy link
Collaborator

mmoskal commented Feb 22, 2025

more thinking:

  • indent level is fixed for the whole grammar (4 spaces or similar)
  • special lexemes INDENT, DEDENT, KEEPDENT (NEWLINE in Python spec), KEEPDENT_LAZY
    they all imply a newline
  • need to identify which lexemes open/close parentheses/etc if any
    (special lexemes not generated inside of parentheses (or other lexemes for that matter))
  • what about %ignore ? don't ignore \n clearly; otherwise special lexemes are greedy so should be fine?
  • for yaml, KEEPDENT can't be greedy:
foo: >
    line 1
        indented line
        another
      a bit less
    and back
bar: 2
string: single_string | double_string | folded_string

# "\n\s*" -> " ", "''" -> "'"
single_string: /'([^']|'')*'/

# "\\\n\s*" -> "", "\n\s*" -> " ",
# then interpret escapes normally
double_string: /"([^"\\]|\\([\nnrfbt]|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8}))*"/

folded_string: />\s*/ INDENT text (KEEPDENT_LAZY text)* DEDENT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants