Skip to content
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

Cannot add @position to external rules #12

Closed
oovm opened this issue Nov 20, 2022 · 2 comments
Closed

Cannot add @position to external rules #12

oovm opened this issue Nov 20, 2022 · 2 comments

Comments

@oovm
Copy link

oovm commented Nov 20, 2022

peg side

@position
@extern(crate::utils::unicode_whitespace)
UnicodeSpace;

rust side

pub fn unicode_whitespace(input: &str) -> Result<(&str, usize), &'static str> {
    let mut length = 0;
    for char in input.chars() {
        if char.is_whitespace() { length += char.len_utf8() } else { break }
    }
    if length == 0 { Err("Not unicode whitespace") } else { Ok((&input[0..length], length)) }
}

except:

start offset + length offset

actual:

Caused by:
  process didn't exit successfully: `target\debug\build\saha-parser-579f728ace3fbfac\build-script-build` (exit code: 101)
  --- stderr
  thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: expected character from character class IdentifierChar
  --> src/parser.peg:54:1
   |
   |  @position
   |  ^
  ', projects\saha-parser\build.rs:7:77
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
@badicsalex
Copy link
Owner

Without @position, UnicodeSpace will be a type alias to String. I guess in your example it would become a struct with a single value and position fields? Or just the position?
I'm not sure how universal these would be and if it fit anyone else's use-case. I'd prefer to wait for someone else with a similar problem.

For now I'd suggest doing something like:

@extern(crate::utils::unicode_whitespace)
UnicodeSpaceExt;

@position
UnicodeSpace = spaces:UnicodeSpaceExt;

@oovm
Copy link
Author

oovm commented Nov 21, 2022

Good idea

@oovm oovm closed this as completed Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants