Skip to content

Commit 0e086d6

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

File tree

6 files changed

+42
-21
lines changed

6 files changed

+42
-21
lines changed

src/lex.rs

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

83-
// Name ↔ Name
84-
#[regex = r"[a-zA-Z][_a-zA-Z0-9]*"]
83+
84+
// Ideally we would have:
85+
// // Name ↔ Name
86+
// #[regex = r"[a-zA-Z][_a-zA-Z0-9]*"]
87+
// Name,
88+
//
89+
// as well as
90+
//
91+
// // FancyNameUnicode ↔ FancyNameAscii
92+
// #[regex = r"[a-zA-Z ... \p{Greek} ...]"]
93+
// FancyNameUnicode,
94+
//
95+
// But these regular expressions overlap, and its ambiguous
96+
// which one a merely ascii string would match
97+
98+
#[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}]*"]
8599
Name,
86100

87101
// Since this uses Coptic letters for keywords all greek letters can be used as variable names.
@@ -111,8 +125,6 @@ pub enum LexToken {
111125
// FancyNameAscii ↔ FancyNameUnicode
112126
#[regex = r"[\\][a-zA-Z][_a-zA-Z0-9]*"]
113127
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,
116128

117129
#[token = ":"]
118130
Colon,

src/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ 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| { println!("{:?}", x); x});
127+
match parser::propParser::new().parse(tokens) {
126128
Ok(_) => panic!(format!("accepted '{}'", s)),
127129
Err(e) => println!("got an expected error: {:?}", e),
128130
}
@@ -174,7 +176,6 @@ fn bad_ascii() -> Result<(), &'static str> {
174176
}
175177
}
176178

177-
178179
fn from_rowan<'a>(s: &'a str) -> Result<(), MainError> {
179180
let tokens = rowan_token::Tokens::from_string(&s);
180181
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: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,29 @@ impl<'a> Iterator for Tokens<'a> {
6666
}
6767
}
6868

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

7583
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);
84+
let parse_result = rowan_parser::propParser::new().parse(&mut builder, tokens);
85+
match parse_result {
86+
Ok(_) => (),
87+
Err(e) => {
88+
println!("{:?}", e);
89+
return Err(error::MainError::SomethingWentAwryAndStuffWasPrinted);
8090
}
81-
*/
91+
}
8292
builder.finish_node();
8393
Ok(())
8494
}

src/test_util.rs

Lines changed: 5 additions & 4 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

@@ -12,7 +10,10 @@ pub fn do_test<'a>(sources: &[&'a str]) -> Result<(), Vec<(&'a str, Error<'a>)>>
1210
.map(|(index, s)| {
1311
(
1412
index,
15-
parser::propParser::new().parse(lex::Tokens::from_string(s)),
13+
{ let tokens = token_wrap::Tokens::from_string(s);
14+
let tokens = tokens.map(|x| { println!("{:?}", x); x});
15+
parser::propParser::new().parse(tokens)
16+
}
1617
)
1718
})
1819
.partition(|(_, r)| r.is_ok());

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)