summaryrefslogtreecommitdiff
path: root/streamhtmlparser/jsparser_fsm.config
blob: 830e13a3e4719890bbc5e3395128a867bb86d205 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# Copyright 2008 Google Inc. All Rights Reserved.
# Author: falmeida@google.com (Filipe Almeida)

name = 'jsparser'

comment = 'Simplified finite state machine for tracking of javascript states'

condition('q', '\''),
condition('dq', '\"'),
condition('/', '/'),
condition('*', '*'),
condition('[', '['),
condition(']', ']'),
condition('lf', '\n'),
condition('backslash', '\\'),
condition('default', '[:default:]')

# Main javascript body.
state(name = 'js_text',
      external = 'text',
      transitions = [
        ['q', 'js_q'],
        ['dq', 'js_dq'],
        ['/', 'js_slash'],
        ['default', 'js_text']
      ])

# Single quoted string literal.
state(name = 'js_q',
      external = 'q',
      transitions = [
        ['backslash', 'js_q_e'],
        ['q', 'js_text'],
        ['default', 'js_q']
      ])

# Javascript escaped character in a single quoted string literal.
state(name = 'js_q_e',
      external = 'q',
      transitions = [
        ['default', 'js_q']
      ])

# Double quoted string literal
state(name = 'js_dq',
      external = 'dq',
      transitions = [
        ['backslash', 'js_dq_e'],
        ['dq', 'js_text'],
        ['default', 'js_dq']
      ])

# Javascript escaped character in a double quoted string literal.
state(name = 'js_dq_e',
      external = 'dq',
      transitions = [
        ['default', 'js_dq']
      ])

# Possible start of a javascript comment.
state(name = 'js_slash',
      external = 'text',
      transitions = [
        ['/', 'js_comment_ln'],
        ['*', 'js_comment_ml'],
        ['default', 'js_text']
      ])

# Possible start of a regular expression literal.
#
# The state diagram does not reach this state directly. When js_slash is
# reached, the function enter_state_js_slash() is called, which checks if the
# last token belongs to the set of tokens that can precede a regular
# expression, in which case it changes the state to js_regexp_slash.
#
# For more information please read the comments in
# jsparser.c:enter_state_js_slash().
state(name = 'js_regexp_slash',
      external = 'text',
      transitions = [
        ['/', 'js_comment_ln'],
        ['*', 'js_comment_ml'],
        ['backslash', 'js_regexp_e'],
        ['[', 'js_regexp_bracket'],
        ['default', 'js_regexp']
      ])

# Regular expression literal.
state(name = 'js_regexp',
      external = 'regexp',
      transitions = [
        ['backslash', 'js_regexp_e'],
        ['[', 'js_regexp_bracket'],
        ['/', 'js_text'],
        ['default', 'js_regexp']
      ])

# Regexp bracket expression
state(name = 'js_regexp_bracket',
      external = 'regexp',
      transitions = [
        ['backslash', 'js_regexp_bracket_e'],
        [']', 'js_regexp'],
        ['default', 'js_regexp_bracket']
      ])

# Backslash escaped regexp bracket expression
state(name = 'js_regexp_bracket_e',
      external = 'regexp',
      transitions = [
        ['default', 'js_regexp_bracket']
      ])

# Escaped regular expression char.
state(name = 'js_regexp_e',
      external = 'regexp',
      transitions = [
        ['default', 'js_regexp']
      ])

# Start of a single line javascript comment (//).
state(name = 'js_comment_ln',
      external = 'comment',
      transitions = [
        ['lf', 'js_comment_after'],
        ['default', 'js_comment_ln']
      ])

# Start of a multiline javascript comment (/*).
state(name = 'js_comment_ml',
      external = 'comment',
      transitions = [
        ['*', 'js_comment_ml_close'],
        ['default', 'js_comment_ml']
      ])

# Close of a multiline javascript comment (*/).
state(name = 'js_comment_ml_close',
      external = 'comment',
      transitions = [
        ['/', 'js_comment_after'],
        ['default', 'js_comment_ml']
      ])

# Ending character of a javascript comment.
# In can either be a '/ in the case of a multiline comment, or a line
# terminator in the case of a single line comment.
# This is needed so we don't insert the '/' or the new line character into the
# ring buffer.
state(name = 'js_comment_after',
      external = 'text',
      transitions = [
        ['q', 'js_q'],
        ['dq', 'js_dq'],
        ['/', 'js_slash'],
        ['default', 'js_text']
      ])