add call/subr to mlr.bnf

This commit is contained in:
John Kerl 2020-11-24 12:01:43 -05:00
parent e9c1101733
commit 22af479b9e
5 changed files with 99 additions and 5 deletions

1
.gitignore vendored
View file

@ -115,3 +115,4 @@ c/reg_test/input/rfc-csv/Makefile
c/stream/Makefile
c/unit_test/Makefile
doc/Makefile
parser-experiments/two/src

3
go/.gitignore vendored
View file

@ -11,6 +11,5 @@ parser-experiments/one/src/github.com
parser-experiments/one/src/experimental
parser-experiments/one/main
parser-experiments/two/src/github.com
parser-experiments/two/src/experimental
parser-experiments/two/src
parser-experiments/two/main

View file

@ -0,0 +1,94 @@
// ================================================================
// LEXER
!whitespace : ' ' | '\t' | '\n' | '\r' ;
!comment : '#' {.} '\n' ;
_letter : 'a'-'z' | 'A'-'Z' ;
_decdig : '0'-'9' ;
_idchar : _letter | _decdig | '_' ;
non_sigil_name : _idchar { _idchar } ;
//call : 'c' 'a' 'l' 'l' ;
// ================================================================
// IMPORT
<< import "miller/dsl" >>
// ================================================================
// PARSER
// ----------------------------------------------------------------
Root
: SubroutineCallsite
<< dsl.NewAST($0) >>
;
// ----------------------------------------------------------------
SubroutineCallsite
: "call" SubroutineName "(" ")"
<< dsl.NewASTNodeZary(
$0,
dsl.NodeTypeSubroutineCallsite,
) >>
| "call" SubroutineName "(" FcnArgs ")"
// As parsed there's an intermediate node between SubroutineCallsite
// and the children. Now we can remove it.
//
// Before:
// * SubroutineCallsite "[]"
// * SubroutineCallsite
// * StringLiteral "a"
// * StringLiteral "b"
//
// After:
// * SubroutineCallsite "[]"
// * StringLiteral "a"
// * StringLiteral "b"
<< dsl.AdoptChildren(
dsl.NewASTNodeNestable(
$0,
dsl.NodeTypeSubroutineCallsite,
),
$3,
) >>
;
// ----------------------------------------------------------------
SubroutineName : non_sigil_name;
// ----------------------------------------------------------------
FcnArgs
: Rvalue
<< dsl.NewASTNodeUnary(
nil,
$0,
dsl.NodeTypeFunctionCallsite,
) >>
// Allow trailing final comma, especially for multiline statements
| Rvalue ","
<< dsl.NewASTNodeUnary(
nil,
$0,
dsl.NodeTypeFunctionCallsite,
) >>
// Allow trailing final comma, especially for multiline statements
| Rvalue "," FcnArgs
<< dsl.PrependChild(
$2,
$0,
) >>
;
// ----------------------------------------------------------------
Rvalue
: "x" << dsl.NewASTNodeZary($0, dsl.NodeTypeStringLiteral) >>
| "y" << dsl.NewASTNodeZary($0, dsl.NodeTypeStringLiteral) >>
| "z" << dsl.NewASTNodeZary($0, dsl.NodeTypeStringLiteral) >>
;

View file

@ -1352,7 +1352,7 @@ SubroutineCallsite
$0,
dsl.NodeTypeSubroutineCallsite,
),
$2,
$3,
) >>
;

View file

@ -2552,7 +2552,7 @@ var productionsTable = ProdTab{
X[0],
dsl.NodeTypeSubroutineCallsite,
),
X[2],
X[3],
) >>`,
Id: "SubroutineCallsite",
NTType: 61,
@ -2564,7 +2564,7 @@ var productionsTable = ProdTab{
X[0],
dsl.NodeTypeSubroutineCallsite,
),
X[2],
X[3],
)
},
},