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

Refactor AST #4

Merged
merged 6 commits into from
Nov 6, 2024
Merged

Refactor AST #4

merged 6 commits into from
Nov 6, 2024

Conversation

raf-nr
Copy link
Owner

@raf-nr raf-nr commented Nov 5, 2024

  • Add new constructor for identifiers
  • Rename typed pattern and type definitions' constructors
  • Add a limit on function arguments (must have at least 1 argument)
  • Add a limit on tuple size (must have at least 2 elements)

@raf-nr raf-nr requested a review from ksenmel November 5, 2024 19:07
@raf-nr
Copy link
Owner Author

raf-nr commented Nov 5, 2024

CI починим в другом PR

@@ -2,30 +2,30 @@

(** SPDX-License-Identifier: LGPL-3.0-or-later *)

type identifier = string [@@deriving show { with_path = false }]
type identifier = Id of string [@@deriving show { with_path = false }]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почему так?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

дело вкуса + потом красивее переиспользовать код. Вообщем тут причина - так красивее


type constant =
| CInt of int (** -1, 0, 1, ... *)
| CBool of bool (** true, false *)
| CChar of char (** 'a', 'b', 'c', ... *)
| CString of string (** "Hello world!" *)
| CUnit of unit (** () *)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Owner Author

@raf-nr raf-nr Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unit внутри себя ничего не хранит, поэтому обычного конструктора (CUnit) без элементов внутри будет достаточно. В самом начале просто ошибся

@@ -34,18 +34,18 @@ type pattern =
| PConst of constant (** Any constant: '1', 'true', etc *)
| PVar of identifier (** A variable pattern: 'x', 'y', etc *)
| POr of pattern * pattern (** 'P1 | P2' *)
| PTuple of pattern list (** Tuple of patterns: '(P1, P2, P3)' *)
| PTuple of pattern * pattern * pattern list (** Tuple of patterns: '(P1, P2, P3)' *)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут тоже не поняла, почему так

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В ocaml кортеж состоит минимум из 2 элементов. Подобной структурой в AST мы создаем некоторый инвариант, что у нас кортеж - хотя бы 2 элемента (pattern * pattern) + оставшиеся элементы если они остались

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Да, точно, спасибо!

@ksenmel ksenmel self-requested a review November 5, 2024 21:47
Copy link
Collaborator

@ksenmel ksenmel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job 👍👍

@raf-nr raf-nr merged commit b434e5d into parser Nov 6, 2024
1 check failed
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