mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 07:51:05 +01:00
Express prelude using Carbon syntax (#955)
This should be clearer, more maintainable, and more scalable than building the prelude AST by hand.
This commit is contained in:
@@ -83,6 +83,7 @@ WHILE "while"
|
||||
|
||||
/* This should be kept table-like, but isn't automatic due to spaces. */
|
||||
identifier [A-Za-z_][A-Za-z0-9_]*
|
||||
intrinsic_identifier __intrinsic_[A-Za-z0-9_]*
|
||||
sized_type_literal [iuf][1-9][0-9]*
|
||||
integer_literal [0-9]+
|
||||
horizontal_whitespace [ \t\r]
|
||||
@@ -226,7 +227,15 @@ string_literal \"([^\\\"\n\v\f\r]|\\.)*\"
|
||||
/* `*` operator case 5: */
|
||||
<INITIAL,AFTER_OPERAND>"*" { return SIMPLE_TOKEN(UNARY_STAR); }
|
||||
|
||||
{sized_type_literal} { return ARG_TOKEN(sized_type_literal, yytext); }
|
||||
{sized_type_literal} {
|
||||
BEGIN(AFTER_OPERAND);
|
||||
return ARG_TOKEN(sized_type_literal, yytext);
|
||||
}
|
||||
|
||||
{intrinsic_identifier} {
|
||||
BEGIN(AFTER_OPERAND);
|
||||
return ARG_TOKEN(intrinsic_identifier, yytext);
|
||||
}
|
||||
|
||||
{identifier} {
|
||||
BEGIN(AFTER_OPERAND);
|
||||
|
||||
@@ -89,6 +89,7 @@
|
||||
|
||||
%token <int> integer_literal
|
||||
%token <std::string> identifier
|
||||
%token <std::string> intrinsic_identifier
|
||||
%token <std::string> sized_type_literal
|
||||
%token <std::string> string_literal
|
||||
%type <std::string> designator
|
||||
@@ -302,6 +303,8 @@ expression:
|
||||
| paren_expression { $$ = $1; }
|
||||
| struct_literal { $$ = $1; }
|
||||
| struct_type_literal { $$ = $1; }
|
||||
| intrinsic_identifier tuple
|
||||
{ $$ = arena->New<IntrinsicExpression>($1, $2, context.source_loc()); }
|
||||
| expression EQUAL_EQUAL expression
|
||||
{
|
||||
$$ = arena->New<PrimitiveOperatorExpression>(
|
||||
|
||||
Reference in New Issue
Block a user