Skip to content

lang: Allow inline statements again #924

@karpfediem

Description

@karpfediem

With the changes in #919 we now require a newline in the last occuring/final stmt token.

This means as a concrete example this won't parse anymore:

❯ build/mgmt-linux-amd64 run lang 'print "hello" { msg => "world", }' --no-network --converged-timeout 1
This is: mgmt, version: 1.0.2-168-g423add81
Copyright (C) James Shubin and the project contributors
Written by James Shubin <james@shubin.ca> and the project contributors
21:22:22 main: start: 1779045742833061284
21:22:22 cli: lang: lexing/parsing...
21:22:22 main: goodbye!
cli parse error: could not generate AST: parser: `syntax error: unexpected $end, expecting NEWLINE` @1:1

It now needs to have a newline at the end

❯ build/mgmt-linux-amd64 run lang 'print "hello" { msg => "world", }
' --no-network --converged-timeout 1

There is already a likely useful/related commented-out top: prog stmt branch here

mgmt/lang/parser/parser.y

Lines 162 to 180 in c7acc75

// Allow a final stmt without a trailing newline (e.g. input that
// doesn't end with `\n`). A NEWLINE here would be handled by the
// `prog stmt NEWLINE` rule below, so this only fires at the $end.
/*
| prog stmt
{
posLast(yylex, yyDollar) // our pos
if stmt, ok := $1.stmt.(*ast.StmtProg); ok {
stmts := stmt.Body
stmts = append(stmts, $2.stmt)
prog := &ast.StmtProg{
Body: stmts,
}
locate(yylex, $1, yyDollar[len(yyDollar)-1], prog)
lp := cast(yylex)
lp.ast = prog
}
}
*/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions