Skip to content

Cannot match a variable against an optional non-terminal in a rule definition #132

@yusungsim

Description

@yusungsim

Hi, I'm currently experimenting with SpecTec to specify the Rust programming language's syntax and semantics. During the process, I found a case where SpecTec toolchain fails to parse the optional nonterminal (i.e. x?) in the rule definition.

The below DSL code is a minified version of the error inducing code.

Code of interest :

;; syntax blockExpression =
;;     | Stmts statements?

syntax blockExpression
    = statements?

syntax statement =
    | LetStmt blockExpression 

syntax statements =
    | Stmts statement*


syntax state = nat  (; just for demo ;)           

relation interp_statement:  state |- statement -> state

rule interp_statement/let :
    s |- LetStmt be -> s

And the below is the result of running ./watsup to compile above code into LaTeX, which emits an error message that cannot match the expected type of optional non-terminal.

The error message :

$ ./watsup min_optional/a.watsup --latex
min_optional/a.watsup:22.10-22.20: type error: expression does not match expected type `blockExpression` = `statements?`

The error states that it cannot match the nonterminal blockExpression with the variable be, which in case the blockExpression is an option of statements.

Interestingly, if you replace the syntax definition of blockExpression with the same version written in the variant (ie. first two commented lines in the DSL code block), SpecTec successfully parses it and produces a LaTeX code.

I expect that the toolchain should accept the original code, also, because there are no actual difference between defining blockExpression directly as an option of statements or using a single variant. I'm not sure if it is a bug, or it is intended to reject such use of optional element.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions