mirror of
https://github.com/johnkerl/miller.git
synced 2026-01-23 02:14:13 +00:00
add call/subr to mlr.bnf
This commit is contained in:
parent
e9c1101733
commit
22af479b9e
5 changed files with 99 additions and 5 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -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
3
go/.gitignore
vendored
|
|
@ -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
|
||||
|
|
|
|||
94
go/parser-experiments/two/temp.bnf
Normal file
94
go/parser-experiments/two/temp.bnf
Normal 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) >>
|
||||
;
|
||||
|
|
@ -1352,7 +1352,7 @@ SubroutineCallsite
|
|||
$0,
|
||||
dsl.NodeTypeSubroutineCallsite,
|
||||
),
|
||||
$2,
|
||||
$3,
|
||||
) >>
|
||||
;
|
||||
|
||||
|
|
|
|||
|
|
@ -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],
|
||||
)
|
||||
},
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue