extend go syntax
This commit is contained in:
parent
1e83b66ba5
commit
7d2abdafb2
41
mml.parser
41
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"
|
||||
|
24
mml_test.go
24
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\"",
|
||||
|
@ -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
|
||||
|
20
syntax.go
20
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user