here-be / snapdragon Goto Github PK
View Code? Open in Web Editor NEWsnapdragon is an extremely pluggable, powerful and easy-to-use parser-renderer factory.
Home Page: https://github.com/here-be
License: MIT License
snapdragon is an extremely pluggable, powerful and easy-to-use parser-renderer factory.
Home Page: https://github.com/here-be
License: MIT License
app
.use(function any () {
var pos = this.position();
var m = this.match(/^./);
if (!m) return;
return pos({
type: 'any',
val: m[0]
});
})
Idea how from one renderer to get prev and next char? I think offset in position would work for me.
edit: And btw, should mention in readme, that you should be careful with parser plugins order (will show example in other issue).
source-map-resolve 0.50 uses two deprecated libs urix and resolve-url. so nstalling snapdragon via npm complains about the deprecated warning.
According to github, the last release was 0.8.0... but there are commits saying otherwise : perhaps you forgot to tag them?
Thanks!
It is nice that snapdragon as well as micromatch are nicely separated into small pieces, but I really think that having all of them in separate repositories make maintaining them a big pain, especially when making a breaking change in one of them that other rely one and then trying to update the whole ecosystem.
I'm also maintaining some projects that use monorepos with yarn workspaces
and lerna
and it gives you the ability to have small packages, but makes bigger changes super easy as they are all in one repository and one PR. So in my opinion setting up a monorepo would be a nice addition for snapdragon and micromatch.
So I wonder what your opinions are on this? And also for the micromatch org.
I don't want to come into a new project and change everything :) but I think it could make things a lot easier for everyone.
snapdragon has vulnerable dependency kind-of with CVE-2019-20149. Upgrading to snapdragon-node 3.0.0 would solve the problem.
to follow esprima/acorn format?
{
"loc": {
"start": {
"line": 82,
"column": 0
},
"end": {
"line": 87,
"column": 3
}
}
_
Could we upgrade the source-map-resolve
dependency from 0.5.3 to 0.6.0 to get rid of the following deprecation messages:
npm WARN deprecated [email protected]: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated [email protected]: https://github.com/lydell/resolve-url#deprecated
Good Afternoon snapdragon team,
We were performing a scan on the snapdragon Javascript library and the Fortify application has picked up the following items that are discovered as vulnerabilities.
(Reason being our project has imported this library as a dependency and part of our deliverable would requires the scanning of the full source code and identify/remove the vulnerable.)
(Low) Password Management: Password in Comment
No of items picked by the Fortify Scan: Less than 10
Kindly refer to the following image, scanImage1.png
Do give us a heads up on when the team is planning to fix these vulnerabilities and/or the possible workarounds to prevent the same items to be picked up by the Fortify Scans again.
https://github.com/lydell/source-map-resolve is deprecated now and contains vulnerable decode-uri-component dependency GHSA-w573-4hg7-7wgq
time to modernize it?
Currently, there are multiple versions of several dependencies in the dependency tree. This issue is meant to organize the deduplication of these.
lazy-cache
(highest version in tree: 2.0.2
)
is-descriptor
requires lazy-cache^1.0.3
. PR: inspect-js/is-descriptor#4.class-utils
requires lazy-cache^1.0.3
. PR: jonschlinkert/class-utils#2.to-object-path
(highest version in tree: 0.3.0
)
set-value
required by cache-base
requires to-object-path^0.2.0
. PR: jonschlinkert/cache-base#7.set-value
required by union-value
requires to-object-path^0.2.0
. PR: jonschlinkert/union-value#2.isobject
(highest version in tree: 3.0.0
)
object-visit
requires isobject^2.0.0
. PR: jonschlinkert/object-visit#1.cache-base
requires isobject^2.0.0
. PR: jonschlinkert/cache-base#7.base
requires isobject^2.0.0
. PR: base/base#26.use
requires isobject^2.0.0
. PR: jonschlinkert/use#9.has-value
requires isobject^2.0.0
. PR: jonschlinkert/has-value#2unset-value
requires isobject^2.0.0
. PR: jonschlinkert/unset-value#2.class-utils
requires isobject^2.0.0
. PR: jonschlinkert/class-utils#2set-value
required by cache-base
requires isobject^2.0.0
. PR: jonschlinkert/cache-base#7..set-value
required by union-value
requires isobject^2.0.0
. PR: jonschlinkert/union-value#2.is-plain-object
requires isobject^1.0.0
. PR: jonschlinkert/is-plain-object#8has-value
(highest version in tree: 0.3.1
)
unset-value
requires has-value^0.2.0
. PR: jonschlinkert/unset-value#2.snapdragon-util
(highest version in tree: 2.1.1
)
snapdragon-node
requires snapdragon-util^1.0.3
. PR: here-be/snapdragon-node#1.kind-of
(highest version in tree: 5.0.2
)
snapdragon-util
requires [email protected]
.The latest source-map which is v0.7.2 got support for WebAssembly and it is 10 times faster than the old one. More info here:
https://github.com/mozilla/source-map/blob/master/CHANGELOG.md#072
http://fitzgeraldnick.com/2018/02/26/speed-without-wizardry.html
https://hacks.mozilla.org/2018/01/oxidizing-source-maps-with-rust-and-webassembly/
firefox-devtools/debugger#5598
Please update so you would get 10 times speed improvements for your library in Firefox, 9 times in Safari and 5 times in Chrome.
Reminder to self or anyone else who might want to do a PR, we should do patch bumps on any older versions to remove debug
. See https://snyk.io/test/npm/debug/2.2.0 for more details.
tags in this repo is not in sync with npm releases.
I'm trying to work with this for building a parser for use in the browser, and it's failing on the source-maps inclusion, specifically webpack is dying because it's calling in fs and path modules.
Is there a configuration that will work for in the browser? Or is that something you're looking at adding in the future? Or maybe is that something I could help with adding?
cf. #20 (comment)
Current iteration of Readme doesn't tell what exactly does snapdragon do.
It is stated it is "a factory", but there's no link to explanation what "a factory" is.
I wrote a few libraries that work with parsed HTML AST's and I'm somewhat familiar with the subject, yet I find the Readme file too steep and unfriendly.
Here are the simple questions that are still unanswered by the current Readme:
If you would lower the barrier for new-comers you would attract more contributors and win promoters for this library.
I got this error using latest version of snapdragon
/home/remi/app/node_modules/snapdragon/node_modules/define-property/index.js:18
throw new TypeError('expected an object, function, or array');
^
TypeError: expected an object, function, or array
at defineProperty (/home/remi/app/node_modules/snapdragon/node_modules/define-property/index.js:18:11)
at Parser.eos (/home/remi/app/node_modules/snapdragon/lib/parser.js:434:9)
at Parser.parse (/home/remi/app/node_modules/snapdragon/lib/parser.js:536:20)
at Object.<anonymous> (/home/remi/app/src/lib/index.js:15:20)
at Module._compile (module.js:652:30)
at loader (/home/remi/app/node_modules/babel-register/lib/node.js:144:5)
at Object.require.extensions.(anonymous function) [as .js] (/home/remi/app/node_modules/babel-register/lib/node.js:154:7)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
using this parser:
function parser () {
const pos = this.position()
const match = this.match(/^\s*(if)\s*\(\s*(.*?)\s*\)\s*(?=then)/)
const prev = this.prev()
if (!match) return
const ifNode = pos(this.node({
type: 'ConditionnalState.if',
val: match[1],
condition: match[2]
}))
const conditionnalStateNode = pos(this.node({
type: 'ConditionnalState',
nodes: [ifNode]
}))
this.push('ConditionnalState', conditionnalStateNode)
prev.nodes.push(conditionnalStateNode)
}
but if I change it for the following
function parser () {
const pos = this.position()
const match = this.match(/^\s*(if)\s*\(\s*(.*?)\s*\)\s*(?=then)/)
// const prev = this.prev()
if (!match) return
const ifNode = pos(this.node({
type: IfConditionnalStateParser.type,
val: match[1],
condition: match[2]
}))
// const conditionnalStateNode = pos(this.node({
// type: 'ConditionnalState',
// nodes: [ifNode]
// }))
// this.push('ConditionnalState', conditionnalStateNode)
// prev.nodes.push(conditionnalStateNode)
return ifNode
}
Here, there is no error.
I can't understand why that error.
It is the bundled eos()
parser that throw TypeError
because prev.parent
is undefined
.
Line 433 in 82fb20d
But I don't know why/when node should/must have a parent
property.
I see that the condition for that line is hasOpenAndClose(prev)
but I dont know hat to do with that.
I'm trying to create an AST to parse plantuml
files (for activity diagrams only for now).
Here is the actual tree I get (when I use the second version of the mentionned parser, the first make eos() throw
Node {
type: 'root',
errors: [],
nodes:
[ Node { type: 'bos', val: '' },
Node {
type: 'Uml',
title: 'Activité Eolienne',
nodes:
[ Node {
type: 'Activity',
nodes:
[ Node { type: 'StaticState', val: 'Je veux installer une éolienne' },
Node {
type: 'ConditionnalState.if',
val: 'if',
condition: 'Hauteur >= 12m (mât + nacelle)' },
Node { type: 'ConditionnalState.then', val: 'then' },
Node { type: 'Space', val: ' ' },
Node { type: 'ConditionnalState.condition.open', val: '(' },
Node { type: 'All', val: 'OUI)' },
Node { type: 'NewLine', val: '\n' },
Node { type: 'StaticState', val: 'CERFA = PC' },
Node { type: 'Space', val: ' ' },
Node { type: 'Activity.stop', val: 'stop' },
Node { type: 'NewLine', val: '\n' },
Node { type: 'ConditionnalState.else', val: 'else' },
Node { type: 'Space', val: ' ' },
Node { type: 'ConditionnalState.condition.open', val: '(' },
Node { type: 'All', val: 'NON)' },
Node { type: 'NewLine', val: '\n' },
Node {
type: 'ConditionnalState.if',
val: 'if',
condition: 'Secteur protégé' },
Node { type: 'ConditionnalState.then', val: 'then' },
Node { type: 'Space', val: ' ' },
Node { type: 'ConditionnalState.condition.open', val: '(' },
Node { type: 'All', val: 'OUI)' },
Node { type: 'NewLine', val: '\n' },
Node { type: 'StaticState', val: 'CERFA = DP' },
Node { type: 'Space', val: ' ' },
Node { type: 'Activity.stop', val: 'stop' },
Node { type: 'NewLine', val: '\n' },
Node { type: 'Space', val: ' ' },
Node { type: 'ConditionnalState.else', val: 'else' },
Node { type: 'Space', val: ' ' },
Node { type: 'ConditionnalState.condition.open', val: '(' },
Node { type: 'All', val: 'NON)' },
Node { type: 'NewLine', val: '\n' },
Node { type: 'StaticState', val: 'Aucune autorisation nécessaire' },
Node { type: 'StaticState', val: 'Retour au début de l\'assistant' },
Node { type: 'Space', val: ' ' },
Node { type: 'DetachPuml', val: 'detach' },
Node { type: 'NewLine', val: '\n' },
Node { type: 'All', val: 'endif' },
Node { type: 'NewLine', val: '\n' } ],
val: '\\undefined' },
Node { type: 'All', val: '' } ] },
Node { type: 'eos', val: '' } ] }
Just browsing some tokenizers/parsers around. This one can be inspiration and is well and logically structured, imho. https://github.com/tildeio/simple-html-tokenizer/blob/master/lib/simple-html-tokenizer/evented-tokenizer.js :)
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.