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

fn #210

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

fn #210

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
## Breaking changes
- 変数定義の`#` → `let`
- 変数定義の`$` → `var`
- 関数定義の`@` → `fn`
- 無名関数`@() {}` → `() => {}`
- 代入の`<-` → `=`
- 比較の`=` → `==`
- `&` → `&&`
Expand Down
14 changes: 7 additions & 7 deletions src/parser/parser.peggy
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ NamespaceStatement

Statement
= VarDef // "let" NAME | "var" NAME
/ FnDef // "@"
/ FnDef // "fn"
/ Out // "<:"
/ Return // "return"
/ Attr // "+"
Expand All @@ -122,7 +122,7 @@ Expr

Expr2
= If // "if"
/ Fn // "@("
/ Fn // "() =>"
/ Chain // Expr3 "(" | Expr3 "[" | Expr3 "."
/ Expr3

Expand Down Expand Up @@ -501,10 +501,10 @@ Args
// define function statement

FnDef
= "@" s1:__* name:NAME s2:__* "(" _* args:Args? _* ")" ret:(_* ":" _* @Type)? _* "{" _* content:Statements? _* "}"
= "fn" _+ name:NAME s1:__* "(" _* args:Args? _* ")" _* ret:(_* "=>" _* @Type)? _* "{" _* content:Statements? _* "}"
Copy link
Contributor

Choose a reason for hiding this comment

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

これって:は型の指定をする時の記号だけど、これを=>にするという意図?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

あーそう
ついでに=>にしてみた(Rustとかだとそう)

{
if (s1.length > 0 || s2.length > 0) {
error('Cannot use spaces before or after the function name.');
if (s1.length > 0) {
error('Cannot use spaces after the function name.');
}
return createNode('def', {
name: name,
Expand All @@ -516,7 +516,7 @@ FnDef

// function expression

Fn = "@(" _* args:Args? _* ")" ret:(_* ":" _* @Type)? _* "{" _* content:Statements? _* "}"
Fn = "(" _* args:Args? _* ")" _* ret:(_* ":" _* @Type)? _* "=>" _* "{" _* content:Statements? _* "}"
Copy link
Contributor

Choose a reason for hiding this comment

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

ありふれている記号列ではスペースや改行の扱いはよく検討する必要がありそう

{ return createNode('fn', { args: args || [], ret: ret }, content || []); }


Expand Down Expand Up @@ -554,7 +554,7 @@ Type
/ NamedType

FnType
= "@(" _* args:ArgTypes? _* ")" _* "=>" _* result:Type
= "(" _* args:ArgTypes? _* ")" _* "=>" _* result:Type
{ return createNode('fn', { args: args || [], result }); }

ArgTypes
Expand Down
Loading