forked from AbleOS/ableos
slight improvement
This commit is contained in:
parent
9092dcd433
commit
ec36cfdb54
|
@ -66,6 +66,21 @@ add_one := fn(x: int): int {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### comments
|
||||||
|
```hb
|
||||||
|
// commant is an item
|
||||||
|
main := fn(): int {
|
||||||
|
// comment is a statement
|
||||||
|
foo(/* comment is an exprression /* if you are crazy */ */);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
foo := fn(comment: void): void
|
||||||
|
return /* comment evaluates to void */;
|
||||||
|
|
||||||
|
// comments might be formatted in the future
|
||||||
|
```
|
||||||
|
|
||||||
#### if_statements
|
#### if_statements
|
||||||
```hb
|
```hb
|
||||||
main := fn(): int {
|
main := fn(): int {
|
||||||
|
|
|
@ -109,6 +109,8 @@ pub enum TokenKind {
|
||||||
Que = b'?',
|
Que = b'?',
|
||||||
Directive = b'@',
|
Directive = b'@',
|
||||||
|
|
||||||
|
Comment,
|
||||||
|
|
||||||
Ident,
|
Ident,
|
||||||
Number,
|
Number,
|
||||||
Eof,
|
Eof,
|
||||||
|
@ -296,15 +298,33 @@ impl<'a> Lexer<'a> {
|
||||||
let ident = &self.bytes[start as usize..self.pos as usize];
|
let ident = &self.bytes[start as usize..self.pos as usize];
|
||||||
T::from_ident(ident)
|
T::from_ident(ident)
|
||||||
}
|
}
|
||||||
b'"' | b'\'' => {
|
b'"' | b'\'' => loop {
|
||||||
while let Some(nc) = self.advance() {
|
match self.advance() {
|
||||||
match nc {
|
Some(b'\\') => _ = self.advance(),
|
||||||
b'\\' => _ = self.advance(),
|
Some(nc) if nc == c => break identity(c),
|
||||||
nc if nc == c => break,
|
Some(_) => {}
|
||||||
|
None => break T::Eof,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
b'/' if self.advance_if(b'/') => {
|
||||||
|
while let Some(l) = self.advance()
|
||||||
|
&& l != b'\n'
|
||||||
|
{}
|
||||||
|
T::Comment
|
||||||
|
}
|
||||||
|
b'/' if self.advance_if(b'*') => {
|
||||||
|
let mut depth = 1;
|
||||||
|
while let Some(l) = self.advance() {
|
||||||
|
match l {
|
||||||
|
b'/' if self.advance_if(b'*') => depth += 1,
|
||||||
|
b'*' if self.advance_if(b'/') => match depth {
|
||||||
|
1 => break,
|
||||||
|
_ => depth -= 1,
|
||||||
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
identity(c)
|
T::Comment
|
||||||
}
|
}
|
||||||
b'.' if self.advance_if(b'{') => T::Ctor,
|
b'.' if self.advance_if(b'{') => T::Ctor,
|
||||||
b'.' if self.advance_if(b'(') => T::Tupl,
|
b'.' if self.advance_if(b'(') => T::Tupl,
|
||||||
|
|
Loading…
Reference in a new issue