-
Notifications
You must be signed in to change notification settings - Fork 317
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
Chained if_then_else application change #8671
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c5bef79
Test describing the current behavior of chained if then else application
JaroslavTulach 1c722f4
Chained block should behave just like Group around if_then_else
JaroslavTulach 3f7c373
Finishing line on BlockStart fixes if_then_else_chained_block
JaroslavTulach 14b5c90
Merge remote-tracking branch 'origin/develop' into wip/jtulach/IfThen…
JaroslavTulach 6f5ec2a
Only finish the line when there was not start of a macro segment
JaroslavTulach bc05faa
Fix tests
kazcw 287e307
Refine else-body with macro patterns.
kazcw 131fbeb
Update test syntax to maintain original semantics
kazcw 8348ce8
Few additional tests
JaroslavTulach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,10 @@ pub enum PatternData { | |
Expected(String, Pattern), | ||
/// Named pattern. Mainly used for splicing the code in the macro definition body. | ||
Named(String, Pattern), | ||
/// Consume a block. | ||
Block, | ||
/// Consume any item except a block. | ||
NotBlock, | ||
} | ||
|
||
/// Constructor. | ||
|
@@ -103,6 +107,16 @@ pub fn named(message: impl Into<String>, item: Pattern) -> Pattern { | |
Pattern::new(PatternData::Named(message.into(), item), matches_empty_input) | ||
} | ||
|
||
/// Matches a block. | ||
pub fn block() -> Pattern { | ||
Pattern::new(PatternData::Block, false) | ||
} | ||
|
||
/// Matches anything except a block. | ||
pub fn not_block() -> Pattern { | ||
Pattern::new(PatternData::NotBlock, false) | ||
} | ||
|
||
impl Pattern { | ||
/// Repeat the current pattern multiple times. | ||
pub fn many(self) -> Self { | ||
|
@@ -171,6 +185,7 @@ pub enum Match<'s> { | |
Identifier(syntax::Item<'s>), | ||
Expected(String, Box<Match<'s>>), | ||
Named(String, Box<Match<'s>>), | ||
Block(Vec<syntax::item::Line<'s>>), | ||
NotBlock(syntax::Item<'s>), | ||
} | ||
|
||
|
@@ -208,6 +223,7 @@ impl<'s> Match<'s> { | |
match self { | ||
Self::Nothing => (), | ||
Self::Identifier(item) | Self::NotBlock(item) => out.push(item), | ||
Self::Block(lines) => out.push(syntax::Item::Block(lines)), | ||
Self::Everything(tokens) => out.extend(tokens), | ||
Self::Seq(fst, snd) => { | ||
fst.get_tokens(out); | ||
|
@@ -341,6 +357,23 @@ impl Pattern { | |
Err(input) | ||
}, | ||
}, | ||
PatternData::Block => match input.pop_front() { | ||
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. |
||
None => Err(default()), | ||
Some(syntax::Item::Block(lines)) => | ||
Ok(MatchResult::new(Match::Block(lines), input)), | ||
Some(t) => { | ||
input.push_front(t); | ||
Err(input) | ||
} | ||
}, | ||
PatternData::NotBlock => match input.pop_front() { | ||
None => Err(default()), | ||
Some(t @ syntax::Item::Block(_)) => { | ||
input.push_front(t); | ||
JaroslavTulach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Err(input) | ||
} | ||
Some(t) => Ok(MatchResult::new(Match::NotBlock(t), input)), | ||
}, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,18 +123,17 @@ impl<'a> SegmentMap<'a> { | |
/// to learn more about the macro resolution steps. | ||
#[derive(Debug)] | ||
pub struct Resolver<'s> { | ||
blocks: Vec<Block>, | ||
blocks: Vec<Block>, | ||
/// The lines of all currently-open blocks. This is partitioned by `blocks`. | ||
lines: Vec<syntax::item::Line<'s>>, | ||
lines: Vec<syntax::item::Line<'s>>, | ||
/// All currently-open macros. These are partitioned into scopes by `blocks`. | ||
macros: Vec<PartiallyMatchedMacro<'s>>, | ||
macros: Vec<PartiallyMatchedMacro<'s>>, | ||
/// Segments of all currently-open macros. These are partitioned by `macros`. | ||
segments: Vec<MatchedSegment<'s>>, | ||
segments: Vec<MatchedSegment<'s>>, | ||
/// Items of all segments of all currently-open macros. These are partitioned by `segments`. | ||
items: Vec<syntax::Item<'s>>, | ||
context: Context, | ||
precedence: syntax::operator::Precedence<'s>, | ||
start_segment: bool, | ||
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. Looks like the |
||
items: Vec<syntax::Item<'s>>, | ||
context: Context, | ||
precedence: syntax::operator::Precedence<'s>, | ||
} | ||
|
||
|
||
|
@@ -144,14 +143,13 @@ impl<'s> Resolver<'s> { | |
/// Create a new resolver, in statement context. | ||
pub fn new_statement() -> Self { | ||
Self { | ||
context: Context::Statement, | ||
precedence: syntax::operator::Precedence::new(), | ||
blocks: default(), | ||
lines: default(), | ||
macros: default(), | ||
segments: default(), | ||
items: default(), | ||
start_segment: false, | ||
context: Context::Statement, | ||
precedence: syntax::operator::Precedence::new(), | ||
blocks: default(), | ||
lines: default(), | ||
macros: default(), | ||
segments: default(), | ||
items: default(), | ||
} | ||
} | ||
|
||
|
@@ -229,8 +227,6 @@ impl<'s> Resolver<'s> { | |
|
||
/// Append a token to the state. | ||
fn push(&mut self, root_macro_map: &MacroMap, token: Token<'s>) { | ||
let was_start_segment = self.start_segment; | ||
self.start_segment = false; | ||
match token.variant { | ||
token::Variant::Newline(newline) => { | ||
if !self.lines.is_empty() { | ||
|
@@ -241,10 +237,6 @@ impl<'s> Resolver<'s> { | |
self.context = Context::Statement; | ||
} | ||
token::Variant::BlockStart(_) => { | ||
if !was_start_segment { | ||
trace!("Finishing line!!!! {:?}", token); | ||
self.finish_current_line(); | ||
} | ||
let macros_start = self.macros.len(); | ||
let outputs_start = self.lines.len(); | ||
let items = self.items.len(); | ||
|
@@ -274,7 +266,6 @@ impl<'s> Resolver<'s> { | |
let items_start = self.items.len(); | ||
self.segments.push(MatchedSegment { header, items_start }); | ||
self.context = Context::Expression; | ||
self.start_segment = true; | ||
break; | ||
} | ||
Step::NormalToken(item) => { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not completely sure what is supposed to be a difference between
everything()
andor(x,not(x))
- in binary logicx or not x
is always true - e.g. close toeverything()
. Here we haveor(block(), many(not_block())))
which is almostor(block(), not_block()))
- e.g.x or not x
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
many
is important! The difference is that this will either match a block at the beginning, or a sequence of non-block items--but unlikeeverything
, it won't match a sequence of non-block items followed by a block.