Skip to content

Commit

Permalink
Add support for program address literals (ex: hello.aleo) & `self.a…
Browse files Browse the repository at this point in the history
…ddress`
  • Loading branch information
evan-schott committed Apr 23, 2024
1 parent f93d77b commit dda608f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion compiler/ast/src/expressions/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use super::*;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum Literal {
// todo: deserialize values here
/// An address literal, e.g., `aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8s7pyjh9`.
/// An address literal, e.g., `aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8s7pyjh9` or `hello.aleo`.
Address(String, #[serde(with = "leo_span::span_json")] Span, NodeID),
/// A boolean literal, either `true` or `false`.
Boolean(bool, #[serde(with = "leo_span::span_json")] Span, NodeID),
Expand Down
3 changes: 0 additions & 3 deletions compiler/parser/src/parser/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,6 @@ impl ParserContext<'_> {

// Parses an external function call `credits.aleo/transfer()` or locator `token.aleo/accounts`.
fn parse_external_resource(&mut self, expr: Expression, network_span: Span) -> Result<Expression> {
// Eat an external function call.
self.eat(&Token::Div); // todo: Make `/` a more general token.

// Parse name.
let name = self.expect_identifier()?;

Expand Down
4 changes: 3 additions & 1 deletion compiler/passes/src/flattening/flatten_statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ impl StatementReconstructor for Flattener<'_> {
let guard = self.construct_guard();

match input.expression {
Expression::Unit(_) | Expression::Identifier(_) | Expression::Access(_) => self.returns.push((guard, input)),
Expression::Unit(_) | Expression::Identifier(_) | Expression::Access(_) => {
self.returns.push((guard, input))
}
_ => unreachable!("SSA guarantees that the expression is always an identifier or unit expression."),
};

Expand Down
21 changes: 21 additions & 0 deletions tests/expectations/parser/expression/literal/address_parse.out
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,24 @@ outputs:
lo: 0
hi: 63
- 0
- Literal:
Address:
- hello
- span:
lo: 0
hi: 5
- 1
- Literal:
Address:
- fooooo
- span:
lo: 0
hi: 6
- 1
- Literal:
Address:
- bar
- span:
lo: 0
hi: 3
- 1

0 comments on commit dda608f

Please sign in to comment.