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

Tree-sitter grammar: support the remaining infix operators #5322

Merged
merged 4 commits into from
Mar 12, 2024

Conversation

OceanOak
Copy link
Collaborator

@OceanOak OceanOak commented Mar 12, 2024

Changelog:

Tree-sitter-darklang
- Update the grammar to support the remaining infix operators, and update the parser accordingly

#5321

@OceanOak OceanOak force-pushed the grammar-updates-3 branch from 3cb5e6f to 4f40c76 Compare March 12, 2024 10:53
@OceanOak
Copy link
Collaborator Author

Questions:

  1. Is it worth adding something like the following to writtenTypesToProgramTypes.dark, or is the approach implemented in this PR acceptable?
      module InfixFnName =
        let toPT (infix: WrittenTypes.InfixOperator) : ProgramTypes.InfixFnName =
          match infix with
          | ArithmeticPlus -> ProgramTypes.InfixFnName.ArithmeticPlus
          | ArithmeticMinus -> ProgramTypes.InfixFnName.ArithmeticMinus
          | ArithmeticMultiply -> ProgramTypes.InfixFnName.ArithmeticMultiply
          | ArithmeticDivide -> ProgramTypes.InfixFnName.ArithmeticDivide
          | ArithmeticModulo -> ProgramTypes.InfixFnName.ArithmeticModulo
          | ArithmeticPower -> ProgramTypes.InfixFnName.ArithmeticPower
          | ComparisonGreaterThan -> ProgramTypes.InfixFnName.ComparisonGreaterThan
          | ComparisonGreaterThanOrEqual ->
            ProgramTypes.InfixFnName.ComparisonGreaterThanOrEqual
          | ComparisonLessThan -> ProgramTypes.InfixFnName.ComparisonLessThan
          | ComparisonLessThanOrEqual ->
            ProgramTypes.InfixFnName.ComparisonLessThanOrEqual
          | ComparisonEqual -> ProgramTypes.InfixFnName.ComparisonEquals
          | ComparisonNotEqual -> ProgramTypes.InfixFnName.ComparisonNotEquals
          | StringConcat -> ProgramTypes.InfixFnName.StringConcat


      module BinaryOperation =
        let toPT
          (binop: WrittenTypes.BinaryOperator)
          : ProgramTypes.BinaryOperation =
          match binop with
          | BinOpAnd -> ProgramTypes.BinaryOperation.BinOpAnd
          | BinOpOr -> ProgramTypes.BinaryOperation.BinOpOr
         
  1. In tests/corpus, should we include tests similar to the following, or should we limit it to testing aspects like precedence?
==================
comparison operator ==
==================

a == b

---

(source_file
  (expression
    (infix_operation
      (expression (variable_identifier))
      (operator)
      (expression (variable_identifier))
    )
  )
)

==================
exponent operator ^
==================

a ^ b

---

(source_file
  (expression
    (infix_operation
      (expression (variable_identifier))
      (operator)
      (expression (variable_identifier))
    )
  )
)

@OceanOak OceanOak marked this pull request as ready for review March 12, 2024 11:13
@OceanOak OceanOak force-pushed the grammar-updates-3 branch from e3847dc to 34632ad Compare March 12, 2024 11:23
@StachuDotNet
Copy link
Member

StachuDotNet commented Mar 12, 2024

Questions:

  1. Is it worth adding something like the following to writtenTypesToProgramTypes.dark, or is the approach implemented in this PR acceptable?

I think this it'd be worth refactoring that fn out, yeah

  1. In tests/corpus, should we include tests similar to the following, or should we limit it to testing aspects like precedence?

Hm maybe I'm missing why you'd question these tests -- they seem useful to me. We don't have that many operators, so a handful of tests for each seems OK. The tree-sitter corpus tests run super fast, anyway.

@OceanOak OceanOak requested a review from StachuDotNet March 12, 2024 20:21
@StachuDotNet StachuDotNet merged commit 0a7fcff into darklang:main Mar 12, 2024
8 checks passed
@OceanOak OceanOak changed the title Update the grammar to support the remaining infix operators Tree-sitter grammar: support the remaining infix operators Mar 28, 2024
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

Successfully merging this pull request may close these issues.

2 participants