-
Notifications
You must be signed in to change notification settings - Fork 0
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
Refactor AST #4
Conversation
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)
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 }] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Почему так?
There was a problem hiding this comment.
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 (** () *) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
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)' *) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тут тоже не поняла, почему так
There was a problem hiding this comment.
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) + оставшиеся элементы если они остались
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Да, точно, спасибо!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job 👍👍