noteed / language-glsl Goto Github PK
View Code? Open in Web Editor NEWHaskell package for representation, parsing, and pretty-printing of GLSL
License: Other
Haskell package for representation, parsing, and pretty-printing of GLSL
License: Other
The module Language.GLSL.Tests
should be moved to a cabal test suite: http://www.haskell.org/cabal/users-guide/developing-packages.html#test-suites .
This would eliminate the unnecessary dependency on HUnit
when installing the library.
The prettyBinary
function in Language.GLSL.Pretty
sometimes incorrectly omits parentheses.
For instance, (/)
is left-associative, so "a / b / c" parses as "(a / b) / c", i.e.,
Div (Div (Variable "a") (Variable "b")) (Variable "c")
and "a / (b / c)" parses as
Div (Variable "a") (Div (Variable "b") (Variable "c"))
However, pretty-printing this last expression yields "a / b / c", which is incorrect.
The problematic code:
prettyBinary :: Pretty a =>
PrettyLevel -> Rational -> Rational -> String -> a -> a -> Doc
prettyBinary l p op o e1 e2 = prettyParen (p > op) $
pPrintPrec l op e1 <+> text o <+> pPrintPrec l op e2
To fix this bug, tweak the precedence context when pretty-printing the argument expressions, depending on the operator's associative:
type Assoc = (Rational -> Rational, Rational -> Rational)
assocLeft, assocRight, assocNone :: Assoc
assocLeft = (id,bump)
assocRight = (bump,id)
assocNone = (bump,bump)
bump :: Rational -> Rational
bump = (+ 0.5)
prettyBinary :: Pretty a =>
PrettyLevel -> Rational -> Rational -> Assoc -> String -> a -> a -> Doc
prettyBinary l p op (lf,rf) o e1 e2 = prettyParen (p > op) $
pPrintPrec l (lf op) e1 <+> text o <+> pPrintPrec l (rf op) e2
I submitted a pull request.
Hello, I would like to try resolving this issue #4 (or at least enough to support #extension
).
I'm stuck trying to build and run the tests for this repo though. When I run cabal test
I get this error
PS C:\Users\Martin\Desktop\language-glsl> cabal test
Resolving dependencies...
Warning: solver failed to find a solution:
[__0] trying: language-glsl-0.3.0 (user goal)
line flag, or user target requires opposite flag selection)
[__1] trying: language-glsl:*test
[__2] unknown package: test-framework-hunit (dependency of language-glsl
*test)
[__1] fail (backjumping, conflict set: language-glsl, test-framework-hunit,
language-glsl:test)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: language-glsl, language-glsl:test,
test-framework-hunit
Trying configure anyway.
Configuring language-glsl-0.3.0...
cabal.exe: Encountered missing dependencies:
HUnit -any,
test-framework -any,
test-framework-hunit -any
(I get the same error for cabal configure
and cabal build
)
I'm new to haskell so maybe I'm missing something obvious.
GHC version: 8.4.3
cabal-install version 2.2.0.0
Unpacking to language-glsl-0.1.1/
Resolving dependencies...
Configuring language-glsl-0.1.1...
Building language-glsl-0.1.1...
Preprocessing library language-glsl-0.1.1...
[1 of 4] Compiling Language.GLSL.Syntax ( Language/GLSL/Syntax.hs, dist/build/Language/GLSL/Syntax.o )
[2 of 4] Compiling Language.GLSL.Parser ( Language/GLSL/Parser.hs, dist/build/Language/GLSL/Parser.o )
Language/GLSL/Parser.hs:202:3: Warning: Defined but not used: ‘m’
Language/GLSL/Parser.hs:209:3: Warning: Defined but not used: ‘m’
Language/GLSL/Parser.hs:219:3: Warning: Defined but not used: ‘m’
Language/GLSL/Parser.hs:226:3: Warning: Defined but not used: ‘m’
Language/GLSL/Parser.hs:236:3: Warning: Defined but not used: ‘m’
Language/GLSL/Parser.hs:244:3: Warning: Defined but not used: ‘m’
[3 of 4] Compiling Language.GLSL.Pretty ( Language/GLSL/Pretty.hs, dist/build/Language/GLSL/Pretty.o )
[4 of 4] Compiling Language.GLSL ( Language/GLSL.hs, dist/build/Language/GLSL.o )
In-place registering language-glsl-0.1.1...
Preprocessing executable 'glsl-pprint' for language-glsl-0.1.1...
bin/glsl-pprint.hs:4:8:
Ambiguous module name ‘Text.PrettyPrint.HughesPJClass’:
it was found in multiple packages:
pretty-1.1.2.0@prett_7jIfj8VCGFf1WS0tIQ1XSZ prettyclass-1.0.0.0@prett_2FbqlbOn8rU3vmeTF7SGKM
<> is now in Prelude, so theres some name space collisions
What's the status of this project? Is it/will it continue to be maintained?
The Language.GLSL.Parser.parse function rejects the following code:
'''
layout (std140) uniform PatternBlock
{ float pattern[100];
};
void main ()
{ gl_FragColor = vec4 (1.0, 1.0, 0.0, 1.0);
}
'''
with the error:
'''
Left "GLSL" (line 2, column 17):
unexpected "1"
expecting "/", space or "]"
'''
From reading a bit in the specification (https://www.opengl.org/registry/doc/GLSLangSpec.1.50.11.pdf), I'm fairly sure that it should accept this syntax.
More precisely, it seems that the 'conditionalExpression' parser does not accept '100', which I believe it should (in spite of the name!), see *.
Looking at the implementation of 'conditionalExpression', it seems quite clear to me that Parsec's 'buildExpressionParser' function may not be the right fit, but I have not looked into why it fails yet.
I intend to investigate this a bit more in-depth shortly.
I'll send you a pull request if I figure out a valid fix.
Just thought I'd let you know in case I never get around to it.
*Note that it is not immediately obvious from the grammar in the spec that '100' should be accepted.
Here are the rewrites to get to '100' starting from conditional_expression:
conditional_expression, logical_or_expression, logical_xor_expression, logical_and_expression, inclusive_or_expression, exclusive_or_expression, and_expression, equality_expression, relational_expression, shift_expression, additive_expression, multiplicative_expression, unary_expression, postfix_expression, primary_expression, which includes INTCONSTANT.
The preprocessor is part of the GLSL spec, section 3.4 of https://www.khronos.org/registry/gles/specs/2.0/GLSL_ES_Specification_1.0.17.pdf
Is it even possible to handle #define and #ifdef properly in language-glsl?
While using WebGL
in Elm
, I discovered the GLSL
parser doesn't seem to infer types of arrays correctly.
For instance: uniform int array[32];
is inferred as having just the type Int
.
I'm not sure about Haskell
, but in Elm
I expect this type to be inferred as Array Int
.
Is this simply not supported, or is it a bug?
I have a few questions about using this library:
What versions of GLSL does it support?
Are there any critical portions of GLSL unsupported at this point?
Do you have any tutorials or rough guidelines for using the project?
Thanks!
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.