Live data from Hacker News

Weird Lexical Syntax

justine.lol

171–180 of 234 posts

Re: Weird Lexical Syntax

#171
post #114
post #113

Author hasn’t tried to highlight TeX. Which is good for their mental health, I suppose, as it’s generally impossible to fully highlight TeX without interpreting it. Even parsing is not enough, as it’s possible to redefine what each character does. You can make it do things like “and now K means { and C means }”. Yes, you can find papers on arXiv that use this god-forsaken feature.

I wrote https://github.com/Mozilla-Ocho/llamafile/blob/main/llamafil... and it does a reasonable job highlighting without breaking for all the .tex files I could find on my hard drive. My goal is to hopefully cover 99.9% of real world usage, since that'll likely cover everything an LLM might output. Esoteric syntax also usually isn't a problem, so long as it doesn't cause strings and comments to extend forever, eclip…

Yes, when goal isn’t to support 100% of all the weird stuff, then it’s orders of magnitude easier!

Re: Weird Lexical Syntax

#172
post #166
post #153

Earlier quoted context omitted.

While you're conceptually right, in practice I think it bears mentioning that in C# the two syntaxes compile differently. This is because C#’s target platform, the .NET Framework, has always had a function called `string.Format` that lets you write this: var str = string.Format("{0} is {1} years old.", name, age); When interpolated strings were introduced later, it was natural to have them compile to this instead of…

There's no reason in principle why name + " is " + age + " years old." couldn't compile to exactly the same. (Other than maybe `string.Format` having some additional customizable behavior, I don't know C# that well.)

Like python, and Rust with the format! macro (which doesn't even support arbitrary expressions), C# the full syntax for interpolated/formatted strings is this: {[,][:]}, ie there is more going on then just a simple wrapper around concat or StringBuilder.

Re: Weird Lexical Syntax

#175
post #162

Justine gets very close to the hairiest parsing issue in any language without encountering it: Perl's syntax is undecidable, because the difference between treating some characters as a comment or as a regex can depend on the type of a variable that is only determined e.g. based on whether a search for a Collatz counterexample terminates, or just, you know, user input. https://perlmonks.org/?node_id=663393 C++ templa…

Yup, bash and GNU Make have the same issue as Perl does, and I mention the C++ issue here too: Parsing Bash is Undecidable - https://www.oilshell.org/blog/2016/10/20.html I remember a talk from Larry Wall on Perl 6 (now Raku), where he says this type of thing is a mistake. Raku can be statically parsed, as far as I know.

Parsing POSIX shell in undecidable too:

https://news.ycombinator.com/item?id=30362718

Re: Weird Lexical Syntax

#176
post #125

Earlier quoted context omitted.

Could you review my comment on HN? Please educate me if there is something I haven’t understood, rather than downvoting my question.

The grandparent post is specifically about trigraphs. Saying something about trigraphs was the end-in-itself, trigraphs were chosen to illustrate something about trigraphs. So your question made no sense. Hope that helps.

My question was precisely about why the user like trigraphs over using just || on this case. It is a very clear question and makes all the sense.

Re: Weird Lexical Syntax

#177
post #22

Some random things that the author seem to have missed: > but TypeScript, Swift, Kotlin, and Scala take string interpolation to the furthest extreme of encouraging actual code being embedded inside strings Many more languages support that: C# $"{x} plus {y} equals {x + y}" Python f"{x} plus {y} equals {x + y}" JavaScript `${x} plus ${y} equals ${x + y}` Ruby "#{x} plus #{y} equals #{x + y}" Shell "$x plus $y equals $…

> Scala

Note about Scala's string interpolation. They can be used as pattern match targets.

  val s"${a} + ${b}" = "1 + 2";
  println(a) // 1
  println(b) // 2

Re: Weird Lexical Syntax

#178
post #166
post #153

Earlier quoted context omitted.

While you're conceptually right, in practice I think it bears mentioning that in C# the two syntaxes compile differently. This is because C#’s target platform, the .NET Framework, has always had a function called `string.Format` that lets you write this: var str = string.Format("{0} is {1} years old.", name, age); When interpolated strings were introduced later, it was natural to have them compile to this instead of…

There's no reason in principle why name + " is " + age + " years old." couldn't compile to exactly the same. (Other than maybe `string.Format` having some additional customizable behavior, I don't know C# that well.)

When not using the format specifiers or alignment it will indeed compile to just string.Concat (which is also what the + operator for strings compiles to). Similar to C compilers choosing to call pits instead of printf if there is nothing to be formatted.

Re: Weird Lexical Syntax

#179
post #100

The author may have missed that lexing C is actually context-sensitive, i.e. you need a symbol table: https://en.wikipedia.org/wiki/Lexer_hack Of course, for syntax highlighting this is only relevant if you want to highlight the multiplication operator differently from the dereferencing operator, or declarations differently from expressions. More generally, however, I find it useful to highlight (say) types different…

> this is only relevant if you want to highlight the multiplication operator differently from the dereferencing operator

Can you mention one editor which does that?

Re: Weird Lexical Syntax

#180
post #176

Earlier quoted context omitted.

The grandparent post is specifically about trigraphs. Saying something about trigraphs was the end-in-itself, trigraphs were chosen to illustrate something about trigraphs. So your question made no sense. Hope that helps.

My question was precisely about why the user like trigraphs over using just || on this case. It is a very clear question and makes all the sense.

I didn't downvote your comment but understand why it looks "wrong": it's like, in a thread on English oddities, you replied to someone bringing up the "buffalo buffalo buffalo" example with the question "why are you so fond of bovines"?
Post reply on HN