The Unique Recipe for A New Outfit

Then go about building your business with that wardrobe style with your personal touches. Be aware of how your personality influences your wardrobe choices

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Parsing JSON

The Definitive ANTLR 4 Reference — by Terence Parr (39 / 99)

👈 Parsing Comma-Separated Values | TOC | Parsing DOT 👉

JSON is a text data format that captures a collection of name-value pairs, and since values can themselves be collections, JSON can include nested structures. Designing a parser for JSON gives us an opportunity to derive a grammar from a language reference manual[31] and to work with some more complicated lexical rules. To make things more concrete, here’s a simple JSON data file:

Our goal is to build an ANTLR grammar by reading the JSON reference manual and looking at its syntax diagram and existing grammar. We’ll pull out key phrases from the manual and figure out how to encode them as ANTLR rules, starting with the grammatical structures.

The language reference says that a JSON file can be either an object, as shown earlier, or an array of values. Grammatically, that’s just a choice pattern, which we can specify formally with this rule:

The next step is to drill down into the rule references in json. For objects, the reference says the following:

The syntax diagram at the JSON website also indicates that names have to be strings.

To convert this English description into grammar constructs, we break it apart looking for key phrases that represent one of our patterns: sequence, choice, token dependency, and nested phrase. The start of the sentence “An object is” clearly indicates we should create a rule called object. Next, an “unordered set of name-value pairs” is really just a sequence of pairs. The “unordered set” is referring to the semantics, or meaning, of the names; specifically, the order of the names has no meaning. That means we can just match any old list of pairs since we are just parsing.

Add a comment

Related posts:

Volunteers

This first-ever interactive Agile Adventure is the gripping tale of an experienced team struggling with agile adoption. In this unique mashup of a business novel written in the gamebook format, you'll overcome common yet daunting challenges that come from using agile methods. As Jim, the agile coach, you'll learn to apply a rang

JazzB

Um dos meus programas pós pandemia foi com o amigo mais eclético que eu tenho. Enquanto estávamos escolhendo um lugar, ele literalmente falou “Você quer vir comigo para uma aula de hip-hop?” O lugar…

Back and forth

Back and forth his feet swing Back and forth our minds drift What have we just done? It was all good fun Back and forth his feet swing Remember how we screamed his name? We wanted his head on a tray…