mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 00:01:16 +00:00
Parse number literal width suffixes
Supports [u,i][8,16,32,64,128] and [nat,dec] Part of #2350
This commit is contained in:
parent
545882f210
commit
320827167f
112 changed files with 1159 additions and 127 deletions
|
@ -6,7 +6,8 @@ use crate::spaces::{fmt_comments_only, fmt_spaces, NewlineAt, INDENT};
|
|||
use crate::Buf;
|
||||
use roc_module::called_via::{self, BinOp};
|
||||
use roc_parse::ast::{
|
||||
AssignedField, Base, Collection, CommentOrNewline, Expr, ExtractSpaces, Pattern, WhenBranch,
|
||||
AssignedField, Base, Collection, CommentOrNewline, Expr, ExtractSpaces, NumericBound, Pattern,
|
||||
WhenBranch,
|
||||
};
|
||||
use roc_parse::ast::{StrLiteral, StrSegment};
|
||||
use roc_region::all::Loc;
|
||||
|
@ -27,8 +28,8 @@ impl<'a> Formattable for Expr<'a> {
|
|||
}
|
||||
|
||||
// These expressions never have newlines
|
||||
Float(_)
|
||||
| Num(_)
|
||||
Float(..)
|
||||
| Num(..)
|
||||
| NonBase10Int { .. }
|
||||
| Access(_, _)
|
||||
| AccessorFunction(_)
|
||||
|
@ -196,7 +197,23 @@ impl<'a> Formattable for Expr<'a> {
|
|||
buf.push(')');
|
||||
}
|
||||
}
|
||||
Num(string) | Float(string) | GlobalTag(string) | PrivateTag(string) => {
|
||||
Num(string, bound) => {
|
||||
buf.indent(indent);
|
||||
buf.push_str(string);
|
||||
|
||||
if let &NumericBound::Exact(width) = bound {
|
||||
buf.push_str(&width.to_string());
|
||||
}
|
||||
}
|
||||
Float(string, bound) => {
|
||||
buf.indent(indent);
|
||||
buf.push_str(string);
|
||||
|
||||
if let &NumericBound::Exact(width) = bound {
|
||||
buf.push_str(&width.to_string());
|
||||
}
|
||||
}
|
||||
GlobalTag(string) | PrivateTag(string) => {
|
||||
buf.indent(indent);
|
||||
buf.push_str(string)
|
||||
}
|
||||
|
@ -204,6 +221,7 @@ impl<'a> Formattable for Expr<'a> {
|
|||
base,
|
||||
string,
|
||||
is_negative,
|
||||
bound,
|
||||
} => {
|
||||
buf.indent(indent);
|
||||
if *is_negative {
|
||||
|
@ -218,6 +236,10 @@ impl<'a> Formattable for Expr<'a> {
|
|||
}
|
||||
|
||||
buf.push_str(string);
|
||||
|
||||
if let &NumericBound::Exact(width) = bound {
|
||||
buf.push_str(&width.to_string());
|
||||
}
|
||||
}
|
||||
Record(fields) => {
|
||||
fmt_record(buf, None, *fields, indent);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::annotation::{Formattable, Newlines, Parens};
|
||||
use crate::spaces::{fmt_comments_only, fmt_spaces, NewlineAt};
|
||||
use crate::Buf;
|
||||
use roc_parse::ast::{Base, Pattern};
|
||||
use roc_parse::ast::{Base, NumericBound, Pattern};
|
||||
|
||||
pub fn fmt_pattern<'a, 'buf>(
|
||||
buf: &mut Buf<'buf>,
|
||||
|
@ -31,9 +31,9 @@ impl<'a> Formattable for Pattern<'a> {
|
|||
| Pattern::GlobalTag(_)
|
||||
| Pattern::PrivateTag(_)
|
||||
| Pattern::Apply(_, _)
|
||||
| Pattern::NumLiteral(_)
|
||||
| Pattern::NumLiteral(..)
|
||||
| Pattern::NonBase10Literal { .. }
|
||||
| Pattern::FloatLiteral(_)
|
||||
| Pattern::FloatLiteral(..)
|
||||
| Pattern::StrLiteral(_)
|
||||
| Pattern::Underscore(_)
|
||||
| Pattern::Malformed(_)
|
||||
|
@ -116,14 +116,18 @@ impl<'a> Formattable for Pattern<'a> {
|
|||
loc_pattern.format(buf, indent);
|
||||
}
|
||||
|
||||
NumLiteral(string) => {
|
||||
NumLiteral(string, bound) => {
|
||||
buf.indent(indent);
|
||||
buf.push_str(string);
|
||||
if let &NumericBound::Exact(width) = bound {
|
||||
buf.push_str(&width.to_string());
|
||||
}
|
||||
}
|
||||
NonBase10Literal {
|
||||
base,
|
||||
string,
|
||||
is_negative,
|
||||
bound,
|
||||
} => {
|
||||
buf.indent(indent);
|
||||
if *is_negative {
|
||||
|
@ -138,10 +142,17 @@ impl<'a> Formattable for Pattern<'a> {
|
|||
}
|
||||
|
||||
buf.push_str(string);
|
||||
|
||||
if let &NumericBound::Exact(width) = bound {
|
||||
buf.push_str(&width.to_string());
|
||||
}
|
||||
}
|
||||
FloatLiteral(string) => {
|
||||
FloatLiteral(string, bound) => {
|
||||
buf.indent(indent);
|
||||
buf.push_str(string);
|
||||
if let &NumericBound::Exact(width) = bound {
|
||||
buf.push_str(&width.to_string());
|
||||
}
|
||||
}
|
||||
StrLiteral(literal) => {
|
||||
todo!("Format string literal: {:?}", literal);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue