mirror of
https://github.com/fluencelabs/lalrpop
synced 2025-03-16 17:00:53 +00:00
Merge pull request #277 from vmx/relax-extern-match
Allow match definition if no custom tokens are defined
This commit is contained in:
commit
038ea15f04
1
.gitignore
vendored
1
.gitignore
vendored
@ -17,6 +17,7 @@ doc/whitespace/src/parser.rs
|
||||
lalrpop-test/src/error.rs
|
||||
lalrpop-test/src/error_issue_113.rs
|
||||
lalrpop-test/src/error_issue_278.rs
|
||||
lalrpop-test/src/error_issue_261.rs
|
||||
lalrpop-test/src/error_recovery.rs
|
||||
lalrpop-test/src/error_recovery_pull_182.rs
|
||||
lalrpop-test/src/error_recovery_issue_240.rs
|
||||
|
25
lalrpop-test/src/error_issue_261.lalrpop
Normal file
25
lalrpop-test/src/error_issue_261.lalrpop
Normal file
@ -0,0 +1,25 @@
|
||||
use std::str::FromStr;
|
||||
use lalrpop_util::ParseError;
|
||||
|
||||
grammar;
|
||||
|
||||
extern {
|
||||
type Error = &'static str;
|
||||
}
|
||||
|
||||
pub Value: f64 = {
|
||||
<n:Float> => n,
|
||||
<n:Int> => n as f64,
|
||||
};
|
||||
|
||||
|
||||
Int: u64 = r"\d+"
|
||||
=>? u64::from_str(<>).map_err(|_| ParseError::User{ error: "invalid int" });
|
||||
Float: f64 = r"\d+(\.\d+)?(e-?\d+)?"
|
||||
=>? f64::from_str(<>).map_err(|_| ParseError::User{ error: "invalid float" });
|
||||
|
||||
match {
|
||||
r"\d+(\.\d+)?(e-?\d+)?"
|
||||
} else {
|
||||
_
|
||||
}
|
@ -66,11 +66,13 @@ impl<'grammar> Validator<'grammar> {
|
||||
"multiple match definitions are not permitted");
|
||||
}
|
||||
|
||||
// We may want to allow a limited extern to coexist with match in the future
|
||||
// Only error if a custom lexer is specified, having a custom types is ok
|
||||
if let Some(d) = self.extern_token {
|
||||
return_err!(
|
||||
d.span,
|
||||
"extern and match definitions are mutually exclusive");
|
||||
if d.enum_token.is_some() {
|
||||
return_err!(
|
||||
d.span,
|
||||
"extern (with custom tokens) and match definitions are mutually exclusive");
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure that the catch all is final item of final block
|
||||
@ -94,11 +96,13 @@ impl<'grammar> Validator<'grammar> {
|
||||
"multiple extern definitions are not permitted");
|
||||
}
|
||||
|
||||
// We may want to allow a limited extern to coexist with match in the future
|
||||
// Only error if a custom lexer is specified, having a custom types is ok
|
||||
if let Some(d) = self.match_token {
|
||||
return_err!(
|
||||
d.span,
|
||||
"match and extern definitions are mutually exclusive");
|
||||
if data.enum_token.is_some() {
|
||||
return_err!(
|
||||
d.span,
|
||||
"match and extern (with custom tokens) definitions are mutually exclusive");
|
||||
}
|
||||
}
|
||||
|
||||
let allowed_names = vec![intern(LOCATION), intern(ERROR)];
|
||||
|
@ -82,7 +82,7 @@ fn multiple_match_token() {
|
||||
#[test]
|
||||
fn match_after_extern_token() {
|
||||
check_err(
|
||||
r#"match and extern definitions are mutually exclusive"#,
|
||||
r#"match and extern \(with custom tokens\) definitions are mutually exclusive"#,
|
||||
r#"grammar; extern { enum Tok { } } match { _ }"#,
|
||||
r#" ~~~~~ "#);
|
||||
}
|
||||
@ -90,7 +90,7 @@ fn match_after_extern_token() {
|
||||
#[test]
|
||||
fn extern_after_match_token() {
|
||||
check_err(
|
||||
r#"extern and match definitions are mutually exclusive"#,
|
||||
r#"extern \(with custom tokens\) and match definitions are mutually exclusive"#,
|
||||
r#"grammar; match { _ } extern { enum Tok { } }"#,
|
||||
r#" ~~~~~~ "#);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user