From 7d2abdafb2a4c18bdf38b65285dec0f192219bb6 Mon Sep 17 00:00:00 2001 From: Arpad Ryszka Date: Sat, 15 Jul 2017 19:04:04 +0200 Subject: [PATCH] extend go syntax --- mml.parser | 41 ++++++++++++++++++++++++++++++++++++++++- mml_test.go | 24 +++++++++++++++++++++++- notes.txt | 7 ++++++- syntax.go | 20 ++++++++++---------- 4 files changed, 79 insertions(+), 13 deletions(-) diff --git a/mml.parser b/mml.parser index abc0137..1c5012b 100644 --- a/mml.parser +++ b/mml.parser @@ -150,6 +150,45 @@ string-type = "string"; bool-type = "bool"; error-type = "error"; +/* +support: + + go { + foo() + bar() + } + + go { for { f() } } + go func() { for { f() } }() + fn f() { go f() }; go f() + +and not: + + go for {foo()} + +or: + + go for foo() + +because we don't know what the arguments are +*/ + +/* + + fn foo() { + bar() + baz() + } + let qux foo() + +equivalent to: + + let qux { + bar() + baz() + } +*/ + primitive-type:alias = int-type | float-type | string-type @@ -290,7 +329,7 @@ select = "select" wsnlc* "{" (wsnlc | ";")* (sep (select-case-line | default-line | statement))*)? (wsnlc | ";")* "}"; -go = "go" wsnlc* function-application; +go = "go" wsnlc* (function-application | block); /* require . = "mml/foo" diff --git a/mml_test.go b/mml_test.go index 1b9d0ee..ceb7df5 100644 --- a/mml_test.go +++ b/mml_test.go @@ -1029,7 +1029,7 @@ func TestMML(t *testing.T) { }}, }}, }, { - msg: "float on a new line", + msg: "float on a new line", text: "f()\n.9", nodes: []*Node{{ Name: "function-application", @@ -1983,6 +1983,28 @@ func TestMML(t *testing.T) { }}, }}, ignorePosition: true, + }, { + msg: "go, block", + text: "go { for { f() } }", + nodes: []*Node{{ + Name: "go", + Nodes: []*Node{{ + Name: "block", + Nodes: []*Node{{ + Name: "loop", + Nodes: []*Node{{ + Name: "block", + Nodes: []*Node{{ + Name: "function-application", + Nodes: []*Node{{ + Name: "symbol", + }}, + }}, + }}, + }}, + }}, + }}, + ignorePosition: true, }, { msg: "require, dot, equal", text: "require . = \"mml/foo\"", diff --git a/notes.txt b/notes.txt index b669134..b9b27b2 100644 --- a/notes.txt +++ b/notes.txt @@ -1,5 +1,10 @@ -cleanup error reporting +- longest parse +- count the lines +- print the line +- print the deepest non-alias node name +- print the documentation of the node name +read, with error reporting custom tokens indentation streaming diff --git a/syntax.go b/syntax.go index 6216f8e..190cb59 100644 --- a/syntax.go +++ b/syntax.go @@ -32,16 +32,16 @@ type Syntax struct { } var ( - ErrSyntaxInitialized = errors.New("syntax initialized") - ErrInitFailed = errors.New("init failed") - ErrNoParsersDefined = errors.New("no parsers defined") - ErrInvalidInput = errors.New("invalid input") - ErrInvalidUnicodeCharacter = errors.New("invalid unicode character") - ErrInvalidEscapeCharacter = errors.New("invalid escape character") - ErrUnexpectedCharacter = errors.New("unexpected character") - ErrInvalidSyntax = errors.New("invalid syntax") - ErrRootAlias = errors.New("root node cannot be an alias") - ErrNotImplemented = errors.New("not implemented") + ErrSyntaxInitialized = errors.New("syntax initialized") + ErrInitFailed = errors.New("init failed") + ErrNoParsersDefined = errors.New("no parsers defined") + ErrInvalidInput = errors.New("invalid input") + ErrInvalidUnicodeCharacter = errors.New("invalid unicode character") + ErrInvalidEscapeCharacter = errors.New("invalid escape character") + ErrUnexpectedCharacter = errors.New("unexpected character") + ErrInvalidSyntax = errors.New("invalid syntax") + ErrRootAlias = errors.New("root node cannot be an alias") + ErrNotImplemented = errors.New("not implemented") ) func duplicateDefinition(name string) error {