Skip to content

Commit f1d0d18

Browse files
committed
try and get tests working...
1 parent 4881ee1 commit f1d0d18

File tree

6 files changed

+49
-24
lines changed

6 files changed

+49
-24
lines changed

src/lex.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,20 @@ pub enum LexToken {
8080
#[token = ")"]
8181
RParen,
8282

83-
// Name ↔ Name
84-
#[regex = r"[a-zA-Z][_a-zA-Z0-9]*"]
83+
// Ideally we would have:
84+
// // Name ↔ Name
85+
// #[regex = r"[a-zA-Z][_a-zA-Z0-9]*"]
86+
// Name,
87+
//
88+
// as well as
89+
//
90+
// // FancyNameUnicode ↔ FancyNameAscii
91+
// #[regex = r"[a-zA-Z ... \p{Greek} ...]"]
92+
// FancyNameUnicode,
93+
//
94+
// But these regular expressions overlap, and its ambiguous
95+
// which one a merely ascii string would match
96+
#[regex = r"[a-zA-Z\p{Greek}\x{1d49c}-\x{1d59f}\x{2100}-\x{214f}][_a-zA-Z0-9\x{207f}-\x{2089}\x{2090}-\x{209c}\x{1d62}-\x{1d6a}]*"]
8597
Name,
8698

8799
// Since this uses Coptic letters for keywords all greek letters can be used as variable names.
@@ -111,8 +123,6 @@ pub enum LexToken {
111123
// FancyNameAscii ↔ FancyNameUnicode
112124
#[regex = r"[\\][a-zA-Z][_a-zA-Z0-9]*"]
113125
FancyNameAscii,
114-
#[regex = r"[a-zA-Z\p{Greek}\x{1d49c}-\x{1d59f}\x{2100}-\x{214f}][_a-zA-Z0-9\x{207f}-\x{2089}\x{2090}-\x{209c}\x{1d62}-\x{1d6a}]*"]
115-
FancyNameUnicode,
116126

117127
#[token = ":"]
118128
Colon,

src/main.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,12 @@ fn bad_unicode() -> () {
122122
];
123123

124124
for s in invalid_source.iter() {
125-
match parser::propParser::new().parse(token_wrap::Tokens::from_string(s)) {
125+
let tokens = token_wrap::Tokens::from_string(s);
126+
let tokens = tokens.map(|x| {
127+
println!("{:?}", x);
128+
x
129+
});
130+
match parser::propParser::new().parse(tokens) {
126131
Ok(_) => panic!(format!("accepted '{}'", s)),
127132
Err(e) => println!("got an expected error: {:?}", e),
128133
}
@@ -174,7 +179,6 @@ fn bad_ascii() -> Result<(), &'static str> {
174179
}
175180
}
176181

177-
178182
fn from_rowan<'a>(s: &'a str) -> Result<(), MainError> {
179183
let tokens = rowan_token::Tokens::from_string(&s);
180184
let mut builder = rowan::GreenNodeBuilder::new();

src/rowan_prop.lalrpop

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::rowan_token::TokenWrap;
66
use TokenWrap::Token;
77
grammar<'a>(gb: &mut GreenNodeBuilder<'static>);
88

9-
109
extern {
1110
type Location = usize;
1211
type Error = LexicalError;
@@ -32,14 +31,12 @@ extern {
3231
")" => Token{token: LexToken::RParen, string: <SmolStr>},
3332
Name => Token{token: LexToken::Name, string: <SmolStr>},
3433
FancyNameAscii => Token{token: LexToken::FancyNameAscii, string: <SmolStr>},
35-
FancyNameUnicode => Token{token: LexToken::FancyNameUnicode, string: <SmolStr>},
3634
}
3735
}
3836

3937
name: (LexToken, SmolStr) = {
4038
Name => (LexToken::Name.into(), <>),
4139
FancyNameAscii => (LexToken::FancyNameAscii.into(), <>),
42-
FancyNameUnicode => (LexToken::FancyNameUnicode.into(), <>),
4340
}
4441

4542
pub prop = Semi<Binding>;
@@ -112,5 +109,6 @@ BinaryProp: Prop = {
112109
Term: Prop = {
113110
"⊤" => Prop::True,
114111
"(" <p:Prop> ")" => p,
112+
<n:name> => Prop::Var(n.1.into()),
115113
};
116114

src/rowan_token.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,31 @@ impl<'a> Iterator for Tokens<'a> {
6666
}
6767
}
6868

69+
#[cfg(test)]
70+
use crate::{error, lex, rowan_parser, test_util};
71+
6972
#[test]
7073
fn rowan_lex() -> Result<(), error::MainError> {
71-
let s = "X := X";
72-
let lexer = token_wrap::TokensRowan::from_string(&s);
74+
let s = "trivial ≔ ⊤; X ≔ ⊤; Y := Z;";
75+
test_util::expect_success(test_util::do_test(&[s]))?;
76+
77+
let tokens = Tokens::from_string(s);
78+
let tokens = tokens.map(|x| {
79+
println!("{:?}", x);
80+
x
81+
});
82+
7383
let mut builder = rowan::GreenNodeBuilder::new();
7484

7585
builder.start_node(lex::LexToken::Root.into());
76-
let parse_result = rowan_parser::propParser::new().parse(&mut builder, tokens)?;
77-
/* for thing in lexer {
78-
let checkpoint = self.builder.checkpoint();
79-
println!("{:?}", thing);
86+
let parse_result = rowan_parser::propParser::new().parse(&mut builder, tokens);
87+
match parse_result {
88+
Ok(_) => (),
89+
Err(e) => {
90+
println!("{:?}", e);
91+
return Err(error::MainError::SomethingWentAwryAndStuffWasPrinted);
8092
}
81-
*/
93+
}
8294
builder.finish_node();
8395
Ok(())
8496
}

src/test_util.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
use crate::codespan;
21
use crate::error::*;
3-
use crate::lex;
4-
use crate::parser;
2+
use crate::{codespan, parser, token_wrap};
53
use codespan_reporting::term;
64
use codespan_reporting::term::termcolor::{ColorChoice, StandardStream};
75

@@ -10,10 +8,14 @@ pub fn do_test<'a>(sources: &[&'a str]) -> Result<(), Vec<(&'a str, Error<'a>)>>
108
.iter()
119
.enumerate()
1210
.map(|(index, s)| {
13-
(
14-
index,
15-
parser::propParser::new().parse(lex::Tokens::from_string(s)),
16-
)
11+
(index, {
12+
let tokens = token_wrap::Tokens::from_string(s);
13+
let tokens = tokens.map(|x| {
14+
println!("{:?}", x);
15+
x
16+
});
17+
parser::propParser::new().parse(tokens)
18+
})
1719
})
1820
.partition(|(_, r)| r.is_ok());
1921
if fail.is_empty() {

src/token_wrap.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ impl<'a> Iterator for Tokens<'a> {
6464
LexToken::LexError => break Err(LexicalError(range)),
6565
LexToken::Name => break ok(Token::Name(lex.slice())),
6666
LexToken::FancyNameAscii => break ok(Token::Name(lex.slice())),
67-
LexToken::FancyNameUnicode => break ok(Token::Name(lex.slice())),
6867
// And the rest are all unary members
6968
LexToken::Dot => break ok(Token::Dot),
7069
LexToken::Abs => break ok(Token::Abs),

0 commit comments

Comments
 (0)