step_p21/parser/basic.rs
1//! Parser for basic alphabets defined in the table 1 of ISO-10303-21
2
3#![allow(clippy::manual_is_ascii_check)]
4
5use super::combinator::*;
6use nom::{
7 Parser,
8 branch::alt,
9 character::complete::{char, satisfy},
10};
11
12/// latin_codepoint = [space] | [digit] | [lower] | [upper] | [special] |
13/// [reverse_solidus] | [apostrophe]
14pub fn latin_codepoint(input: &str) -> ParseResult<'_, char> {
15 alt((
16 space,
17 digit,
18 lower,
19 upper,
20 special,
21 reverse_solidus,
22 apostrophe,
23 ))
24 .parse(input)
25}
26
27/// space = ` ` .
28pub fn space(input: &str) -> ParseResult<'_, char> {
29 char(' ')(input)
30}
31
32/// digit = `0` | `1` | `2` | `3` | `4` | `5` | `6` | `7` | `8` | `9` .
33pub fn digit(input: &str) -> ParseResult<'_, char> {
34 satisfy(|c| matches!(c, '0'..='9')).parse(input)
35}
36
37/// lower = `a` | `b` | `c` | `d` | `e` | `f` | `g` | `h`
38/// | `i` | `j` | `k` | `l` | `m` | `n` | `o` | `p`
39/// | `q` | `r` | `s` | `t` | `u` | `v` | `w` | `x`
40/// | `y` | `z` .
41pub fn lower(input: &str) -> ParseResult<'_, char> {
42 satisfy(|c| matches!(c, 'a'..='z')).parse(input)
43}
44
45/// upper = `A` | `B` | `C` | `D` | `E` | `F` | `G` | `H`
46/// | `I` | `J` | `K` | `L` | `M` | `N` | `O` | `P`
47/// | `Q` | `R` | `S` | `T` | `U` | `V` | `W` | `X`
48/// | `Y` | `Z` | `_` .
49pub fn upper(input: &str) -> ParseResult<'_, char> {
50 satisfy(|c| matches!(c, 'A'..='Z' | '_')).parse(input)
51}
52
53/// special = `!` | `"` | `*` | `$` | `%` | `&` | `.` | `#` | `+` | `,` | `-`
54/// | `(` | `)` | `?` | `/` | `:` | `;` | `<` | `=` | `>` | `@` | `[` | `]` |
55/// `{` | `|` | `}` | `^` | \` | `~` .
56pub fn special(input: &str) -> ParseResult<'_, char> {
57 satisfy(|c| {
58 matches!(
59 c,
60 '!' | '"'
61 | '*'
62 | '$'
63 | '%'
64 | '&'
65 | '.'
66 | '#'
67 | '+'
68 | ','
69 | '-'
70 | '('
71 | ')'
72 | '?'
73 | '/'
74 | ':'
75 | ';'
76 | '<'
77 | '='
78 | '>'
79 | '@'
80 | '['
81 | ']'
82 | '{'
83 | '|'
84 | '}'
85 | '^'
86 | '`'
87 | '~'
88 )
89 })
90 .parse(input)
91}
92
93/// reverse_solidus = `\\` .
94pub fn reverse_solidus(input: &str) -> ParseResult<'_, char> {
95 char('\\')(input)
96}
97
98/// apostrophe = `'` .
99pub fn apostrophe(input: &str) -> ParseResult<'_, char> {
100 char('\'')(input)
101}