Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write down a formal grammar for Maud #60

Closed
lambda-fairy opened this issue Nov 12, 2016 · 2 comments
Closed

Write down a formal grammar for Maud #60

lambda-fairy opened this issue Nov 12, 2016 · 2 comments

Comments

@lambda-fairy
Copy link
Owner

lambda-fairy commented Nov 12, 2016

This would be nice as an appendix of the book.

@lambda-fairy
Copy link
Owner Author

lambda-fairy commented Dec 21, 2016

Here's an initial attempt using EBNF:

markups = { markup } ;
markup = literal | special form | element | splice | block ;

special form = '@',
    ( 'if', moelarry, block
    | 'if', 'let', pattern, '=', moelarry, block
    | 'while', moelarry, block
    | 'while', 'let', pattern, '=', moelarry, block
    | 'for', pattern, 'in', moelarry, block
    | 'match', moelarry, match body
    | 'let', pattern, '=', moelarry, block
    ) ;
match body = ... ;  (* this is complicated *)

element = name, { normal attribute | empty attribute }, ( markup | '/' ) ;
name = identifier, { '-', identifier } ;
normal attribute = name, '=', attribute value ;
attribute value = literal | special form | splice | attribute block ;
attribute block = '{', attribute value, '}' ;
empty attribute = name, '?', [ '[', expression, ']' ] ;

splice = '(', expression, ')' ;

block = '{', markups, '}' ;

identifier = ? Rust identifier ? ;
literal = ? Rust string literal ? ;
expression = ? Rust expression ? ;
moelarry = ? Rust expression excluding struct literals ? ;
pattern = ? Rust pattern ? ;

(See rust-lang/rfcs#1384 (comment) for an explanation of the term "moelarry".)

Seems pretty straightforward, except for the @match syntax (I'm not really familiar with that part of the parser).

@lambda-fairy
Copy link
Owner Author

I don't think anyone is asking for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant