github.com/jxskiss/gopkg@v0.17.3/json/extparser/json.peg (about)

     1  # Extended JSON grammar
     2  #
     3  # Reference:
     4  # - https://json.org/ and ECMA-262 Ed.5
     5  # - https://github.com/pointlander/peg
     6  #
     7  # Extended features:
     8  # - trailing comma of Object and Array
     9  # - traditional, end of line, or pragma comments
    10  # - simple identifier as object key without quotes
    11  # - Python boolean constants
    12  # - Python None as null
    13  # - Python style single quote string
    14  # - import other JSON files
    15  
    16  
    17  package extparser
    18  
    19  type JSON Peg {
    20  }
    21  
    22  
    23  Document  <-  Spacing JSON EOT
    24  JSON      <-  ( Object / Array / String / True / False / Null / Number / Import ) Spacing
    25  Object    <-  LWING ( ObjectKey COLON JSON COMMA )* ( ObjectKey COLON JSON )? RWING
    26  ObjectKey <-  String / SimpleIdentifier
    27  Array     <-  LBRK ( JSON COMMA )* JSON? RBRK
    28  Import    <-  '@import(' String ')'
    29  
    30  SimpleIdentifier    <-  [0-9A-Za-z_$]+
    31  String              <-  SingleQuoteLiteral / DoubleQuoteLiteral
    32  SingleQuoteLiteral  <-  '\'' ( SingleQuoteEscape / !['\\\n\r] .)* '\''
    33  DoubleQuoteLiteral  <-  '\"' ( DoubleQuoteEscape / !["\\\n\r] .)* '\"'
    34  SingleQuoteEscape   <-  '\\' ( [btnfr'\\/] / UnicodeEscape )
    35  DoubleQuoteEscape   <-  '\\' ( [btnfr"\\/] / UnicodeEscape )
    36  UnicodeEscape       <-  'u' HexDigit HexDigit HexDigit HexDigit
    37  HexDigit            <-  [a-f] / [A-F] / [0-9]
    38  
    39  True            <-  'true'  / 'True'
    40  False           <-  'false' / 'False'
    41  Null            <-  'null'  / 'None'
    42  
    43  Number          <-  Minus? IntegralPart FractionalPart? ExponentPart?
    44  Minus           <-  '-'
    45  IntegralPart    <-  '0' / [1-9] [0-9]*
    46  FractionalPart  <-  '.' [0-9]+
    47  ExponentPart    <-  "e" ( '+' / '-' )? [0-9]+
    48  
    49  Spacing         <-  ( Whitespace / LongComment / LineComment / Pragma )*
    50  Whitespace      <-  [ \t\r\n]+
    51  LongComment     <-  '/*'  (!'*/' .)*    '*/'
    52  LineComment     <-  '//'  (![\r\n] .)*  [\r\n]
    53  Pragma          <-  '#'   (![\r\n] .)*  [\r\n]
    54  
    55  LWING           <-  '{'  Spacing
    56  RWING           <-  '}'  Spacing
    57  LBRK            <-  '['  Spacing
    58  RBRK            <-  ']'  Spacing
    59  COMMA           <-  ','  Spacing
    60  COLON           <-  ':'  Spacing
    61  
    62  EOT <- !.