1 #include "Pegmatite/pegmatite.hh" 5 using pegmatite::operator
""_E;
6 using pegmatite::operator
""_S;
7 using pegmatite::ExprPtr;
8 using pegmatite::BindAST;
11 using pegmatite::trace;
27 (*(!ExprPtr(
"*/") >> (nl(
'\n') | any()))) >>
29 "//"_E >> *(!(ExprPtr(
"\n")) >> any()) >> nl(
'\n');
41 Rule
num = -(
"+-"_S) >> +digit;
99 Rule
cmp = eq_cmp | ne_cmp | lt_cmp | gt_cmp | le_cmp |
ge_cmp;
107 ExprPtr
character = term((
"\\\""_E | !ExprPtr(
'"') >> (nl(
'\n') | any())));
116 Rule
string = term(
'"' >> string_body >>
'"');
120 ExprPtr
letter = ((
'a'_E -
'z') | (
'A'_E -
'Z'));
188 Rule
ret =
"return"_E >> expression >>
';';
199 Rule
whileLoop =
"while"_E >>
'(' >> expression >>
')' >>
200 '{' >> statements >>
'}';
211 Rule
statement = cls | ret | ifStatement | whileLoop | decl |
Rule sub_op
Subtract operations follow the same structure as add.
Rule ignored
Rule for treating both comments and whitespace as ignored tokens.
Rule ge_cmp
Greater-than-or-equal comparison.
Rule call
A call is something that is callable, followed eventually by an argument list.
Rule statement
All valid statement types.
Rule eq_cmp
Equal comparison.
Rule le_cmp
Less-than-or-equal comparison.
Rule mul
Multiply-precedence operations are either multiply or divide operations, or simple values (numbers of...
Rule whileLoop
A while loop, with the condition in brackets followed by the body in braces.
Rule variable
Variable references are single identifiers.
Rule num
Numbers are one or more digits, optionally prefixed with its sign.
Rule div_op
Divide operations follow the same syntax as multiply.
Rule lt_cmp
Less-than comparison.
Rule decl
A variable declaration, optionally with an initialiser.
Rule argList
Argument list.
ExprPtr character
A character in a string.
Rule ne_cmp
Not-equal comparison.
Rule expression
All of the valid kinds of expression.
Rule identifier
Identifiers are a letter followed by zero or more alphanumeric characters.
Rule callArgList
The argument list for a call.
Rule whitespace
Whitespace: spaces, tabs, newlines.
Rule newExpr
A new expression: the keyword new followed by a class name.
Rule ifStatement
An if statement, with a condition in brackets followed by the body in braces.
ExprPtr digit
Digits are things in the range 0-9.
Rule cls
Classes are the keyword class, followed by the class name and optionally a superclass.
Rule ret
A return statement.
Rule gt_cmp
Greater-than comparison.
Rule statements
A list of statements: the top-level for programs in this grammar.
Rule val
Values are either numbers or expressions in brackets (highest precedence).
Rule string_body
The body of a string.
Grammar for the MysoreScript language.
Rule comment
Comments, including tracking newlines inside comments via the whitespace rule.
Rule assignment
Assignments are variables, followed by a single equals sign, and then the expression to assign to the...
Rule cmp
General rule for comparisons.
Rule arith_expr
Expressions can be any of the other types.
Rule closure
A closure starts with the keyword 'func', followed by a function name, a list of arguments in bracket...
Rule callable
Callable expression.
Rule add_op
Add operations can have any expression on the left (including other add expressions), but only higher-precedence operations on the right.
Rule mul_op
Multiply operations are values or multiply, or divide operations, followed by a multiply symbol...
ExprPtr letter
Letters - valid characters for the start of an identifier.
Rule string
Strings any characters, enclosed in quotes.