Commit bf95dca6 authored by Custom2043's avatar Custom2043
Browse files

doc correction

parent 71f747f5
#MPL : Meta Parser Language
# MPL : Meta Parser Language
MLP is a meta-language : It is meant to describe other languages
It is also reflexive : MPL.mpl is a MPL file that describe the MPL syntax
This file will described how it works.
#Lines
# Lines
MPL works with lines. A line defines a token and looks like : "Identifier = Search1 Search2"
......@@ -15,9 +15,9 @@ MPL.x will be read line by line, trying at each line to build the token (here it
Each part of the right side is called a Search. The token is built only if all searches are successful.
Thus, a space act as a "and" since all searches must be matched.
##Searches
## Searches
###TokenSearch
### TokenSearch
A TokenSearch is the simplest search : it is just a Identifier, or a String, which is surrounded by quotes
......@@ -27,11 +27,11 @@ And in this case, "Identifier" and " "test" are also TokenSearches.
All other searches (called MultipleSearches) come down to a combination of TokenSearches.
###MultipleSearch
### MultipleSearch
A MultipleSearch is composed of a number of searches. It can contains any search in any order, but it can't be empty.
###OrSearch
### OrSearch
An OrSearch is a MultipleSearch and is an Or between searches.
......@@ -46,7 +46,7 @@ The order of declaration is meaningful because the first token will be checked f
Here the order matters, as the "b" may or may not be taken under consideration.
###BracketSearch
### BracketSearch
A BracketSearch is a MultipleSearch that just holds some Searches
......@@ -58,7 +58,7 @@ In this example, the BracketSearch is useless, as it would mean the same thing w
Here, this line means that an Identifier is composed of a Search1 only, or a Search2 and a Search3.
###OptionalSearch
### OptionalSearch
An OptionnalSearch is a MultipleSearch that is an optional part of the token
......@@ -73,7 +73,7 @@ As an optional search may be empty, MultipleToken can't be composed of OptionalS
This line is also incorrect, as a token cannot be empty.
###ArraySearch
### ArraySearch
An ArraySearch is a MultipleSearch and allows to search for an unknown number of token
......@@ -115,7 +115,7 @@ The left and right parts are equivalent, since
all describe the same ItemList.
##Strings
## Strings
A string is a TokenSearch, as seen before :
......@@ -127,7 +127,7 @@ A String is actually divided in character :
A character is either a simple character, as in "test", or it can be a complex one.
###SimpleCharacter
### SimpleCharacter
A complex character is either :
......@@ -143,7 +143,7 @@ In that case, the backslash must be followed by
- Anything else that is not a complex character
###Complex character
### Complex character
A complex character is a character that is surrounded by single quotes
......@@ -169,7 +169,7 @@ Inside the single quote, a character can also be written by using its numeric co
##Reading an MPL file
## Reading an MPL file
First, the position inside the contents is set to the start.
......@@ -179,7 +179,7 @@ Then the MPL file will be read line by line.
If all searches are successful on a line, the token is built and it becomes the current token.
##Reading a line
## Reading a line
When a line is read, all searches must be matched, but the first token search is particular.
......@@ -187,7 +187,7 @@ Once at least one token search is successful, all other ones are read standardly
This difference is made to prevent a left-recursion
###First Search
### First Search
- If this token search is a string (like "a") :
......@@ -199,7 +199,7 @@ Then, if the current token match the identifier, the search is successful
This means that only identifiers declared prior to this (excluded) line can be used. Thus it is not allowed, as, even if it is not a issue, it is still something that will never happen.
###Other Searches
### Other Searches
After the first search, no current token is used.
......@@ -213,7 +213,7 @@ All lines up to the identifier declaration will be read (or re-read). If the cur
These searches can use identifiers declared anywhere in the file, even themselves.
##Line Example
## Line Example
We want to parse the X language.
X is a simple language which only allows to add 2 numbers.
......@@ -242,8 +242,7 @@ Is there other character left ? No
The result is an addition.
#Ignore
# Ignore
An ignore line is a particular type of line called ignore, for example :
......@@ -266,7 +265,7 @@ ignore is not a token, thus it can not be used as a TokenSearch.
is incorrect.
##Ignore example
## Ignore example
number = {'0-9'}
ignore = " "
......@@ -285,9 +284,9 @@ Here we only ignore one space per Search, generally ignores are ArraySearch to i
allows to skip any space or tabulations. It should not be declaring before number, as "0 9" would become a correct number.
#Transient token
# Transient token
##Generalities
## Generalities
A transient token is a token that is not built, unless it is referenced by another token. Thus it is impossible to get a transient token as a current token, but it is possible to get a token that contains a transient token.
......@@ -299,7 +298,7 @@ It can be written by putting a "#" before the identifier
In this example, an Identifier may be created because Transient is transient. Otherwise, building an Identifier wouldn't have
been possible since the current token would have been built before.
##Building a transient token
## Building a transient token
When we try to build a transient token, like here when we are building an Identifier :
......@@ -319,7 +318,7 @@ That's because there is no left-recursion possibilities with a transient token.
As with classic lines, first and other searches are different for transient lines :
###First search
### First search
If the transient token is the first encountered in the Identifier's list of Search, then the transient uses the current token.
......@@ -339,11 +338,11 @@ The situation is the same than it was before : As it is impossible to get a curr
Thus we need to create the referenced token with the current one. To prevent left-recursion, the first search must be declared before (exclusive) the transient's declaration line. That is different from a classic token, because the token is built here, not just checked.
###Other tokens
### Other tokens
Other tokens are build exactly as it would be as a classic token.
###Strings
### Strings
String are considered as transient, as they can't be a current token and generally follow the same construction rules as transient tokens do.
......@@ -351,13 +350,13 @@ For example, OrSearch's priority : it doesn't matter unless a transient token is
That's because a transient token disrupt the usual "one current token" system by adding the possibility to creating another one.
##Purpose
## Purpose
The main purpose of a transient token is to disrupt the line-by-line way of reading an MPL file (That's why it is not read the same as other tokens).
They mainly have 2 purposes :
###Context token
### Context token
Some tokens may be useful only in certain contexts.
......@@ -365,13 +364,13 @@ For example, letter in MPL can be put inside quotes, in which case they are only
Transient are fit for this job, as they are only built inside another declaration.
###Forward reference
### Forward reference
Since non-transient tokens can use further declared transient token, it can be used to reference further declared non-transient token too, even at the first search. It is impossible to build them, since it could create a left-recursion, but it can be used to create a single group of multiple tokens that uses each other.
##Transient Example
## Transient Example
###Context token example
### Context token example
We want to parse a complex pattern, but only if it's between quotes.
......@@ -392,7 +391,7 @@ That's why transient tokens are the best solution here :
#complexPattern = (backSlash ("b"|"r"|"t"|"n"|backSlash|allChar|quote|caracQuote|orToken))
String = quote complexPattern quote
###Forward reference example
### Forward reference example
Forward reference is really useful to create a group of tokens that can call each other.
For example, searches in MPL are defined using this system :
......@@ -404,7 +403,7 @@ For example, searches in MPL are defined using this system :
OrSearchToken = ...
#NamedSearch = {([searchNames:SearchName] searches:(TokenSearchToken|ArraySearchToken|OptionalSearchToken|BracketSearchToken)) | searches:OrSearchToken}
##Digest
## Digest
Declaring transient :
......@@ -418,9 +417,9 @@ String are transient, as they behave the same.
Transient token are useful to create token only usable in a certain context, or to grab a further token.
##OrSearch
## OrSearch
###Naming an OrSearch
### Naming an OrSearch
Actually, OrSearch cannot be named as other searches, because
......@@ -434,7 +433,7 @@ To name a OrSearch, use a BracketSearch instead
OrSearchName:(Search1|Search2)
###Reusing a name
### Reusing a name
Usually, a search name cannot be used multiple times on a single line.
......@@ -448,7 +447,7 @@ The name can also be used inside other searches.
Here we use this to separate the definition of a binary and an hexadecimal number, but it is still called "value". Generally, that is useful when tokens with the same meanings can be written differently.
###Limitations of Search names
### Limitations of Search names
The same name is only allowed once per part of the OrSearch.
......
#JMP : Java Meta Parser
# JMP : Java Meta Parser
A Meta Parser to describe languages and generate a Parser written in Java.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment