F-Flat

F♭ (pronounced F-flat) is a toy language.


Project maintained by Hypercubed Hosted on GitHub Pages — Theme by mattgraham

FFlat Specification 0.0.8

PEG Grammar

bool <- AstRule((((AnyCase("true") !core.identifierNext) / (AnyCase("false") !core.identifierNext)) !identifierNext))
bracket <- AstRule(advanceIf([[]{}()]))
comment <- (fullComment / lineComment)
decimal <- ((plusOrMinus? (integer (fraction? (exponent? advanceIf([%])?)))) !advanceIf((![ \t\n\r\f,'\"``,[]{}():] / core.atDigit)))
decimalFraction <- ((plusOrMinus? (integer? (fraction (exponent? advanceIf([%])?)))) !advanceIf((![ \t\n\r\f,'\"``,[]{}():] / core.atDigit)))
delimiter <- advanceIf([ \t\n\r\f,])+
digit <- advanceIf((core.atDigit / [_]))
digits <- digit+
doubleQuotedString <- AstRule(("\"" ((advanceIf(![\"])* / <predicate>) ("\"" / <predicate>))))
escapedChar <- (advanceIf([\\]) core.advance)
exponent <- (advanceIf([eE]) (plusOrMinus? digits))
fraction <- ("." integer)
fullComment <- ("/*" (advanceIf(!"*/")* "*/"))
i <- AstRule(((AnyCase("i") !core.identifierNext) !identifierNext))
identifier <- (identifierFirst identifierNext*)
identifierFirst <- advanceIf(![ \t\n\r\f,'\"``,[]{}()])
identifierNext <- advanceIf(![ \t\n\r\f,'\"``,[]{}():])
integer <- (core.digit+ digit*)
key <- AstRule((identifier advanceIf([:])))
lineComment <- ("//" untilEol)
literal <- (bool / (null / (nan / i)))
nan <- AstRule(((AnyCase("nan") !core.identifierNext) !identifierNext))
null <- AstRule(((AnyCase("null") !core.identifierNext) !identifierNext))
number <- AstRule((radix / (decimal / (decimalFraction / integer))))
plusOrMinus <- advanceIf([+-])
radix <- ((plusOrMinus? ("0" (advanceIf([oObBxF]) (radixInteger (radixFraction? radixExponent?))))) !advanceIf((![ \t\n\r\f,'\"``,[]{}():] / ([0123456789abcdefABCDEF] / [_]))))
radixDigit <- advanceIf(([0123456789abcdefABCDEF] / [_]))
radixExponent <- (advanceIf([eEpP]) (plusOrMinus? radixDigit+))
radixFraction <- ("." radixInteger)
radixInteger <- (rawRadixDigit+ radixDigit*)
rawRadixDigit <- advanceIf([0123456789abcdefABCDEF])
sequence <- (value (ws value)*)?
singleQuotedString <- AstRule(("'" ((advanceIf(!['])* / <predicate>) ("'" / <predicate>))))
string <- (templateString / (singleQuotedString / doubleQuotedString))
symbol <- AstRule((advanceIf([#]) identifier))
templateString <- AstRule(("`" ((advanceIf(![`])* / <predicate>) ("`" / <predicate>))))
untilEol <- (advanceIf(!core.newLine)* core.newLine?)
value <- (comment / (number / (symbol / (literal / (key / (word / (string / bracket)))))))
word <- AstRule(identifier)
ws <- (delimiter / advanceIf(core.atWs))*

Syntax diagrams (WIP)

bracket

fflat.bracket

identifierFirst

[ \t\n\r\f,'\"``,[]{}()]

identifierNext

[ \t\n\r\f,'\"``,[]{}():]

identifier

identifierFirst identifierNext

word

fflat.word

key

fflat.key

digit

core.atDigit [_]

digits

digit

integer

atDigit digit

fraction

"." integer

plusOrMinus

[+-]

exponent

[eE] plusOrMinus digits

decimal

plusOrMinus integer fraction exponent [%] [ \t\n\r\f,'\"``,[]{}():] atDigit

decimalFraction

plusOrMinus integer fraction exponent [%] [ \t\n\r\f,'\"``,[]{}():] atDigit

rawRadixDigit

[0123456789abcdefABCDEF]

radixDigit

[0123456789abcdefABCDEF] [_]

radixInteger

rawRadixDigit radixDigit

radixFraction

"." radixInteger

radixExponent

[eEpP] plusOrMinus radixDigit

radix

plusOrMinus "0" [oObBxF] radixInteger radixFraction radixExponent [ \t\n\r\f,'\"``,[]{}():] [0123456789abcdefABCDEF] [_]

number

fflat.number

untilEol

core.crlf "\n" [any character] newLine

fullComment

"/*" "*/" [any character] "*/"

lineComment

"//" untilEol

comment

fullComment lineComment

delimiter

[ \t\n\r\f,]

ws

delimiter core.atWs

symbol

fflat.symbol

bool

fflat.bool

null

fflat.null

nan

fflat.nan

i

fflat.i

literal

bool null nan i

escapedChar

[\\] [any character]

templateString

fflat.templateString

singleQuotedString

fflat.singleQuotedString

doubleQuotedString

fflat.doubleQuotedString

string

templateString singleQuotedString doubleQuotedString

value

comment number symbol literal key word string bracket

sequence

value ws