mirror of
https://github.com/fluencelabs/lalrpop
synced 2025-03-28 06:01:02 +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.rs
|
||||||
lalrpop-test/src/error_issue_113.rs
|
lalrpop-test/src/error_issue_113.rs
|
||||||
lalrpop-test/src/error_issue_278.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.rs
|
||||||
lalrpop-test/src/error_recovery_pull_182.rs
|
lalrpop-test/src/error_recovery_pull_182.rs
|
||||||
lalrpop-test/src/error_recovery_issue_240.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");
|
"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 {
|
if let Some(d) = self.extern_token {
|
||||||
return_err!(
|
if d.enum_token.is_some() {
|
||||||
d.span,
|
return_err!(
|
||||||
"extern and match definitions are mutually exclusive");
|
d.span,
|
||||||
|
"extern (with custom tokens) and match definitions are mutually exclusive");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure that the catch all is final item of final block
|
// 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");
|
"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 {
|
if let Some(d) = self.match_token {
|
||||||
return_err!(
|
if data.enum_token.is_some() {
|
||||||
d.span,
|
return_err!(
|
||||||
"match and extern definitions are mutually exclusive");
|
d.span,
|
||||||
|
"match and extern (with custom tokens) definitions are mutually exclusive");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let allowed_names = vec![intern(LOCATION), intern(ERROR)];
|
let allowed_names = vec![intern(LOCATION), intern(ERROR)];
|
||||||
|
@ -82,7 +82,7 @@ fn multiple_match_token() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn match_after_extern_token() {
|
fn match_after_extern_token() {
|
||||||
check_err(
|
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#"grammar; extern { enum Tok { } } match { _ }"#,
|
||||||
r#" ~~~~~ "#);
|
r#" ~~~~~ "#);
|
||||||
}
|
}
|
||||||
@ -90,7 +90,7 @@ fn match_after_extern_token() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn extern_after_match_token() {
|
fn extern_after_match_token() {
|
||||||
check_err(
|
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#"grammar; match { _ } extern { enum Tok { } }"#,
|
||||||
r#" ~~~~~~ "#);
|
r#" ~~~~~~ "#);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user