Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing issues #149

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions glsl-quasiquote/src/tokenize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,11 @@ fn tokenize_statement(st: &syntax::Statement) -> TokenStream {

fn tokenize_simple_statement(sst: &syntax::SimpleStatement) -> TokenStream {
match *sst {
syntax::SimpleStatement::Preprocessor(ref pp) => {
let pp = tokenize_preprocessor(pp);
quote! { glsl::syntax::SimpleStatement::Preprocessor(#pp) }
}

syntax::SimpleStatement::Declaration(ref d) => {
let d = tokenize_declaration(d);
quote! { glsl::syntax::SimpleStatement::Declaration(#d) }
Expand Down
2 changes: 1 addition & 1 deletion glsl/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "glsl"
version = "6.0.1"
version = "6.0.2"
license = "BSD-3-Clause"
authors = ["Dimitri Sabadie <[email protected]>"]
description = "A GLSL450/GLSL460 parser."
Expand Down
3 changes: 2 additions & 1 deletion glsl/src/parsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1305,6 +1305,7 @@ pub fn multiplicative_expr(i: &str) -> ParserResult<syntax::Expr> {
/// Parse a simple statement.
pub fn simple_statement(i: &str) -> ParserResult<syntax::SimpleStatement> {
alt((
map(preprocessor, syntax::SimpleStatement::Preprocessor),
map(jump_statement, syntax::SimpleStatement::Jump),
map(iteration_statement, syntax::SimpleStatement::Iteration),
map(case_label, syntax::SimpleStatement::CaseLabel),
Expand Down Expand Up @@ -1631,7 +1632,7 @@ pub(crate) fn pp_version_profile(i: &str) -> ParserResult<syntax::PreprocessorVe
///
/// This parser is needed to authorize breaking a line with the multiline annotation (\).
pub(crate) fn pp_space0(i: &str) -> ParserResult<&str> {
recognize(many0_(alt((space1, tag("\\\n")))))(i)
recognize(many0_(alt((space1, tag("\\\n"), tag("\\\r\n")))))(i)
}

/// Parse a preprocessor define.
Expand Down
20 changes: 16 additions & 4 deletions glsl/src/parsers/nom_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,22 @@ where
/// Discard any leading newline.
pub fn str_till_eol(i: &str) -> ParserResult<&str> {
map(
recognize(till(alt((value((), tag("\\\n")), value((), anychar))), eol)),
recognize(till(
alt((
value((), tag("\\\n")),
value((), tag("\\\r\n")),
value((), anychar),
)),
eol,
)),
|i| {
if i.as_bytes().last() == Some(&b'\n') {
&i[0..i.len() - 1]
let bytes = i.as_bytes();
if bytes.last() == Some(&b'\n') {
if bytes.get(i.len() - 2) == Some(&b'\r') {
&i[0..i.len() - 2]
} else {
&i[0..i.len() - 1]
}
} else {
i
}
Expand All @@ -91,5 +103,5 @@ pub fn str_till_eol(i: &str) -> ParserResult<&str> {
//
// Taylor Swift loves it.
pub fn blank_space(i: &str) -> ParserResult<&str> {
recognize(many0_(alt((multispace1, tag("\\\n")))))(i)
recognize(many0_(alt((multispace1, tag("\\\n"), tag("\\\r\n")))))(i)
}
1 change: 1 addition & 0 deletions glsl/src/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,7 @@ impl Statement {
/// Simple statement.
#[derive(Clone, Debug, PartialEq)]
pub enum SimpleStatement {
Preprocessor(Preprocessor),
Declaration(Declaration),
Expression(ExprStatement),
Selection(SelectionStatement),
Expand Down
1 change: 1 addition & 0 deletions glsl/src/transpiler/glsl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,7 @@ where
F: Write,
{
match *sst {
syntax::SimpleStatement::Preprocessor(ref pp) => show_preprocessor(f, pp),
syntax::SimpleStatement::Declaration(ref d) => show_declaration(f, d),
syntax::SimpleStatement::Expression(ref e) => show_expression_statement(f, e),
syntax::SimpleStatement::Selection(ref s) => show_selection_statement(f, s),
Expand Down
1 change: 1 addition & 0 deletions glsl/src/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,7 @@ macro_rules! make_host_trait {

if visit == Visit::Children {
match self {
syntax::SimpleStatement::Preprocessor(p) => p.$mthd_name(visitor),
syntax::SimpleStatement::Declaration(d) => d.$mthd_name(visitor),
syntax::SimpleStatement::Expression(e) => e.$mthd_name(visitor),
syntax::SimpleStatement::Selection(s) => s.$mthd_name(visitor),
Expand Down