question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Line:column for embedded languages

See original GitHub issue

Question: how to address line:column mismatches for embedded languages?

For example, I have the following file:

---
foo: bar
---

Baz

in FrontMatter format and the following parser, working with fm.body:

let P = require("parsimmon")

let s = `
Baz
`

let lang = P.createLanguage({
  Baz: function (L) {
    return P.string("Baz+").trim(P.optWhitespace)
  },
})

console.log(lang.Baz.tryParse(s))

The error says:

Error: expected 'Baz+' at line 2 column 1, got '...Baz

While the real line, as the user perceives it is 5. The solution of catching and parsing exception messages with .replace(/line (\d+)/, "...") is obviously a last resort hack. Those messages aren’t an API part and can be changed any day.

What should we do instead, ideally? Accept some parser options?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ivan-kleshnincommented, Jun 5, 2018

Yeah, I thought of this version but wanted to avoid writing a YAML parser.

Now I see I can create just-an-FM parser like:

P.seq(
  P.string("---")).skip(P.nl),
  P.any.notFollowedBy(P.string("---")).many().tie(),
  P.nl.then(P.string("---")),
)

combined with body parser as you said.

Then parse YAML with a 3-rd party lib after that, on a separate step. That would raise the original problem again, now for the YAML, which would be 1 line shifted from it’s initial position. But then I can spoof it by adding one empty line to the YAML before parsing. Problem solved 😃

0reactions
wavebeemcommented, Jun 5, 2018

Like instead of doing:

  • Parse front matter, get raw body text
  • Parse raw body text with parser based on file extension

You could do like:

let MarkdownParser = P.createLanguage({ ... });
let FrontmatterParser = P.createLanguage({ ... });
let EnhancedMarkdownParser = P.seq(FrontmatterParser.main, MarkdownParser.main);

EnhancedMarkdownParser.tryParse(fileTextContent);

or something like that?

Read more comments on GitHub >

github_iconTop Results From Across the Web

A list of embedded scripting languages - GitHub
Project name/link Implementation language GC AbcDatalog Java JVM's GC AngelScript C++ Ref. counting + cycle‑detecting tracing GC Anko Go Go's GC
Read more >
Embedded Software Programming Languages: Pros, Cons ...
Learn about programming languages for embedded systems, pros & cons of popular languages, download a comparison table, and expert advice.
Read more >
Top 10 Best Embedded Systems Programming Languages
This article deals with programming languages for Embedded Systems. And also Bollywood… Why Bollywood you ask? Well, that's because Embedded ...
Read more >
Top 17 Programming Languages for Embedded Systems Work
As with so many other arenas, Python, C, and C++ are immensely useful when it comes to embedded systems, although many lesser-known languages...
Read more >
Embedded software programming languages you should learn
Learn which software programming languages you should consider learning if you're interested in a career in embedded software development.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found