-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow precedence expressions to omit operator classes
- Loading branch information
1 parent
93061e8
commit 9776de1
Showing
196 changed files
with
4,859 additions
and
7,783 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,73 @@ | ||
#[derive(Debug)] | ||
#[allow(non_camel_case_types)] | ||
pub enum TokenKind { | ||
comment, | ||
constant, | ||
keyword, | ||
operator, | ||
string, | ||
} | ||
|
||
pub trait EBNFWriter { | ||
fn write_token(&mut self, kind: TokenKind, value: &str); | ||
fn write_line_break(&mut self); | ||
|
||
fn write_production_definition(&mut self, production_name: &str); | ||
fn write_production_reference(&mut self, production_name: &str); | ||
|
||
fn write_prelude(&mut self) {} | ||
fn write_postlude(&mut self) {} | ||
fn write_line_start(&mut self) {} | ||
|
||
fn write_comment(&mut self, value: &str) { | ||
self.write_token(TokenKind::comment, value) | ||
} | ||
fn write_constant(&mut self, value: &str) { | ||
self.write_token(TokenKind::constant, value) | ||
} | ||
fn write_keyword(&mut self, value: &str) { | ||
self.write_token(TokenKind::keyword, value) | ||
} | ||
fn write_operator(&mut self, value: &str) { | ||
self.write_token(TokenKind::operator, value) | ||
} | ||
fn write_string(&mut self, value: &str) { | ||
self.write_token(TokenKind::string, &Self::format_string_literal(value)) | ||
} | ||
|
||
fn format_string_literal(value: &str) -> String { | ||
let delimiter = if value.len() == 1 { | ||
if value.contains("'") && !value.contains('"') { | ||
'"' | ||
} else { | ||
'\'' | ||
} | ||
} else { | ||
if value.contains('"') && !value.contains("'") { | ||
'\'' | ||
} else { | ||
'"' | ||
} | ||
}; | ||
|
||
let formatted: String = value | ||
.chars() | ||
.map(|c| { | ||
if c == '\'' || c == '\\' { | ||
format!("\\{}", c) | ||
} else if c.is_ascii_graphic() || c == '¬' || c == '…' || c == '«' || c == '»' | ||
{ | ||
c.to_string() | ||
} else { | ||
c.escape_unicode().to_string() | ||
} | ||
}) | ||
.collect(); | ||
|
||
return format!("{}{}{}", delimiter, formatted, delimiter); | ||
} | ||
} | ||
|
||
pub trait EBNFWritable<W: EBNFWriter> { | ||
fn write_ebnf(&self, name: &str, writer: &mut W); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
mod expression; | ||
mod grammar; | ||
mod parser; | ||
mod precedence_parser; | ||
mod production; | ||
mod scanner; | ||
|
||
pub use grammar::GrammarEBNFGeneratorExtensions; | ||
pub use production::ProductionEBNFGeneratorExtensions; | ||
pub mod ebnf_writer; |
Oops, something went wrong.