-
Notifications
You must be signed in to change notification settings - Fork 2
Format improvements (WIP) #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
2ed6200
a8b2ad4
e66c92d
f3de737
96c1d4c
7fe31f4
4d089ac
9605ae3
5ff6724
b3e8508
b70b2ed
17ce209
92292d5
3d32e3b
88e5a47
26f14dc
6e5e625
8d9e7a8
7a8dd56
4e2e6a2
ac21a91
fba8534
e04f291
20a4da0
b2dcd1c
7778c45
21c30dd
3bdc5fa
e9c3d28
471b51d
1a5964e
8eb4c4b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -462,7 +462,7 @@ pub enum Expr { | |
| value: raw::LangInt, | ||
| /// A hint to the formatter on how it should write the integer. | ||
| /// (may not necessarily represent the original radix of a parsed token) | ||
| radix: IntRadix, | ||
| format: IntFormat, | ||
| }, | ||
| LitFloat { value: raw::LangFloat }, | ||
| LitString(LitString), | ||
|
|
@@ -476,14 +476,18 @@ pub enum Expr { | |
| }, | ||
| } | ||
|
|
||
| #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] | ||
| pub struct IntFormat { | ||
| pub unsigned: bool, | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might prefer
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I went with
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| pub radix: IntRadix, | ||
| } | ||
|
|
||
| #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
| pub enum IntRadix { | ||
| /// Display as decimal. | ||
| Dec, | ||
| /// Display as hexadecimal, with an `0x` prefix. | ||
| Hex, | ||
| /// Display as potentially negative hexadecimal, with an `0x` prefix. | ||
| SignedHex, | ||
| /// Display as binary, with an `0b` prefix. | ||
| Bin, | ||
| /// Use `true` and `false` if the value is `1` or `0`. Otherwise, fall back to decimal. | ||
|
|
@@ -848,7 +852,7 @@ string_enum! { | |
| } | ||
|
|
||
| impl From<raw::LangInt> for Expr { | ||
| fn from(value: raw::LangInt) -> Expr { Expr::LitInt { value, radix: IntRadix::Dec } } | ||
| fn from(value: raw::LangInt) -> Expr { Expr::LitInt { value, format: IntFormat { unsigned: false, radix: IntRadix::Dec } } } | ||
| } | ||
| impl From<raw::LangFloat> for Expr { | ||
| fn from(value: raw::LangFloat) -> Expr { Expr::LitFloat { value } } | ||
|
|
@@ -1266,7 +1270,7 @@ macro_rules! generate_visitor_stuff { | |
| Expr::XcrementOp { op: _, order: _, var } => { | ||
| v.visit_var(var); | ||
| }, | ||
| Expr::LitInt { value: _, radix: _ } => {}, | ||
| Expr::LitInt { value: _, format: _ } => {}, | ||
| Expr::LitFloat { value: _ } => {}, | ||
| Expr::LitString(_s) => {}, | ||
| Expr::LabelProperty { .. } => {}, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1114,34 +1114,18 @@ impl Signature { | |
| signature_from_func_ast(ty_keyword, params) | ||
| } | ||
|
|
||
| pub(crate) fn validate(&self, ctx: &CompilerContext) -> Result<(), ErrorReported> { | ||
| self._check_non_optional_after_optional(ctx) | ||
| } | ||
|
|
||
| fn _check_non_optional_after_optional(&self, ctx: &CompilerContext) -> Result<(), ErrorReported> { | ||
| let mut first_optional = None; | ||
| for param in self.params.iter() { | ||
| if param.default.is_some() { | ||
| first_optional = Some(param); | ||
| } else if let Some(optional) = first_optional { | ||
| return Err(ctx.emitter.emit(error!( | ||
| message("invalid function signature"), | ||
| secondary(optional.useful_span, "optional parameter"), | ||
| primary(param.useful_span, "non-optional parameter after optional"), | ||
| ))); | ||
| } | ||
| } | ||
| pub(crate) fn validate(&self, _ctx: &CompilerContext) -> Result<(), ErrorReported> { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was removed because its only purpose was to handle the padding arguments from old STD. This was refactored into the _ and - formats usable in any script type rather than optional arguments, so this check is unnecessary |
||
| Ok(()) | ||
| } | ||
|
|
||
| /// Minimum number of arguments accepted. | ||
| pub fn min_args(&self) -> usize { | ||
| self.params.iter().take_while(|param| param.default.is_none()).count() | ||
| self.params.iter().fold(0, |count, param| count + param.default.is_none() as usize) | ||
| } | ||
|
|
||
| /// Maximum number of arguments accepted. | ||
| pub fn max_args(&self) -> usize { | ||
| self.params.len() | ||
| self.min_args() | ||
| } | ||
|
|
||
| /// Matches arguments at a call site to their corresponding parameters. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.