Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
109 lines (89 sloc) 2.77 KB
namespace Nitra.Tests
{
syntax module JsonParser : JsonLang
{
using Nitra.Core;
using Nitra.CStyleComments;
[StartRule, ExplicitSpaces]
syntax Start = s Value !Any;
///////////////////////////////////////////////////////////////////////////
// Identifier
// Non ambiguous
token Identifier = !Keyword IdentifierBody
{
regex KeywordToken = "true" | "false" | "null";
token Keyword = KeywordToken !IdentifierPartCharacters;
}
syntax QI
{
precedence MemberAcces:
| QI "." Identifier
| Identifier
}
// Non ambiguous (Keyword vs. Identifier)
//token Identifier = IdentifierBody;
///////////////////////////////////////////////////////////////////////////
// Strings
regex EscChar = '\\' | '/' | 'b' | 'f' | 'n' | 'r'| 't' | 'u' HexDigit HexDigit HexDigit HexDigit
{
regex HexDigit = ['0'..'9', 'a'..'f', 'A'..'F'];
}
[SpanClass(String)]
token StringLiteral1 = Quote StringPart* Quote
{
regex Quote = '\"';
regex Esc = '\\' (Quote | EscChar);
regex Escs = Esc+;
regex NotEscs = Any+ - (Any* (Quote | '\\' | NewLine) Any*);
token StringPart
{
| Escs;
| NotEscs;
}
}
[SpanClass(String)]
token StringLiteral2 = Quote StringPart* Quote
{
regex Quote = '\'';
token StringPart
{
regex Esc = '\\' (Quote | EscChar);
| Escs { regex Escs = Esc+; }
| NotEscs { regex NotEscs = Any+ - (Any* (Quote | '\\' | NewLine) Any*); }
}
}
///////////////////////////////////////////////////////////////////////////
// Numbers
regex Digits = ['0'..'9']+;
regex Integer = '0' | ['1'..'9'] ['0'..'9']*;
regex Exponent = ("E" | "e") ("-" | "+")? Digits;
//[ExplicitSpaces]
regex Fraction = "." Digits ;
//[ExplicitSpaces]
[SpanClass(Number)]
regex Number = "-"? Integer Fraction? Exponent?;
///////////////////////////////////////////////////////////////////////////
// Value
syntax Value
{
| QI
| StringLiteral1
| StringLiteral2
| Number
//| [ExplicitSpaces] Number = Integer Fraction? Exponent? s;
//| [ExplicitSpaces] NumberNeg = Minus="-" Integer Fraction? Exponent? s;
| Object = "{" outline_begin_before inl (Property; "," nl)* nl d outline_end "}";
| Array = "[" outline_begin_before (Value; "," sm)* outline_end "]";
| "true"
| "false"
| "null"
}
syntax Key
{
| StringLiteral1
| StringLiteral2
| Identifier
}
syntax Property = Key sm ":" sm Value;
}
}
You can’t perform that action at this time.