%YAML 1.2
---
name: S Expressions
file_extensions: ["sexp"]
scope: source.sexpr

contexts:
  main:
    - match: '(;+).*$'
      scope: comment.line.sexpr
      captures:
        1: punctuation.definition.comment.sexpr
    - match: '#;'
      scope: punctuation.definition.comment.sexpr
      push: comment
    - match: '#\|'
      scope: punctuation.definition.comment.sexpr
      push: block_comment

    - match: '"'
      scope: punctuation.definition.string.begin.sexpr
      push: string_unquote
    - match: '\d+\.\d+'
      scope: constant.numeric.float.sexpr
    - match: '\d+'
      scope: constant.numeric.integer.sexpr
    - match: '\w+'
      scope: constant.other.sexpr
    - match: '\('
      scope: punctuation.section.parens.begin.sexpr
      push: main_rparen
    - match: '\)'
      scope: invalid.illegal.stray-paren-end

  string_unquote:
    - meta_scope: string.quoted.double.sexpr
    - match: '""'
      scope: constant.character.escape.sexpr
    - match: '"'
      scope: punctuation.definition.string.end.sexpr
      pop: true

  main_rparen:
    - match: '\)'
      scope: punctuation.section.parens.end.sexpr
      pop: true
    - include: main

  comment:
    - meta_scope: comment.block.sexpr
    - match: '\('
      set: comment_rparen

  comment_lparen:
    - meta_scope: comment.block.sexpr
    - match: '\('
      push: comment_rparen
    - match: '\)'
      scope: invalid.illegal.stray-paren-end

  comment_rparen:
    - meta_scope: comment.block.sexpr
    - match: '\)'
      pop: true
    - include: comment

  block_comment:
    - meta_scope: comment.block.sexpr
    - match: '#\|'
      push: block_comment
    - match: '\|#'
      scope: punctuation.definition.comment.sexpr
      pop: true
