Golang's syntax parser in Rust follow by the Specification.
chikaku / gosyn Goto Github PK
View Code? Open in Web Editor NEWGolang syntax parser in Rust
Home Page: https://docs.rs/gosyn
License: MIT License
Golang syntax parser in Rust
Home Page: https://docs.rs/gosyn
License: MIT License
Golang's syntax parser in Rust follow by the Specification.
I see in Cargo.toml it is MIT licensed but there is no LICENSE file in the repo
Repro steps:
fn main() {
let source = "# hello world";
parse_source(source);
println!("Did not panic");
}
It panics here:
Line 31 in b5c363e
I don't know if it's intended or not, but the from_file
returns a nice Result<>
object. How would we feel about changing the signature of from<S: AsRef<str>>(s: S) -> Self
to from<S: AsRef<str>>(s: S) -> Result<Self>
?
if we're concerned about breaking the API here, we can always add an panic_safe_from<S: AsRef<str>>(s: S) -> Result<Self>
and maybe deprecate the other.
Wdyt? Let me know which one of the above improvements you prefer and I'm more than happy to submit a PR.
*/
func _gen(){
}
just like the func comments, parse the comment is ""
It would be useful to implement Debug on the ast, i think.
The current tests for the switch aren't asserting the parsed AST is correct.
It is in fact, broken.
switch x {
case 5:
print(5)
}
This generates a switch statement without a tag.
https://github.com/chikaku/gosyn/blob/main/src/parser.rs#L1923
I believe this should be moved inside the if statement above.
Like so
if self.skipped(Operator::SemiColon)? {
init = tag;
tag = self
.current_not(Operator::BraceLeft)
.then(|| self.parse_simple_stmt())
.map_or(Ok(None), |r| r.map(Some))?;
}
Because currently, the tag gets parsed correctly before this and it gets overwritten with None
Can we get the struct nodes to implement clone?
Right now, this invalid code parses correctly.
a := 1
b := 2
foo(a b)
I believe, you need to do something like
Some((_, Token::Operator(Operator::ParenLeft))) => {
self.next()?;
let mut args = vec![];
let mut prev_comma: Option<bool> = None;
while self.current_not(Operator::ParenRight)
&& self.current_not(Operator::DotDotDot)
{
if let Some(pc) = prev_comma {
assert!(pc);
}
args.push(self.parse_next_level_expr()?);
prev_comma = Some(self.skipped(Operator::Comma)?);
}
I've added
let mut prev_comma: Option<bool> = None;
If there are more than 1 arguments, this will assert that there was a comma
Hello,i am about to try to use this for a Go interpreter.
Can you identify where is the problematic utf8 decode, that you mentioned in the readme?
After #3 merged, the parsing result of struct field can contain comments, but comments placed on the same line after type cannot be located accurately.
type Person struct {
// ✅ this comment is ok
name string
age int // ❌ this comment can't be located
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.