mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-17 19:21:04 +00:00
use normal style for comments
Signed-off-by: xermicus <cyrill@parity.io>
This commit is contained in:
@@ -1,12 +1,8 @@
|
||||
//!
|
||||
//! The Yul IR lexer error.
|
||||
//!
|
||||
|
||||
use crate::yul::lexer::token::location::Location;
|
||||
|
||||
///
|
||||
/// The Yul IR lexer error.
|
||||
///
|
||||
#[derive(Debug, thiserror::Error, PartialEq, Eq)]
|
||||
pub enum Error {
|
||||
/// The invalid lexeme error.
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
//!
|
||||
//! The compiler lexer.
|
||||
//!
|
||||
|
||||
pub mod error;
|
||||
pub mod token;
|
||||
@@ -18,9 +16,7 @@ use self::token::lexeme::Lexeme;
|
||||
use self::token::location::Location;
|
||||
use self::token::Token;
|
||||
|
||||
///
|
||||
/// The compiler lexer.
|
||||
///
|
||||
pub struct Lexer {
|
||||
/// The input source code.
|
||||
input: String,
|
||||
@@ -33,9 +29,7 @@ pub struct Lexer {
|
||||
}
|
||||
|
||||
impl Lexer {
|
||||
///
|
||||
/// A shortcut constructor.
|
||||
///
|
||||
pub fn new(mut input: String) -> Self {
|
||||
input.push('\n');
|
||||
|
||||
@@ -47,9 +41,7 @@ impl Lexer {
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Advances the lexer, returning the next lexeme.
|
||||
///
|
||||
#[allow(clippy::should_implement_trait)]
|
||||
pub fn next(&mut self) -> Result<Token, Error> {
|
||||
if let Some(peeked) = self.peeked.take() {
|
||||
@@ -121,9 +113,7 @@ impl Lexer {
|
||||
Ok(Token::new(self.location, Lexeme::EndOfFile, 0))
|
||||
}
|
||||
|
||||
///
|
||||
/// Peeks the next lexeme without advancing the iterator.
|
||||
///
|
||||
pub fn peek(&mut self) -> Result<Token, Error> {
|
||||
match self.peeked {
|
||||
Some(ref peeked) => Ok(peeked.clone()),
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
//!
|
||||
//! The Yul IR lexer tests.
|
||||
//!
|
||||
|
||||
use crate::yul::lexer::error::Error;
|
||||
use crate::yul::lexer::token::lexeme::Lexeme;
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
//!
|
||||
//! The comment lexeme.
|
||||
//!
|
||||
|
||||
pub mod multi_line;
|
||||
pub mod single_line;
|
||||
@@ -10,9 +8,7 @@ use crate::yul::lexer::token::Token;
|
||||
use self::multi_line::Comment as MultiLineComment;
|
||||
use self::single_line::Comment as SingleLineComment;
|
||||
|
||||
///
|
||||
/// The comment lexeme.
|
||||
///
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
#[allow(dead_code)]
|
||||
pub enum Comment {
|
||||
@@ -23,9 +19,7 @@ pub enum Comment {
|
||||
}
|
||||
|
||||
impl Comment {
|
||||
///
|
||||
/// Returns the comment's length, including the trimmed whitespace around it.
|
||||
///
|
||||
pub fn parse(input: &str) -> Option<Token> {
|
||||
if input.starts_with(SingleLineComment::START) {
|
||||
Some(SingleLineComment::parse(input))
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
//!
|
||||
//! The multi-line comment lexeme.
|
||||
//!
|
||||
|
||||
use crate::yul::lexer::token::lexeme::Lexeme;
|
||||
use crate::yul::lexer::token::location::Location;
|
||||
use crate::yul::lexer::token::Token;
|
||||
|
||||
///
|
||||
/// The multi-line comment lexeme.
|
||||
///
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Comment {}
|
||||
|
||||
@@ -18,9 +14,7 @@ impl Comment {
|
||||
/// The end symbol.
|
||||
pub const END: &'static str = "*/";
|
||||
|
||||
///
|
||||
/// Returns the comment, including its length and number of lines.
|
||||
///
|
||||
pub fn parse(input: &str) -> Token {
|
||||
let end_position = input.find(Self::END).unwrap_or(input.len());
|
||||
let input = &input[..end_position];
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
//!
|
||||
//! The single-line comment lexeme.
|
||||
//!
|
||||
|
||||
use crate::yul::lexer::token::lexeme::Lexeme;
|
||||
use crate::yul::lexer::token::location::Location;
|
||||
use crate::yul::lexer::token::Token;
|
||||
|
||||
///
|
||||
/// The single-line comment lexeme.
|
||||
///
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Comment {}
|
||||
|
||||
@@ -18,9 +14,7 @@ impl Comment {
|
||||
/// The end symbol.
|
||||
pub const END: &'static str = "\n";
|
||||
|
||||
///
|
||||
/// Returns the comment's length, including the trimmed whitespace around it.
|
||||
///
|
||||
pub fn parse(input: &str) -> Token {
|
||||
let end_position = input.find(Self::END).unwrap_or(input.len());
|
||||
let length = end_position + Self::END.len();
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
//!
|
||||
//! The identifier lexeme.
|
||||
//!
|
||||
|
||||
use crate::yul::lexer::token::lexeme::keyword::Keyword;
|
||||
use crate::yul::lexer::token::lexeme::Lexeme;
|
||||
use crate::yul::lexer::token::location::Location;
|
||||
use crate::yul::lexer::token::Token;
|
||||
|
||||
///
|
||||
/// The identifier lexeme.
|
||||
///
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Identifier {
|
||||
/// The inner string.
|
||||
@@ -17,16 +13,12 @@ pub struct Identifier {
|
||||
}
|
||||
|
||||
impl Identifier {
|
||||
///
|
||||
/// A shortcut constructor.
|
||||
///
|
||||
pub fn new(inner: String) -> Self {
|
||||
Self { inner }
|
||||
}
|
||||
|
||||
///
|
||||
/// Parses the identifier, returning it as a token.
|
||||
///
|
||||
pub fn parse(input: &str) -> Option<Token> {
|
||||
if !input.starts_with(Self::can_begin) {
|
||||
return None;
|
||||
@@ -47,16 +39,12 @@ impl Identifier {
|
||||
))
|
||||
}
|
||||
|
||||
///
|
||||
/// Checks whether the character can begin an identifier.
|
||||
///
|
||||
pub fn can_begin(character: char) -> bool {
|
||||
character.is_alphabetic() || character == '_' || character == '$'
|
||||
}
|
||||
|
||||
///
|
||||
/// Checks whether the character can continue an identifier.
|
||||
///
|
||||
pub fn can_continue(character: char) -> bool {
|
||||
Self::can_begin(character)
|
||||
|| character.is_numeric()
|
||||
@@ -65,9 +53,7 @@ impl Identifier {
|
||||
|| character == '.'
|
||||
}
|
||||
|
||||
///
|
||||
/// Checks whether the character cannot continue an identifier.
|
||||
///
|
||||
pub fn cannot_continue(character: char) -> bool {
|
||||
!Self::can_continue(character)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
//!
|
||||
//! The keyword lexeme.
|
||||
//!
|
||||
|
||||
use crate::yul::lexer::token::lexeme::literal::boolean::Boolean as BooleanLiteral;
|
||||
use crate::yul::lexer::token::lexeme::literal::Literal;
|
||||
@@ -8,9 +6,7 @@ use crate::yul::lexer::token::lexeme::Lexeme;
|
||||
use crate::yul::lexer::token::location::Location;
|
||||
use crate::yul::lexer::token::Token;
|
||||
|
||||
///
|
||||
/// The keyword lexeme.
|
||||
///
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum Keyword {
|
||||
/// The `object` keyword.
|
||||
@@ -50,9 +46,7 @@ pub enum Keyword {
|
||||
}
|
||||
|
||||
impl Keyword {
|
||||
///
|
||||
/// Parses the keyword, returning it as a token.
|
||||
///
|
||||
pub fn parse(input: &str) -> Option<Token> {
|
||||
let keyword = Self::parse_keyword(input)?;
|
||||
let lexeme = match BooleanLiteral::try_from(keyword) {
|
||||
@@ -68,9 +62,7 @@ impl Keyword {
|
||||
Some(Token::new(Location::new(0, length), lexeme, length))
|
||||
}
|
||||
|
||||
///
|
||||
/// Parses the keyword itself.
|
||||
///
|
||||
fn parse_keyword(input: &str) -> Option<Self> {
|
||||
if !input.starts_with(Self::can_begin) {
|
||||
return None;
|
||||
@@ -111,23 +103,17 @@ impl Keyword {
|
||||
})
|
||||
}
|
||||
|
||||
///
|
||||
/// Checks whether the character can begin a keyword.
|
||||
///
|
||||
pub fn can_begin(character: char) -> bool {
|
||||
character.is_alphabetic()
|
||||
}
|
||||
|
||||
///
|
||||
/// Checks whether the character can continue a keyword.
|
||||
///
|
||||
pub fn can_continue(character: char) -> bool {
|
||||
Self::can_begin(character) || character.is_numeric()
|
||||
}
|
||||
|
||||
///
|
||||
/// Checks whether the character cannot continue a keyword.
|
||||
///
|
||||
pub fn cannot_continue(character: char) -> bool {
|
||||
!Self::can_continue(character)
|
||||
}
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
//!
|
||||
//! The boolean literal lexeme.
|
||||
//!
|
||||
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::yul::lexer::token::lexeme::keyword::Keyword;
|
||||
|
||||
///
|
||||
/// The boolean literal lexeme.
|
||||
///
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
|
||||
pub enum Boolean {
|
||||
/// Created from the `false` keyword.
|
||||
@@ -19,16 +15,12 @@ pub enum Boolean {
|
||||
}
|
||||
|
||||
impl Boolean {
|
||||
///
|
||||
/// Creates a `false` value.
|
||||
///
|
||||
pub fn r#false() -> Self {
|
||||
Self::False
|
||||
}
|
||||
|
||||
///
|
||||
/// Creates a `true` value.
|
||||
///
|
||||
pub fn r#true() -> Self {
|
||||
Self::True
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
//!
|
||||
//! The integer literal lexeme.
|
||||
//!
|
||||
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
@@ -10,9 +8,7 @@ use crate::yul::lexer::token::lexeme::Literal;
|
||||
use crate::yul::lexer::token::location::Location;
|
||||
use crate::yul::lexer::token::Token;
|
||||
|
||||
///
|
||||
/// The integer literal lexeme.
|
||||
///
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
|
||||
pub enum Integer {
|
||||
/// An integer literal, like `42`.
|
||||
@@ -28,23 +24,17 @@ pub enum Integer {
|
||||
}
|
||||
|
||||
impl Integer {
|
||||
///
|
||||
/// Creates a decimal value.
|
||||
///
|
||||
pub fn new_decimal(inner: String) -> Self {
|
||||
Self::Decimal { inner }
|
||||
}
|
||||
|
||||
///
|
||||
/// Creates a hexadecimal value.
|
||||
///
|
||||
pub fn new_hexadecimal(inner: String) -> Self {
|
||||
Self::Hexadecimal { inner }
|
||||
}
|
||||
|
||||
///
|
||||
/// Parses the value from the source code slice.
|
||||
///
|
||||
pub fn parse(input: &str) -> Option<Token> {
|
||||
let (value, length) = if let Some(body) = input.strip_prefix("0x") {
|
||||
let end = body
|
||||
@@ -72,37 +62,27 @@ impl Integer {
|
||||
Some(token)
|
||||
}
|
||||
|
||||
///
|
||||
/// Checks whether the character can begin a decimal number.
|
||||
///
|
||||
pub fn can_begin_decimal(character: char) -> bool {
|
||||
Self::can_continue_decimal(character)
|
||||
}
|
||||
|
||||
///
|
||||
/// Checks whether the character can continue a decimal number.
|
||||
///
|
||||
pub fn can_continue_decimal(character: char) -> bool {
|
||||
character.is_digit(revive_common::BASE_DECIMAL)
|
||||
}
|
||||
|
||||
///
|
||||
/// Checks whether the character cannot continue a decimal number.
|
||||
///
|
||||
pub fn cannot_continue_decimal(character: char) -> bool {
|
||||
!Self::can_continue_decimal(character)
|
||||
}
|
||||
|
||||
///
|
||||
/// Checks whether the character can continue a hexadecimal number.
|
||||
///
|
||||
pub fn can_continue_hexadecimal(character: char) -> bool {
|
||||
character.is_digit(revive_common::BASE_HEXADECIMAL)
|
||||
}
|
||||
|
||||
///
|
||||
/// Checks whether the character cannot continue a hexadecimal number.
|
||||
///
|
||||
pub fn cannot_continue_hexadecimal(character: char) -> bool {
|
||||
!Self::can_continue_hexadecimal(character)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
//!
|
||||
//! The literal lexeme.
|
||||
//!
|
||||
|
||||
pub mod boolean;
|
||||
pub mod integer;
|
||||
@@ -13,9 +11,7 @@ use self::boolean::Boolean;
|
||||
use self::integer::Integer;
|
||||
use self::string::String;
|
||||
|
||||
///
|
||||
/// The literal lexeme.
|
||||
///
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
|
||||
pub enum Literal {
|
||||
/// A boolean literal, like `true`, or `false`.
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
//!
|
||||
//! The string literal lexeme.
|
||||
//!
|
||||
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
@@ -10,9 +8,7 @@ use crate::yul::lexer::token::lexeme::Literal;
|
||||
use crate::yul::lexer::token::location::Location;
|
||||
use crate::yul::lexer::token::Token;
|
||||
|
||||
///
|
||||
/// The string literal lexeme.
|
||||
///
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
|
||||
pub struct String {
|
||||
/// The inner string contents.
|
||||
@@ -22,9 +18,7 @@ pub struct String {
|
||||
}
|
||||
|
||||
impl String {
|
||||
///
|
||||
/// Creates a string literal value.
|
||||
///
|
||||
pub fn new(inner: ::std::string::String, is_hexadecimal: bool) -> Self {
|
||||
Self {
|
||||
inner,
|
||||
@@ -32,9 +26,7 @@ impl String {
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Parses the value from the source code slice.
|
||||
///
|
||||
pub fn parse(input: &str) -> Option<Token> {
|
||||
let mut length = 0;
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
//!
|
||||
//! The lexeme.
|
||||
//!
|
||||
|
||||
pub mod comment;
|
||||
pub mod identifier;
|
||||
@@ -13,9 +11,7 @@ use self::keyword::Keyword;
|
||||
use self::literal::Literal;
|
||||
use self::symbol::Symbol;
|
||||
|
||||
///
|
||||
/// The lexeme.
|
||||
///
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum Lexeme {
|
||||
/// The keyword lexeme.
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
//!
|
||||
//! The symbol lexeme.
|
||||
//!
|
||||
|
||||
use crate::yul::lexer::token::lexeme::Lexeme;
|
||||
use crate::yul::lexer::token::location::Location;
|
||||
use crate::yul::lexer::token::Token;
|
||||
|
||||
///
|
||||
/// The symbol lexeme.
|
||||
///
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum Symbol {
|
||||
/// The `:=` symbol.
|
||||
@@ -30,9 +26,7 @@ pub enum Symbol {
|
||||
}
|
||||
|
||||
impl Symbol {
|
||||
///
|
||||
/// Parses the symbol, returning it as a token.
|
||||
///
|
||||
pub fn parse(input: &str) -> Option<Token> {
|
||||
let (symbol, length) = match &input[..2] {
|
||||
":=" => (Self::Assignment, 2),
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
//!
|
||||
//! The lexical token location.
|
||||
//!
|
||||
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
///
|
||||
/// The token location in the source code file.
|
||||
///
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Eq)]
|
||||
pub struct Location {
|
||||
/// The line number, starting from 1.
|
||||
@@ -23,17 +19,13 @@ impl Default for Location {
|
||||
}
|
||||
|
||||
impl Location {
|
||||
///
|
||||
/// Creates a default location.
|
||||
///
|
||||
pub fn new(line: usize, column: usize) -> Self {
|
||||
Self { line, column }
|
||||
}
|
||||
|
||||
///
|
||||
/// Mutates the location by shifting the original one down by `lines` and
|
||||
/// setting the column to `column`.
|
||||
///
|
||||
pub fn shift_down(&mut self, lines: usize, column: usize) {
|
||||
if lines == 0 {
|
||||
self.shift_right(column);
|
||||
@@ -44,9 +36,7 @@ impl Location {
|
||||
self.column = column;
|
||||
}
|
||||
|
||||
///
|
||||
/// Mutates the location by shifting the original one rightward by `columns`.
|
||||
///
|
||||
pub fn shift_right(&mut self, columns: usize) {
|
||||
self.column += columns;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
//!
|
||||
//! The token.
|
||||
//!
|
||||
|
||||
pub mod lexeme;
|
||||
pub mod location;
|
||||
@@ -8,11 +6,8 @@ pub mod location;
|
||||
use self::lexeme::Lexeme;
|
||||
use self::location::Location;
|
||||
|
||||
///
|
||||
/// The token.
|
||||
///
|
||||
/// Contains a lexeme and its location.
|
||||
///
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Token {
|
||||
/// The token location.
|
||||
@@ -24,9 +19,7 @@ pub struct Token {
|
||||
}
|
||||
|
||||
impl Token {
|
||||
///
|
||||
/// A shortcut constructor.
|
||||
///
|
||||
pub fn new(location: Location, lexeme: Lexeme, length: usize) -> Self {
|
||||
Self {
|
||||
location,
|
||||
|
||||
Reference in New Issue
Block a user