-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for any character in multiline comments + tests
- Loading branch information
Showing
4 changed files
with
65 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,4 @@ extern crate unicode_reader; | |
pub mod parser; | ||
pub mod put_back_n; | ||
|
||
mod lexer; | ||
pub mod lexer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
extern crate prolog_parser; | ||
|
||
use prolog_parser::ast::*; | ||
use prolog_parser::lexer::{Lexer, Token}; | ||
use prolog_parser::tabled_rc::TabledData; | ||
|
||
use std::rc::Rc; | ||
|
||
fn read_all_tokens(text: &str) -> Result<Vec<Token>, ParserError> { | ||
let atom_tbl = TabledData::new(Rc::new("my_module".to_string())); | ||
let flags = MachineFlags::default(); | ||
let mut stream = parsing_stream(text.as_bytes()); | ||
let mut lexer = Lexer::new(atom_tbl, flags, &mut stream); | ||
|
||
let mut tokens = Vec::new(); | ||
while !lexer.eof()? { | ||
let token = lexer.next_token()?; | ||
tokens.push(token); | ||
} | ||
Ok(tokens) | ||
} | ||
|
||
#[test] | ||
fn empty_multiline_comment() -> Result<(), ParserError> { | ||
let tokens = read_all_tokens("/**/ 4\n")?; | ||
assert_eq!(tokens, [Token::Constant(Constant::Fixnum(4))]); | ||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn any_char_multiline_comment() -> Result<(), ParserError> { | ||
let tokens = read_all_tokens("/* █╗╚═══╝ © */ 4\n")?; | ||
assert_eq!(tokens, [Token::Constant(Constant::Fixnum(4))]); | ||
Ok(()) | ||
} |