Ver código fonte

Parse escape sequences

pull/8/head
Max Brunsfeld 8 anos atrás
pai
commit
df769721cb
4 arquivos alterados com 50510 adições e 48805 exclusões
  1. +5
    -5
      corpus/expressions.txt
  2. +21
    -7
      grammar.js
  3. +84
    -72
      src/grammar.json
  4. +50400
    -48721
      src/parser.c

+ 5
- 5
corpus/expressions.txt Ver arquivo

@ -81,7 +81,7 @@ int main() {
(compound_statement
(expression_statement (call_expression
(identifier)
(argument_list (string_literal) (identifier)))))))
(argument_list (string_literal (escape_sequence)) (identifier)))))))
============================================
String literals
@ -102,7 +102,7 @@ int main() {
(compound_statement
(expression_statement (string_literal))
(expression_statement (concatenated_string (string_literal) (string_literal) (string_literal)))
(expression_statement (string_literal)))))
(expression_statement (string_literal (escape_sequence) (escape_sequence))))))
============================================
Character literals
@ -123,9 +123,9 @@ int main() {
(function_declarator (identifier) (parameter_list))
(compound_statement
(expression_statement (char_literal))
(expression_statement (char_literal))
(expression_statement (char_literal))
(expression_statement (char_literal)))))
(expression_statement (char_literal (escape_sequence)))
(expression_statement (char_literal (escape_sequence)))
(expression_statement (char_literal (escape_sequence))))))
============================================
Field access

+ 21
- 7
grammar.js Ver arquivo

@ -673,26 +673,40 @@ module.exports = grammar({
repeat(choice('u', 'l', 'U', 'L'))
)),
char_literal: $ => token(seq(
char_literal: $ => seq(
'\'',
choice(
seq(optional('\\'), /[^']/),
seq('\\', '\'')
$.escape_sequence,
/[^\n']/
),
'\''
)),
),
concatenated_string: $ => seq(
$.string_literal,
repeat1($.string_literal)
),
string_literal: $ => token(seq(
string_literal: $ => seq(
'"',
repeat(choice(/[^\\"\n]/, /\\./)),
'"')
repeat(choice(
token(prec(1, /[^\\"\n]/)),
$.escape_sequence
)),
'"'
),
escape_sequence: $ => token(seq(
'\\',
choice(
/[^xuU]/,
/\d{2,3}/,
/x[0-9a-fA-F]{2,}/,
/u[0-9a-fA-F]{4}/,
/U[0-9a-fA-F]{8}/
)
)),
system_lib_string: $ => token(seq(
'<',
repeat(choice(/[^>\n]/, '\\>')),

+ 84
- 72
src/grammar.json Ver arquivo

@ -4060,59 +4060,30 @@
}
},
"char_literal": {
"type": "TOKEN",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "'"
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "\\"
},
{
"type": "BLANK"
}
]
},
{
"type": "PATTERN",
"value": "[^']"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "\\"
},
{
"type": "STRING",
"value": "'"
}
]
}
]
},
{
"type": "STRING",
"value": "'"
}
]
}
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "'"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "escape_sequence"
},
{
"type": "PATTERN",
"value": "[^\\n']"
}
]
},
{
"type": "STRING",
"value": "'"
}
]
},
"concatenated_string": {
"type": "SEQ",
@ -4131,33 +4102,74 @@
]
},
"string_literal": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "\""
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[^\\\\\"\\n]"
}
}
},
{
"type": "SYMBOL",
"name": "escape_sequence"
}
]
}
},
{
"type": "STRING",
"value": "\""
}
]
},
"escape_sequence": {
"type": "TOKEN",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "\""
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[^\\\\\"\\n]"
},
{
"type": "PATTERN",
"value": "\\\\."
}
]
}
"value": "\\"
},
{
"type": "STRING",
"value": "\""
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[^xuU]"
},
{
"type": "PATTERN",
"value": "\\d{2,3}"
},
{
"type": "PATTERN",
"value": "x[0-9a-fA-F]{2,}"
},
{
"type": "PATTERN",
"value": "u[0-9a-fA-F]{4}"
},
{
"type": "PATTERN",
"value": "U[0-9a-fA-F]{8}"
}
]
}
]
}

+ 50400
- 48721
src/parser.c
Diferenças do arquivo suprimidas por serem muito extensas
Ver arquivo


Carregando…
Cancelar
Salvar